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.

local_test.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package storage
  4. import (
  5. "os"
  6. "path/filepath"
  7. "testing"
  8. "code.gitea.io/gitea/modules/setting"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestBuildLocalPath(t *testing.T) {
  12. kases := []struct {
  13. localDir string
  14. path string
  15. expected string
  16. }{
  17. {
  18. "/a",
  19. "0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
  20. "/a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
  21. },
  22. {
  23. "/a",
  24. "../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
  25. "/a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
  26. },
  27. {
  28. "/a",
  29. "0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
  30. "/a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
  31. },
  32. {
  33. "/b",
  34. "a/../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
  35. "/b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
  36. },
  37. {
  38. "/b",
  39. "a\\..\\0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
  40. "/b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
  41. },
  42. }
  43. for _, k := range kases {
  44. t.Run(k.path, func(t *testing.T) {
  45. l := LocalStorage{dir: k.localDir}
  46. assert.EqualValues(t, k.expected, l.buildLocalPath(k.path))
  47. })
  48. }
  49. }
  50. func TestLocalStorageIterator(t *testing.T) {
  51. dir := filepath.Join(os.TempDir(), "TestLocalStorageIteratorTestDir")
  52. testStorageIterator(t, setting.LocalStorageType, &setting.Storage{Path: dir})
  53. }