diff --git a/.travis.yml b/.travis.yml index f0d08fd..87c2832 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: go go: 1.1.2 +env: + - TRAVISCONFIGPATH=/home/travis/gopath/src/github.com/pushrax/chihaya/config/example.json + services: - redis-server diff --git a/config/config_test.go b/config/config_test.go index c63f7f0..7cf6d6a 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -11,14 +11,21 @@ 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(os.ExpandEnv("$GOPATH/src/github.com/pushrax/chihaya/config/example.json")); err != nil { + if _, err := Open(getConfigPath()); err != nil { t.Error(err) } } func TestNewConfig(t *testing.T) { - contents, err := ioutil.ReadFile(os.ExpandEnv("$GOPATH/src/github.com/pushrax/chihaya/config/example.json")) + contents, err := ioutil.ReadFile(getConfigPath()) if err != nil { t.Error(err) } diff --git a/server/stats_test.go b/server/stats_test.go index bd0f31b..8eaeba7 100644 --- a/server/stats_test.go +++ b/server/stats_test.go @@ -6,7 +6,6 @@ package server import ( "errors" - "fmt" "net/http" "net/http/httptest" "os" @@ -18,13 +17,29 @@ import ( _ "github.com/pushrax/chihaya/storage/batter" ) -func TestStats(t *testing.T) { - testConfig, err := config.Open(os.ExpandEnv("$GOPATH/src/github.com/pushrax/chihaya/config/example.json")) - if err != nil { - t.Error(err) +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") } - fmt.Println(testConfig) + + testConfig, err := config.Open(path) + if err != nil { + return nil, err + } + s, err := New(testConfig) + if err != nil { + return nil, err + } + + return s, nil +} + +func TestStats(t *testing.T) { + s, err := NewServer() if err != nil { t.Error(err) }