1package command 2 3import ( 4 "path/filepath" 5 "reflect" 6 "strings" 7 "testing" 8) 9 10const FixturePath = "./test-fixtures" 11 12func TestLoadConfig(t *testing.T) { 13 config, err := LoadConfig(filepath.Join(FixturePath, "config.hcl")) 14 if err != nil { 15 t.Fatalf("err: %s", err) 16 } 17 18 expected := &DefaultConfig{ 19 TokenHelper: "foo", 20 } 21 if !reflect.DeepEqual(expected, config) { 22 t.Fatalf("bad: %#v", config) 23 } 24} 25 26func TestLoadConfig_noExist(t *testing.T) { 27 config, err := LoadConfig("nope/not-once/.never") 28 if err != nil { 29 t.Fatal(err) 30 } 31 32 if config.TokenHelper != "" { 33 t.Errorf("expected %q to be %q", config.TokenHelper, "") 34 } 35} 36 37func TestParseConfig_badKeys(t *testing.T) { 38 _, err := ParseConfig(` 39token_helper = "/token" 40nope = "true" 41`) 42 if err == nil { 43 t.Fatal("expected error") 44 } 45 46 if !strings.Contains(err.Error(), `invalid key "nope" on line 3`) { 47 t.Errorf("bad error: %s", err.Error()) 48 } 49} 50