github.com/rothwerx/packer@v0.9.0/post-processor/atlas/util_test.go (about) 1 package atlas 2 3 import ( 4 "path/filepath" 5 "testing" 6 ) 7 8 func TestLongestCommonPrefix(t *testing.T) { 9 sep := string(filepath.Separator) 10 cases := []struct { 11 Input []string 12 Output string 13 }{ 14 { 15 []string{"foo", "bar"}, 16 "", 17 }, 18 { 19 []string{"foo", "foobar"}, 20 "", 21 }, 22 { 23 []string{"foo" + sep, "foo" + sep + "bar"}, 24 "foo" + sep, 25 }, 26 { 27 []string{sep + "foo" + sep, sep + "bar"}, 28 sep, 29 }, 30 } 31 32 for _, tc := range cases { 33 actual := longestCommonPrefix(tc.Input) 34 if actual != tc.Output { 35 t.Fatalf("bad: %#v\n\n%#v", actual, tc.Input) 36 } 37 } 38 }