archive_unix_test.go 1018 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // +build !windows
  2. package archive
  3. import (
  4. "testing"
  5. )
  6. func TestCanonicalTarNameForPath(t *testing.T) {
  7. cases := []struct{ in, expected string }{
  8. {"foo", "foo"},
  9. {"foo/bar", "foo/bar"},
  10. {"foo/dir/", "foo/dir/"},
  11. }
  12. for _, v := range cases {
  13. if out, err := canonicalTarNameForPath(v.in); err != nil {
  14. t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err)
  15. } else if out != v.expected {
  16. t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out)
  17. }
  18. }
  19. }
  20. func TestCanonicalTarName(t *testing.T) {
  21. cases := []struct {
  22. in string
  23. isDir bool
  24. expected string
  25. }{
  26. {"foo", false, "foo"},
  27. {"foo", true, "foo/"},
  28. {"foo/bar", false, "foo/bar"},
  29. {"foo/bar", true, "foo/bar/"},
  30. }
  31. for _, v := range cases {
  32. if out, err := canonicalTarName(v.in, v.isDir); err != nil {
  33. t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err)
  34. } else if out != v.expected {
  35. t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out)
  36. }
  37. }
  38. }