mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 08:21:11 +00:00 
			
		
		
		
	**Backport:** https://codeberg.org/forgejo/forgejo/pulls/7337 - Massive replacement of changing `code.gitea.io/gitea` to `forgejo.org`. - Resolves forgejo/discussions#258 Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7354 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
		
			
				
	
	
		
			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})
 | 
						|
}
 |