diff --git a/.travis.yml b/.travis.yml index 87c2832..192ad76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: go go: 1.1.2 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: - redis-server diff --git a/README.md b/README.md index 2a38cc2..6441be3 100644 --- a/README.md +++ b/README.md @@ -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 ``` +## Testing + +```sh +$ export TESTCONFIGPATH=$GOPATH/src/chihaya/config/example.json +$ go get github.com/pushrax/chihaya +$ go test -v ./... +``` + ## Configuring Configuration is done in a JSON formatted file specified with the `-config` diff --git a/config/config_test.go b/config/config_test.go index 7cf6d6a..8ee6884 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -11,21 +11,14 @@ import ( "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) { - if _, err := Open(getConfigPath()); err != nil { + if _, err := Open(os.Getenv("TESTCONFIGPATH")); err != nil { t.Error(err) } } func TestNewConfig(t *testing.T) { - contents, err := ioutil.ReadFile(getConfigPath()) + contents, err := ioutil.ReadFile(os.Getenv("TESTCONFIGPATH")) if err != nil { t.Error(err) } diff --git a/server/stats_test.go b/server/stats_test.go index 8eaeba7..2bf1542 100644 --- a/server/stats_test.go +++ b/server/stats_test.go @@ -17,15 +17,8 @@ import ( _ "github.com/pushrax/chihaya/storage/batter" ) -func NewServer() (*Server, error) { - var path string - 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) +func newTestServer() (*Server, error) { + testConfig, err := config.Open(os.Getenv("TESTCONFIGPATH")) if err != nil { return nil, err } @@ -39,7 +32,7 @@ func NewServer() (*Server, error) { } func TestStats(t *testing.T) { - s, err := NewServer() + s, err := newTestServer() if err != nil { t.Error(err) }