github.com/kcmerrill/common.go@v0.0.0-20180608223308-4114128a6803/config/config_test.go (about) 1 package config 2 3 import ( 4 "os" 5 "strings" 6 "testing" 7 ) 8 9 func TestFindAndCombine(t *testing.T) { 10 c, _ := os.Getwd() 11 if os.Chdir("t/alfred/level.one/level.two") != nil { 12 t.Fatalf("Test directories do not exist") 13 } 14 15 dir, contents, err := FindAndCombine("alfred", "yml") 16 17 if err != nil { 18 t.Errorf("Huh. Wasn't expecting an error.") 19 } 20 21 if !strings.Contains(string(contents), "a") { 22 t.Errorf("Expected a to be in the file") 23 } 24 25 if !strings.Contains(string(contents), "b") { 26 t.Errorf("Expected b to be in the file") 27 } 28 29 if !strings.Contains(string(contents), "c") { 30 t.Errorf("Expected c to be in the file") 31 } 32 33 if !strings.HasSuffix(dir, "common.go/config/t") { 34 t.Errorf("Expecting the directory to contain common.go/config/t/ instead got " + dir) 35 } 36 37 os.Chdir(c) 38 } 39 40 func TestFindConfig(t *testing.T) { 41 c, _ := os.Getwd() 42 if os.Chdir("t/a/b/c") != nil { 43 t.Errorf("Unable to switch to directory 'c'") 44 } 45 if dir, contents, err := Find("a.yml"); err == nil { 46 if string(contents) != "a\n" { 47 t.Errorf("Contents of a.yml != 'a'") 48 } 49 if !strings.HasSuffix(dir, "common.go/config/t/a/") { 50 t.Errorf("Expecting the directory to contain common.go/config/t/a/ instead got " + dir) 51 } 52 } else { 53 t.Errorf("Unable to find a.yml") 54 } 55 os.Chdir(c) 56 }