archive_windows_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // +build windows
  2. package archive
  3. import (
  4. "os"
  5. "testing"
  6. )
  7. func TestCanonicalTarNameForPath(t *testing.T) {
  8. cases := []struct {
  9. in, expected string
  10. shouldFail bool
  11. }{
  12. {"foo", "foo", false},
  13. {"foo/bar", "___", true}, // unix-styled windows path must fail
  14. {`foo\bar`, "foo/bar", false},
  15. }
  16. for _, v := range cases {
  17. if out, err := CanonicalTarNameForPath(v.in); err != nil && !v.shouldFail {
  18. t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err)
  19. } else if v.shouldFail && err == nil {
  20. t.Fatalf("canonical path call should have failed with error. in=%s out=%s", v.in, out)
  21. } else if !v.shouldFail && out != v.expected {
  22. t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out)
  23. }
  24. }
  25. }
  26. func TestCanonicalTarName(t *testing.T) {
  27. cases := []struct {
  28. in string
  29. isDir bool
  30. expected string
  31. }{
  32. {"foo", false, "foo"},
  33. {"foo", true, "foo/"},
  34. {`foo\bar`, false, "foo/bar"},
  35. {`foo\bar`, true, "foo/bar/"},
  36. }
  37. for _, v := range cases {
  38. if out, err := canonicalTarName(v.in, v.isDir); err != nil {
  39. t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err)
  40. } else if out != v.expected {
  41. t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out)
  42. }
  43. }
  44. }
  45. func TestChmodTarEntry(t *testing.T) {
  46. cases := []struct {
  47. in, expected os.FileMode
  48. }{
  49. {0000, 0111},
  50. {0777, 0755},
  51. {0644, 0755},
  52. {0755, 0755},
  53. {0444, 0555},
  54. }
  55. for _, v := range cases {
  56. if out := chmodTarEntry(v.in); out != v.expected {
  57. t.Fatalf("wrong chmod. expected:%v got:%v", v.expected, out)
  58. }
  59. }
  60. }