generic test config
This commit is contained in:
parent
6e7d6f1a31
commit
a2527aa4e2
4 changed files with 14 additions and 20 deletions
|
@ -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
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue