github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/builder/dockerfile/dispatchers_unix_test.go (about) 1 // +build !windows 2 3 package dockerfile 4 5 import ( 6 "runtime" 7 "testing" 8 ) 9 10 func TestNormalizeWorkdir(t *testing.T) { 11 testCases := []struct{ current, requested, expected, expectedError string }{ 12 {``, ``, ``, `cannot normalize nothing`}, 13 {``, `foo`, `/foo`, ``}, 14 {``, `/foo`, `/foo`, ``}, 15 {`/foo`, `bar`, `/foo/bar`, ``}, 16 {`/foo`, `/bar`, `/bar`, ``}, 17 } 18 19 for _, test := range testCases { 20 normalized, err := normalizeWorkdir(runtime.GOOS, test.current, test.requested) 21 22 if test.expectedError != "" && err == nil { 23 t.Fatalf("NormalizeWorkdir should return an error %s, got nil", test.expectedError) 24 } 25 26 if test.expectedError != "" && err.Error() != test.expectedError { 27 t.Fatalf("NormalizeWorkdir returned wrong error. Expected %s, got %s", test.expectedError, err.Error()) 28 } 29 30 if normalized != test.expected { 31 t.Fatalf("NormalizeWorkdir error. Expected %s for current %s and requested %s, got %s", test.expected, test.current, test.requested, normalized) 32 } 33 } 34 }