generic test config

This commit is contained in:
Jimmy Zelinskie 2013-08-29 00:47:37 -04:00
parent 6e7d6f1a31
commit a2527aa4e2
4 changed files with 14 additions and 20 deletions

View file

@ -3,7 +3,7 @@ language: go
go: 1.1.2 go: 1.1.2
env: env:
- TRAVISCONFIGPATH=/home/travis/gopath/src/github.com/pushrax/chihaya/config/example.json - TESTCONFIGPATH=/home/travis/gopath/src/github.com/pushrax/chihaya/config/example.json
services: services:
- redis-server - redis-server

View file

@ -30,6 +30,14 @@ Make sure you have your $GOROOT and $GOPATH set up correctly and have your $GOBI
$ go install github.com/pushrax/chihaya $ go install github.com/pushrax/chihaya
``` ```
## Testing
```sh
$ export TESTCONFIGPATH=$GOPATH/src/chihaya/config/example.json
$ go get github.com/pushrax/chihaya
$ go test -v ./...
```
## Configuring ## Configuring
Configuration is done in a JSON formatted file specified with the `-config` Configuration is done in a JSON formatted file specified with the `-config`

View file

@ -11,21 +11,14 @@ import (
"testing" "testing"
) )
func getConfigPath() string {
if os.Getenv("TRAVISCONFIGPATH") != "" {
return os.Getenv("TRAVISCONFIGPATH")
}
return os.ExpandEnv("$GOPATH/src/github.com/pushrax/chihaya/config/example.json")
}
func TestOpenConfig(t *testing.T) { func TestOpenConfig(t *testing.T) {
if _, err := Open(getConfigPath()); err != nil { if _, err := Open(os.Getenv("TESTCONFIGPATH")); err != nil {
t.Error(err) t.Error(err)
} }
} }
func TestNewConfig(t *testing.T) { func TestNewConfig(t *testing.T) {
contents, err := ioutil.ReadFile(getConfigPath()) contents, err := ioutil.ReadFile(os.Getenv("TESTCONFIGPATH"))
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View file

@ -17,15 +17,8 @@ import (
_ "github.com/pushrax/chihaya/storage/batter" _ "github.com/pushrax/chihaya/storage/batter"
) )
func NewServer() (*Server, error) { func newTestServer() (*Server, error) {
var path string testConfig, err := config.Open(os.Getenv("TESTCONFIGPATH"))
if os.Getenv("TRAVISCONFIGPATH") != "" {
path = os.Getenv("TRAVISCONFIGPATH")
} else {
path = os.ExpandEnv("$GOPATH/src/github.com/pushrax/chihaya/config/example.json")
}
testConfig, err := config.Open(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -39,7 +32,7 @@ func NewServer() (*Server, error) {
} }
func TestStats(t *testing.T) { func TestStats(t *testing.T) {
s, err := NewServer() s, err := newTestServer()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }