internals_windows_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // +build windows
  2. package dockerfile
  3. import "testing"
  4. func TestNormaliseDest(t *testing.T) {
  5. tests := []struct{ current, requested, expected, etext string }{
  6. {``, `D:\`, ``, `Windows does not support TEST with a destinations not on the system drive (C:)`},
  7. {``, `e:/`, ``, `Windows does not support TEST with a destinations not on the system drive (C:)`},
  8. {`invalid`, `./c1`, ``, `Current WorkingDir invalid is not platform consistent`},
  9. {`C:`, ``, ``, `Current WorkingDir C: is not platform consistent`},
  10. {`C`, ``, ``, `Current WorkingDir C is not platform consistent`},
  11. {`D:\`, `.`, ``, "Windows does not support TEST with relative paths when WORKDIR is not the system drive"},
  12. {``, `D`, `D`, ``},
  13. {``, `./a1`, `.\a1`, ``},
  14. {``, `.\b1`, `.\b1`, ``},
  15. {``, `/`, `\`, ``},
  16. {``, `\`, `\`, ``},
  17. {``, `c:/`, `\`, ``},
  18. {``, `c:\`, `\`, ``},
  19. {``, `.`, `.`, ``},
  20. {`C:\wdd`, `./a1`, `\wdd\a1`, ``},
  21. {`C:\wde`, `.\b1`, `\wde\b1`, ``},
  22. {`C:\wdf`, `/`, `\`, ``},
  23. {`C:\wdg`, `\`, `\`, ``},
  24. {`C:\wdh`, `c:/`, `\`, ``},
  25. {`C:\wdi`, `c:\`, `\`, ``},
  26. {`C:\wdj`, `.`, `\wdj`, ``},
  27. {`C:\wdk`, `foo/bar`, `\wdk\foo\bar`, ``},
  28. {`C:\wdl`, `foo\bar`, `\wdl\foo\bar`, ``},
  29. {`C:\wdm`, `foo/bar/`, `\wdm\foo\bar\`, ``},
  30. {`C:\wdn`, `foo\bar/`, `\wdn\foo\bar\`, ``},
  31. }
  32. for _, i := range tests {
  33. got, err := normaliseDest("TEST", i.current, i.requested)
  34. if err != nil && i.etext == "" {
  35. t.Fatalf("TestNormaliseDest Got unexpected error %q for %s %s. ", err.Error(), i.current, i.requested)
  36. }
  37. if i.etext != "" && ((err == nil) || (err != nil && err.Error() != i.etext)) {
  38. if err == nil {
  39. t.Fatalf("TestNormaliseDest Expected an error for %s %s but didn't get one", i.current, i.requested)
  40. } else {
  41. t.Fatalf("TestNormaliseDest Wrong error text for %s %s - %s", i.current, i.requested, err.Error())
  42. }
  43. }
  44. if i.etext == "" && got != i.expected {
  45. t.Fatalf("TestNormaliseDest Expected %q for %q and %q. Got %q", i.expected, i.current, i.requested, got)
  46. }
  47. }
  48. }