@@ -36,14 +36,17 @@ func TestRouter_ServeHTTP(t *testing.T) {
36
36
url := baseAPI
37
37
if l .Path != "" {
38
38
switch l .TestType {
39
- case "checkpath" , "checkpathnotrailingslash" , "chaining" , "chaining-nofallthrough" :
39
+ case "checkpath" ,
40
+ "checkpathnotrailingslash" ,
41
+ "chaining" ,
42
+ "chaining-nofallthrough" :
40
43
{
41
44
url = strings .Join ([]string {url , l .Path }, "" )
42
45
}
43
- case "checkparams" :
46
+ case "checkparams" , "widlcardwithouttrailingslash" :
44
47
{
45
48
for idx , key := range l .ParamKeys {
46
- // in case of wildcard params, they have to replaced first for proper URL construction
49
+ // in case of wildcard params, they have to be replaced first for proper URL construction
47
50
l .Path = strings .Replace (l .Path , ":" + key + "*" , l .Params [idx ], 1 )
48
51
l .Path = strings .Replace (l .Path , ":" + key , l .Params [idx ], 1 )
49
52
}
@@ -60,7 +63,7 @@ func TestRouter_ServeHTTP(t *testing.T) {
60
63
router .ServeHTTP (respRec , req )
61
64
62
65
switch l .TestType {
63
- case "checkpath" , "checkpathnotrailingslash" :
66
+ case "checkpath" , "checkpathnotrailingslash" , "widlcardwithouttrailingslash" :
64
67
{
65
68
err = checkPath (req , respRec )
66
69
}
@@ -99,7 +102,15 @@ func TestRouter_ServeHTTP(t *testing.T) {
99
102
)
100
103
}
101
104
}
105
+ } else if err == nil && l .WantErr {
106
+ t .Errorf (
107
+ "'%s' (%s '%s') expected error, but received nil" ,
108
+ l .Name ,
109
+ l .Method ,
110
+ url ,
111
+ )
102
112
}
113
+
103
114
err = checkMiddleware (req , respRec )
104
115
if err != nil {
105
116
t .Error (err .Error ())
@@ -138,7 +149,7 @@ func getRoutes() []*Route {
138
149
},
139
150
)
140
151
}
141
- case "checkpathnotrailingslash" :
152
+ case "checkpathnotrailingslash" , "widlcardwithouttrailingslash" :
142
153
{
143
154
rr = append (rr ,
144
155
& Route {
@@ -152,6 +163,7 @@ func getRoutes() []*Route {
152
163
)
153
164
154
165
}
166
+
155
167
case "chaining" :
156
168
{
157
169
rr = append (
@@ -462,6 +474,24 @@ func testTable() []struct {
462
474
Params : []string {"hello/world/hi/there/-/~/./again" },
463
475
WantErr : false ,
464
476
},
477
+ {
478
+ Name : "Check with wildcard - 3" ,
479
+ TestType : "widlcardwithouttrailingslash" ,
480
+ Path : "/wildcard3/:a*" ,
481
+ Method : http .MethodGet ,
482
+ ParamKeys : []string {"a" },
483
+ Params : []string {"hello/world/hi/there/-/~/./again/" },
484
+ WantErr : true ,
485
+ },
486
+ {
487
+ Name : "Check with wildcard - 4" ,
488
+ TestType : "widlcardwithouttrailingslash" ,
489
+ Path : "/wildcard3/:a*" ,
490
+ Method : http .MethodGet ,
491
+ ParamKeys : []string {"a" },
492
+ Params : []string {"hello/world/hi/there/-/~/./again" },
493
+ WantErr : false ,
494
+ },
465
495
{
466
496
Name : "Check not implemented" ,
467
497
TestType : "notimplemented" ,
0 commit comments