internals_windows_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //go:build windows
  2. // +build windows
  3. package dockerfile // import "github.com/docker/docker/builder/dockerfile"
  4. import (
  5. "fmt"
  6. "testing"
  7. "gotest.tools/v3/assert"
  8. is "gotest.tools/v3/assert/cmp"
  9. )
  10. func TestNormalizeDest(t *testing.T) {
  11. tests := []struct{ current, requested, expected, etext string }{
  12. {``, `D:\`, ``, `Windows does not support destinations not on the system drive (C:)`},
  13. {``, `e:/`, ``, `Windows does not support destinations not on the system drive (C:)`},
  14. {`invalid`, `./c1`, ``, `Current WorkingDir invalid is not platform consistent`},
  15. {`C:`, ``, ``, `Current WorkingDir C: is not platform consistent`},
  16. {`C`, ``, ``, `Current WorkingDir C is not platform consistent`},
  17. {`D:\`, `.`, ``, "Windows does not support relative paths when WORKDIR is not the system drive"},
  18. {``, `D`, `D`, ``},
  19. {``, `./a1`, `.\a1`, ``},
  20. {``, `.\b1`, `.\b1`, ``},
  21. {``, `/`, `\`, ``},
  22. {``, `\`, `\`, ``},
  23. {``, `c:/`, `\`, ``},
  24. {``, `c:\`, `\`, ``},
  25. {``, `.`, `.`, ``},
  26. {`C:\wdd`, `./a1`, `\wdd\a1`, ``},
  27. {`C:\wde`, `.\b1`, `\wde\b1`, ``},
  28. {`C:\wdf`, `/`, `\`, ``},
  29. {`C:\wdg`, `\`, `\`, ``},
  30. {`C:\wdh`, `c:/`, `\`, ``},
  31. {`C:\wdi`, `c:\`, `\`, ``},
  32. {`C:\wdj`, `.`, `\wdj`, ``},
  33. {`C:\wdk`, `foo/bar`, `\wdk\foo\bar`, ``},
  34. {`C:\wdl`, `foo\bar`, `\wdl\foo\bar`, ``},
  35. {`C:\wdm`, `foo/bar/`, `\wdm\foo\bar\`, ``},
  36. {`C:\wdn`, `foo\bar/`, `\wdn\foo\bar\`, ``},
  37. }
  38. for _, testcase := range tests {
  39. msg := fmt.Sprintf("Input: %s, %s", testcase.current, testcase.requested)
  40. actual, err := normalizeDest(testcase.current, testcase.requested)
  41. if testcase.etext == "" {
  42. if !assert.Check(t, err, msg) {
  43. continue
  44. }
  45. assert.Check(t, is.Equal(testcase.expected, actual), msg)
  46. } else {
  47. assert.Check(t, is.ErrorContains(err, testcase.etext))
  48. }
  49. }
  50. }