archive_windows_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // +build windows
  2. package archive
  3. import (
  4. "testing"
  5. )
  6. func TestCanonicalTarNameForPath(t *testing.T) {
  7. cases := []struct {
  8. in, expected string
  9. shouldFail bool
  10. }{
  11. {"foo", "foo", false},
  12. {"foo/bar", "___", true}, // unix-styled windows path must fail
  13. {`foo\bar`, "foo/bar", false},
  14. }
  15. for _, v := range cases {
  16. if out, err := CanonicalTarNameForPath(v.in); err != nil && !v.shouldFail {
  17. t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err)
  18. } else if v.shouldFail && err == nil {
  19. t.Fatalf("canonical path call should have pailed with error. in=%s out=%s", v.in, out)
  20. } else if !v.shouldFail && out != v.expected {
  21. t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out)
  22. }
  23. }
  24. }
  25. func TestCanonicalTarName(t *testing.T) {
  26. cases := []struct {
  27. in string
  28. isDir bool
  29. expected string
  30. }{
  31. {"foo", false, "foo"},
  32. {"foo", true, "foo/"},
  33. {`foo\bar`, false, "foo/bar"},
  34. {`foo\bar`, true, "foo/bar/"},
  35. }
  36. for _, v := range cases {
  37. if out, err := canonicalTarName(v.in, v.isDir); err != nil {
  38. t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err)
  39. } else if out != v.expected {
  40. t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out)
  41. }
  42. }
  43. }