dispatchers_windows_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //go:build windows
  2. // +build windows
  3. package dockerfile // import "github.com/docker/docker/builder/dockerfile"
  4. import "testing"
  5. func TestNormalizeWorkdir(t *testing.T) {
  6. tests := []struct{ platform, current, requested, expected, etext string }{
  7. {"windows", ``, ``, ``, `cannot normalize nothing`},
  8. {"windows", ``, `C:`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
  9. {"windows", ``, `C:.`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
  10. {"windows", `c:`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
  11. {"windows", `c:.`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`},
  12. {"windows", ``, `a`, `C:\a`, ``},
  13. {"windows", ``, `c:\foo`, `C:\foo`, ``},
  14. {"windows", ``, `c:\\foo`, `C:\foo`, ``},
  15. {"windows", ``, `\foo`, `C:\foo`, ``},
  16. {"windows", ``, `\\foo`, `C:\foo`, ``},
  17. {"windows", ``, `/foo`, `C:\foo`, ``},
  18. {"windows", ``, `C:/foo`, `C:\foo`, ``},
  19. {"windows", `C:\foo`, `bar`, `C:\foo\bar`, ``},
  20. {"windows", `C:\foo`, `/bar`, `C:\bar`, ``},
  21. {"windows", `C:\foo`, `\bar`, `C:\bar`, ``},
  22. {"linux", ``, ``, ``, `cannot normalize nothing`},
  23. {"linux", ``, `foo`, `/foo`, ``},
  24. {"linux", ``, `/foo`, `/foo`, ``},
  25. {"linux", `/foo`, `bar`, `/foo/bar`, ``},
  26. {"linux", `/foo`, `/bar`, `/bar`, ``},
  27. {"linux", `\a`, `b\c`, `/a/b/c`, ``},
  28. }
  29. for _, i := range tests {
  30. r, e := normalizeWorkdir(i.platform, i.current, i.requested)
  31. if i.etext != "" && e == nil {
  32. t.Fatalf("TestNormalizeWorkingDir Expected error %s for '%s' '%s', got no error", i.etext, i.current, i.requested)
  33. }
  34. if i.etext != "" && e.Error() != i.etext {
  35. t.Fatalf("TestNormalizeWorkingDir Expected error %s for '%s' '%s', got %s", i.etext, i.current, i.requested, e.Error())
  36. }
  37. if r != i.expected {
  38. t.Fatalf("TestNormalizeWorkingDir Expected '%s' for '%s' '%s', got '%s'", i.expected, i.current, i.requested, r)
  39. }
  40. }
  41. }