internals_windows_test.go 1.7 KB

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