dispatchers_windows_test.go 1.5 KB

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