code.gitea.io/gitea@v1.22.3/modules/storage/local_test.go (about)

     1  // Copyright 2022 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package storage
     5  
     6  import (
     7  	"os"
     8  	"path/filepath"
     9  	"testing"
    10  
    11  	"code.gitea.io/gitea/modules/setting"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestBuildLocalPath(t *testing.T) {
    17  	kases := []struct {
    18  		localDir string
    19  		path     string
    20  		expected string
    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  			"/a",
    34  			"0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    35  			"/a/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  			"/b",
    44  			"a\\..\\0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    45  			"/b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    46  		},
    47  	}
    48  
    49  	for _, k := range kases {
    50  		t.Run(k.path, func(t *testing.T) {
    51  			l := LocalStorage{dir: k.localDir}
    52  
    53  			assert.EqualValues(t, k.expected, l.buildLocalPath(k.path))
    54  		})
    55  	}
    56  }
    57  
    58  func TestLocalStorageIterator(t *testing.T) {
    59  	dir := filepath.Join(os.TempDir(), "TestLocalStorageIteratorTestDir")
    60  	testStorageIterator(t, setting.LocalStorageType, &setting.Storage{Path: dir})
    61  }