archive_windows_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 TestCanonicalTarNameForPath(t *testing.T) {
  33. cases := []struct {
  34. in, expected string
  35. }{
  36. {"foo", "foo"},
  37. {"foo/bar", "foo/bar"},
  38. {`foo\bar`, "foo/bar"},
  39. }
  40. for _, v := range cases {
  41. if CanonicalTarNameForPath(v.in) != v.expected {
  42. t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, CanonicalTarNameForPath(v.in))
  43. }
  44. }
  45. }
  46. func TestCanonicalTarName(t *testing.T) {
  47. cases := []struct {
  48. in string
  49. isDir bool
  50. expected string
  51. }{
  52. {"foo", false, "foo"},
  53. {"foo", true, "foo/"},
  54. {`foo\bar`, false, "foo/bar"},
  55. {`foo\bar`, true, "foo/bar/"},
  56. }
  57. for _, v := range cases {
  58. if canonicalTarName(v.in, v.isDir) != v.expected {
  59. t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, canonicalTarName(v.in, v.isDir))
  60. }
  61. }
  62. }
  63. func TestChmodTarEntry(t *testing.T) {
  64. cases := []struct {
  65. in, expected os.FileMode
  66. }{
  67. {0000, 0111},
  68. {0777, 0755},
  69. {0644, 0755},
  70. {0755, 0755},
  71. {0444, 0555},
  72. }
  73. for _, v := range cases {
  74. if out := chmodTarEntry(v.in); out != v.expected {
  75. t.Fatalf("wrong chmod. expected:%v got:%v", v.expected, out)
  76. }
  77. }
  78. }