archive_windows_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //go:build windows
  2. // +build windows
  3. package archive // import "github.com/docker/docker/pkg/archive"
  4. import (
  5. "os"
  6. "path/filepath"
  7. "testing"
  8. )
  9. func TestCopyFileWithInvalidDest(t *testing.T) {
  10. // TODO Windows: This is currently failing. Not sure what has
  11. // recently changed in CopyWithTar as used to pass. Further investigation
  12. // is required.
  13. t.Skip("Currently fails")
  14. folder, err := os.MkdirTemp("", "docker-archive-test")
  15. if err != nil {
  16. t.Fatal(err)
  17. }
  18. defer os.RemoveAll(folder)
  19. dest := "c:dest"
  20. srcFolder := filepath.Join(folder, "src")
  21. src := filepath.Join(folder, "src", "src")
  22. err = os.MkdirAll(srcFolder, 0740)
  23. if err != nil {
  24. t.Fatal(err)
  25. }
  26. os.WriteFile(src, []byte("content"), 0777)
  27. err = defaultCopyWithTar(src, dest)
  28. if err == nil {
  29. t.Fatalf("archiver.CopyWithTar should throw an error on invalid dest.")
  30. }
  31. }
  32. func TestCanonicalTarName(t *testing.T) {
  33. cases := []struct {
  34. in string
  35. isDir bool
  36. expected string
  37. }{
  38. {"foo", false, "foo"},
  39. {"foo", true, "foo/"},
  40. {`foo\bar`, false, "foo/bar"},
  41. {`foo\bar`, true, "foo/bar/"},
  42. }
  43. for _, v := range cases {
  44. if canonicalTarName(v.in, v.isDir) != v.expected {
  45. t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, canonicalTarName(v.in, v.isDir))
  46. }
  47. }
  48. }
  49. func TestChmodTarEntry(t *testing.T) {
  50. cases := []struct {
  51. in, expected os.FileMode
  52. }{
  53. {0000, 0111},
  54. {0777, 0755},
  55. {0644, 0755},
  56. {0755, 0755},
  57. {0444, 0555},
  58. }
  59. for _, v := range cases {
  60. if out := chmodTarEntry(v.in); out != v.expected {
  61. t.Fatalf("wrong chmod. expected:%v got:%v", v.expected, out)
  62. }
  63. }
  64. }