2016-05-02 11:42:21 +00:00
|
|
|
package config
|
2016-04-01 03:01:54 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Test file is missing
|
|
|
|
func TestMissingFile(t *testing.T) {
|
|
|
|
filename := "test"
|
|
|
|
_, err := LoadConfYaml(filename)
|
|
|
|
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test wrong json format
|
|
|
|
func TestWrongYAMLormat(t *testing.T) {
|
|
|
|
content := []byte(`Wrong format`)
|
|
|
|
|
|
|
|
filename := "tempfile"
|
|
|
|
|
|
|
|
if err := ioutil.WriteFile(filename, content, 0644); err != nil {
|
|
|
|
log.Fatalf("WriteFile %s: %v", filename, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// clean up
|
|
|
|
defer os.Remove(filename)
|
|
|
|
|
|
|
|
// parse JSON format error
|
|
|
|
_, err := LoadConfYaml(filename)
|
|
|
|
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test config file.
|
|
|
|
func TestReadConfig(t *testing.T) {
|
2016-04-11 13:32:40 +00:00
|
|
|
config, err := LoadConfYaml("../config/config.yml")
|
2016-04-01 03:01:54 +00:00
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "8088", config.Core.Port)
|
2016-04-11 13:32:40 +00:00
|
|
|
assert.True(t, config.Android.Enabled)
|
2016-04-01 03:01:54 +00:00
|
|
|
}
|