dispatchers_windows_test.go 2.0 KB

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