s3api_object_handlers_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. }