github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/storage/local_test.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package storage
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestBuildLocalPath(t *testing.T) {
    15  	kases := []struct {
    16  		localDir string
    17  		path     string
    18  		expected string
    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  			"a",
    32  			"0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    33  			"a/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  			"b",
    42  			"a\\..\\0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    43  			"b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    44  		},
    45  	}
    46  
    47  	for _, k := range kases {
    48  		t.Run(k.path, func(t *testing.T) {
    49  			l := LocalStorage{dir: k.localDir}
    50  
    51  			assert.EqualValues(t, k.expected, l.buildLocalPath(k.path))
    52  		})
    53  	}
    54  }