1// Copyright 2022 The Gitea Authors. All rights reserved. 2// Use of this source code is governed by a MIT-style 3// license that can be found in the LICENSE file. 4 5package storage 6 7import ( 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11) 12 13func TestBuildLocalPath(t *testing.T) { 14 kases := []struct { 15 localDir string 16 path string 17 expected string 18 }{ 19 { 20 "a", 21 "0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14", 22 "a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14", 23 }, 24 { 25 "a", 26 "../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14", 27 "a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14", 28 }, 29 { 30 "a", 31 "0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14", 32 "a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14", 33 }, 34 { 35 "b", 36 "a/../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14", 37 "b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14", 38 }, 39 { 40 "b", 41 "a\\..\\0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14", 42 "b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14", 43 }, 44 } 45 46 for _, k := range kases { 47 t.Run(k.path, func(t *testing.T) { 48 l := LocalStorage{dir: k.localDir} 49 50 assert.EqualValues(t, k.expected, l.buildLocalPath(k.path)) 51 }) 52 } 53} 54