2013-07-05 12:50:52 +02:00
|
|
|
// Copyright 2013 The Chihaya Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by the BSD 2-Clause license,
|
|
|
|
// which can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2013-08-29 05:44:45 +02:00
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
2013-07-17 05:37:03 +02:00
|
|
|
"os"
|
2013-07-05 12:50:52 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2013-08-29 06:24:31 +02:00
|
|
|
func getConfigPath() string {
|
|
|
|
if os.Getenv("TRAVISCONFIGPATH") != "" {
|
|
|
|
return os.Getenv("TRAVISCONFIGPATH")
|
|
|
|
}
|
|
|
|
return os.ExpandEnv("$GOPATH/src/github.com/pushrax/chihaya/config/example.json")
|
|
|
|
}
|
|
|
|
|
2013-08-29 05:44:45 +02:00
|
|
|
func TestOpenConfig(t *testing.T) {
|
2013-08-29 06:24:31 +02:00
|
|
|
if _, err := Open(getConfigPath()); err != nil {
|
2013-07-05 12:50:52 +02:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
2013-07-17 05:37:03 +02:00
|
|
|
|
2013-08-29 05:44:45 +02:00
|
|
|
func TestNewConfig(t *testing.T) {
|
2013-08-29 06:24:31 +02:00
|
|
|
contents, err := ioutil.ReadFile(getConfigPath())
|
2013-07-17 05:37:03 +02:00
|
|
|
if err != nil {
|
2013-08-29 05:44:45 +02:00
|
|
|
t.Error(err)
|
2013-07-17 05:37:03 +02:00
|
|
|
}
|
2013-08-29 05:44:45 +02:00
|
|
|
buff := bytes.NewBuffer(contents)
|
|
|
|
if _, err := newConfig(buff); err != nil {
|
|
|
|
t.Error(err)
|
2013-07-17 05:37:03 +02:00
|
|
|
}
|
|
|
|
}
|