2016-04-01 17:16:05 +00:00
|
|
|
package meta
|
2015-03-30 17:25:24 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"reflect"
|
2016-03-10 18:36:17 +00:00
|
|
|
"strings"
|
2015-03-30 17:25:24 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-04-01 17:16:05 +00:00
|
|
|
const FixturePath = "./test-fixtures"
|
|
|
|
|
2015-03-30 17:25:24 +00:00
|
|
|
func TestLoadConfig(t *testing.T) {
|
|
|
|
config, err := LoadConfig(filepath.Join(FixturePath, "config.hcl"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
TokenHelper: "foo",
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(expected, config) {
|
|
|
|
t.Fatalf("bad: %#v", config)
|
|
|
|
}
|
|
|
|
}
|
2016-03-10 18:36:17 +00:00
|
|
|
|
|
|
|
func TestLoadConfig_noExist(t *testing.T) {
|
|
|
|
config, err := LoadConfig("nope/not-once/.never")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.TokenHelper != "" {
|
|
|
|
t.Errorf("expected %q to be %q", config.TokenHelper, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseConfig_badKeys(t *testing.T) {
|
|
|
|
_, err := ParseConfig(`
|
|
|
|
token_helper = "/token"
|
|
|
|
nope = "true"
|
|
|
|
`)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "invalid key 'nope' on line 3") {
|
|
|
|
t.Errorf("bad error: %s", err.Error())
|
|
|
|
}
|
|
|
|
}
|