archive_unix_test.go 1.3 KB

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