mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-05 03:45:15 +02:00
- Massive replacement of changing `code.gitea.io/gitea` to `forgejo.org`. - Resolves forgejo/discussions#258 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7337 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Reviewed-by: Beowulf <beowulf@beocode.eu> Reviewed-by: Panagiotis "Ivory" Vasilopoulos <git@n0toose.net> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package storage
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"forgejo.org/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestBuildLocalPath(t *testing.T) {
|
|
kases := []struct {
|
|
localDir string
|
|
path string
|
|
expected string
|
|
}{
|
|
{
|
|
"/a",
|
|
"0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
"/a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
},
|
|
{
|
|
"/a",
|
|
"../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
"/a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
},
|
|
{
|
|
"/a",
|
|
"0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
"/a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
},
|
|
{
|
|
"/b",
|
|
"a/../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
"/b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
},
|
|
{
|
|
"/b",
|
|
"a\\..\\0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
"/b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
|
|
},
|
|
}
|
|
|
|
for _, k := range kases {
|
|
t.Run(k.path, func(t *testing.T) {
|
|
l := LocalStorage{dir: k.localDir}
|
|
|
|
assert.EqualValues(t, k.expected, l.buildLocalPath(k.path))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLocalStorageIterator(t *testing.T) {
|
|
dir := filepath.Join(os.TempDir(), "TestLocalStorageIteratorTestDir")
|
|
testStorageIterator(t, setting.LocalStorageType, &setting.Storage{Path: dir})
|
|
}
|