@@ -2064,72 +2064,62 @@ func BenchmarkPathUnescape(b *testing.B) {
2064
2064
}
2065
2065
2066
2066
func TestJoinPath (t * testing.T ) {
2067
- type args struct {
2068
- baseUrl string
2069
- elem []string
2070
- }
2071
2067
tests := []struct {
2072
- name string
2073
- args args
2074
- wantResult string
2075
- wantErr bool
2068
+ base string
2069
+ elem [] string
2070
+ out string
2071
+ err bool
2076
2072
}{
2077
2073
{
2078
- name : "test normal url" ,
2079
- args : args {
2080
- baseUrl : "https://go.googlesource.com" ,
2081
- elem : []string {"go" },
2082
- },
2083
- wantResult : "https://go.googlesource.com/go" ,
2084
- wantErr : false ,
2074
+ base : "https://go.googlesource.com" ,
2075
+ elem : []string {"go" },
2076
+ out : "https://go.googlesource.com/go" ,
2077
+ err : false ,
2085
2078
},
2086
2079
{
2087
- name : "test .. parent url" ,
2088
- args : args {
2089
- baseUrl : "https://go.googlesource.com/a/b/c" ,
2090
- elem : []string {"../../../go" },
2091
- },
2092
- wantResult : "https://go.googlesource.com/go" ,
2093
- wantErr : false ,
2080
+ base : "https://go.googlesource.com/a/b/c" ,
2081
+ elem : []string {"../../../go" },
2082
+ out : "https://go.googlesource.com/go" ,
2083
+ err : false ,
2094
2084
},
2095
2085
{
2096
- name : "test . cul path" ,
2097
- args : args {
2098
- baseUrl : "https://go.googlesource.com/" ,
2099
- elem : []string {"./go" },
2100
- },
2101
- wantResult : "https://go.googlesource.com/go" ,
2102
- wantErr : false ,
2086
+ base : "https://go.googlesource.com/" ,
2087
+ elem : []string {"./go" },
2088
+ out : "https://go.googlesource.com/go" ,
2089
+ err : false ,
2103
2090
},
2104
2091
{
2105
- name : "test multiple Separator" ,
2106
- args : args {
2107
- baseUrl : "https://go.googlesource.com//" ,
2108
- elem : []string {"/go" },
2109
- },
2110
- wantResult : "https://go.googlesource.com/go" ,
2111
- wantErr : false ,
2092
+ base : "https://go.googlesource.com//" ,
2093
+ elem : []string {"/go" },
2094
+ out : "https://go.googlesource.com/go" ,
2095
+ err : false ,
2112
2096
},
2113
2097
{
2114
- name : "test more elems" ,
2115
- args : args {
2116
- baseUrl : "https://go.googlesource.com//" ,
2117
- elem : []string {"/go" , "a" , "b" , "c" },
2118
- },
2119
- wantResult : "https://go.googlesource.com/go/a/b/c" ,
2120
- wantErr : false ,
2098
+ base : "https://go.googlesource.com//" ,
2099
+ elem : []string {"/go" , "a" , "b" , "c" },
2100
+ out : "https://go.googlesource.com/go/a/b/c" ,
2101
+ err : false ,
2121
2102
},
2122
2103
}
2123
2104
for _ , tt := range tests {
2124
- t .Run (tt .name , func (t * testing.T ) {
2125
- gotResult , err := JoinPath (tt .args .baseUrl , tt .args .elem ... )
2126
- if (err != nil ) != tt .wantErr {
2127
- t .Errorf ("JoinPath() error = %v, wantErr %v" , err , tt .wantErr )
2128
- return
2105
+ if out , err := JoinPath (tt .base , tt .elem ... ); out != tt .out || (err != nil ) != tt .err {
2106
+ wantErr := "nil"
2107
+ if tt .err {
2108
+ wantErr = "non-nil error"
2129
2109
}
2130
- if gotResult != tt .wantResult {
2131
- t .Errorf ("JoinPath() = %v, want %v" , gotResult , tt .wantResult )
2110
+ t .Errorf ("JoinPath(%q, %q) = %q, %v, want %q, %v" , tt .base , tt .elem , out , err , tt .out , wantErr )
2111
+ }
2112
+ u , err := Parse (tt .base )
2113
+ if err == nil {
2114
+ u = u .JoinPath (tt .elem ... )
2115
+ }
2116
+ out := u .String ()
2117
+ if out != tt .out || (err != nil ) != tt .err {
2118
+ wantErr := "nil"
2119
+ if tt .err {
2120
+ wantErr = "non-nil error"
2132
2121
}
2133
- })
2122
+ t .Errorf ("JoinPath(%q, %q) = %q, %v, want %q, %v" , tt .base , tt .elem , out , err , tt .out , wantErr )
2123
+ }
2134
2124
}
2135
2125
}
0 commit comments