code.gitea.io/gitea@v1.19.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  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestBuildLocalPath(t *testing.T) {
    13  	kases := []struct {
    14  		localDir string
    15  		path     string
    16  		expected string
    17  	}{
    18  		{
    19  			"a",
    20  			"0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    21  			"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    22  		},
    23  		{
    24  			"a",
    25  			"../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    26  			"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    27  		},
    28  		{
    29  			"a",
    30  			"0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    31  			"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    32  		},
    33  		{
    34  			"b",
    35  			"a/../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    36  			"b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    37  		},
    38  		{
    39  			"b",
    40  			"a\\..\\0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    41  			"b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    42  		},
    43  	}
    44  
    45  	for _, k := range kases {
    46  		t.Run(k.path, func(t *testing.T) {
    47  			l := LocalStorage{dir: k.localDir}
    48  
    49  			assert.EqualValues(t, k.expected, l.buildLocalPath(k.path))
    50  		})
    51  	}
    52  }