You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.6 KiB

  1. package s3api
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestRemoveDuplicateSlashes(t *testing.T) {
  7. tests := []struct {
  8. name string
  9. path string
  10. expectedResult string
  11. }{
  12. {
  13. name: "empty",
  14. path: "",
  15. expectedResult: "",
  16. },
  17. {
  18. name: "slash",
  19. path: "/",
  20. expectedResult: "/",
  21. },
  22. {
  23. name: "object",
  24. path: "object",
  25. expectedResult: "object",
  26. },
  27. {
  28. name: "correct path",
  29. path: "/path/to/object",
  30. expectedResult: "/path/to/object",
  31. },
  32. {
  33. name: "path with duplicates",
  34. path: "///path//to/object//",
  35. expectedResult: "/path/to/object/",
  36. },
  37. }
  38. for _, tst := range tests {
  39. t.Run(tst.name, func(t *testing.T) {
  40. obj := removeDuplicateSlashes(tst.path)
  41. assert.Equal(t, tst.expectedResult, obj)
  42. })
  43. }
  44. }
  45. func TestS3ApiServer_toFilerUrl(t *testing.T) {
  46. tests := []struct {
  47. name string
  48. args string
  49. want string
  50. }{
  51. {
  52. "simple",
  53. "/uploads/eaf10b3b-3b3a-4dcd-92a7-edf2a512276e/67b8b9bf-7cca-4cb6-9b34-22fcb4d6e27d/Bildschirmfoto 2022-09-19 um 21.38.37.png",
  54. "/uploads/eaf10b3b-3b3a-4dcd-92a7-edf2a512276e/67b8b9bf-7cca-4cb6-9b34-22fcb4d6e27d/Bildschirmfoto%202022-09-19%20um%2021.38.37.png",
  55. },
  56. {
  57. "double prefix",
  58. "//uploads/t.png",
  59. "/uploads/t.png",
  60. },
  61. {
  62. "triple prefix",
  63. "///uploads/t.png",
  64. "/uploads/t.png",
  65. },
  66. {
  67. "empty prefix",
  68. "uploads/t.png",
  69. "/uploads/t.png",
  70. },
  71. }
  72. for _, tt := range tests {
  73. t.Run(tt.name, func(t *testing.T) {
  74. assert.Equalf(t, tt.want, urlEscapeObject(tt.args), "clean %v", tt.args)
  75. })
  76. }
  77. }