gitea源码

local_test.go 1.2KB

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