github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/pkg/gateway/path/resolver_test.go (about) 1 package path 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestResolvePath(t *testing.T) { 9 type args struct { 10 encodedPath string 11 } 12 tests := []struct { 13 name string 14 args args 15 want ResolvedPath 16 wantErr bool 17 }{ 18 { 19 name: "branch with root", 20 args: args{encodedPath: "/Branch-1"}, 21 want: ResolvedPath{Ref: "Branch-1", Path: "", WithPath: false}, 22 }, 23 { 24 name: "branch without root", 25 args: args{encodedPath: "Branch-1"}, 26 want: ResolvedPath{Ref: "Branch-1", Path: "", WithPath: false}, 27 }, 28 { 29 name: "branch and path", 30 args: args{encodedPath: "Branch-1/dir1/file1"}, 31 want: ResolvedPath{Ref: "Branch-1", Path: "dir1/file1", WithPath: true}, 32 }, 33 { 34 name: "branch ends with delimiter", 35 args: args{encodedPath: "Branch-1/"}, 36 want: ResolvedPath{Ref: "Branch-1", Path: "", WithPath: true}, 37 }, 38 { 39 name: "branch with path ends with delimiter", 40 args: args{encodedPath: "Branch-1/path2/"}, 41 want: ResolvedPath{Ref: "Branch-1", Path: "path2/", WithPath: true}, 42 }, 43 { 44 name: "branch with path both start and end with delimiter", 45 args: args{encodedPath: "/Branch-1/path2/"}, 46 want: ResolvedPath{Ref: "Branch-1", Path: "path2/", WithPath: true}, 47 }, 48 { 49 name: "branch with path that start and end with delimiter", 50 args: args{encodedPath: "Branch-1//path3/"}, 51 want: ResolvedPath{Ref: "Branch-1", Path: "/path3/", WithPath: true}, 52 }, 53 { 54 name: "empty", 55 args: args{}, 56 want: ResolvedPath{}, 57 }, 58 { 59 name: "have some space", 60 args: args{encodedPath: "BrAnCh99/ a dir / a file"}, 61 want: ResolvedPath{ 62 Ref: "BrAnCh99", 63 Path: " a dir / a file", 64 WithPath: true, 65 }, 66 }, 67 { 68 name: "ref with tilde", 69 args: args{encodedPath: "main~1"}, 70 want: ResolvedPath{Ref: "main~1"}, 71 }, 72 { 73 name: "ref with tilde and multiple separators", 74 args: args{encodedPath: "main~1//a/b"}, 75 want: ResolvedPath{Ref: "main~1", Path: "/a/b", WithPath: true}, 76 }, 77 } 78 for _, tt := range tests { 79 t.Run(tt.name, func(t *testing.T) { 80 got, err := ResolvePath(tt.args.encodedPath) 81 if (err != nil) != tt.wantErr { 82 t.Errorf("ResolvePath() error = %v, wantErr %v", err, tt.wantErr) 83 return 84 } 85 if !reflect.DeepEqual(got, tt.want) { 86 t.Errorf("ResolvePath() got = %v, want %v", got, tt.want) 87 } 88 }) 89 } 90 }