@@ -33,26 +33,37 @@ func TestStripSlashesMW(t *testing.T) {
33
33
34
34
for _ , tt := range tests {
35
35
tt := tt
36
- t .Run (tt .name , func (t * testing.T ) {
37
- t .Parallel ()
38
36
37
+ t .Run ("chi/" + tt .name , func (t * testing.T ) {
38
+ t .Parallel ()
39
39
req := httptest .NewRequest ("GET" , tt .inputPath , nil )
40
40
rec := httptest .NewRecorder ()
41
41
42
- // Create a chi RouteContext and attach it to the request
42
+ // given
43
43
rctx := chi .NewRouteContext ()
44
- rctx .RoutePath = tt .inputPath // Simulate chi route path
44
+ rctx .RoutePath = tt .inputPath
45
45
req = req .WithContext (context .WithValue (req .Context (), chi .RouteCtxKey , rctx ))
46
46
47
- // Pass the request through the middleware
47
+ // when
48
48
singleSlashMW (handler ).ServeHTTP (rec , req )
49
-
50
- // Get the updated chi RouteContext after middleware processing
51
49
updatedCtx := chi .RouteContext (req .Context ())
52
50
53
- // Validate URL path
54
- assert .Equal (t , tt .wantPath , req .URL .Path )
51
+ // then
52
+ assert .Equal (t , tt .inputPath , req .URL .Path )
55
53
assert .Equal (t , tt .wantPath , updatedCtx .RoutePath )
56
54
})
55
+
56
+ t .Run ("stdlib/" + tt .name , func (t * testing.T ) {
57
+ t .Parallel ()
58
+ req := httptest .NewRequest ("GET" , tt .inputPath , nil )
59
+ rec := httptest .NewRecorder ()
60
+
61
+ // when
62
+ singleSlashMW (handler ).ServeHTTP (rec , req )
63
+
64
+ // then
65
+ assert .Equal (t , tt .wantPath , req .URL .Path )
66
+ assert .Nil (t , chi .RouteContext (req .Context ()))
67
+ })
57
68
}
58
69
}
0 commit comments