Skip to content

Commit 3d43a72

Browse files
committed
chi
1 parent 2aef54d commit 3d43a72

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

coderd/coderd_internal_test.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package coderd
22

33
import (
4+
"context"
45
"net/http"
56
"net/http/httptest"
67
"testing"
8+
9+
"github.com/go-chi/chi/v5"
10+
"github.com/stretchr/testify/assert"
711
)
812

913
func TestStripSlashesMW(t *testing.T) {
@@ -30,18 +34,26 @@ func TestStripSlashesMW(t *testing.T) {
3034

3135
for _, tt := range tests {
3236
tt := tt
33-
3437
t.Run(tt.name, func(t *testing.T) {
3538
t.Parallel()
3639

3740
req := httptest.NewRequest("GET", tt.inputPath, nil)
3841
rec := httptest.NewRecorder()
3942

43+
// Create a chi RouteContext and attach it to the request
44+
rctx := chi.NewRouteContext()
45+
rctx.RoutePath = tt.inputPath // Simulate chi route path
46+
req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, rctx))
47+
48+
// Pass the request through the middleware
4049
stripSlashesMW(handler).ServeHTTP(rec, req)
4150

42-
if req.URL.Path != tt.wantPath {
43-
t.Errorf("stripSlashesMW got path = %q, want %q", req.URL.Path, tt.wantPath)
44-
}
51+
// Get the updated chi RouteContext after middleware processing
52+
updatedCtx := chi.RouteContext(req.Context())
53+
54+
// Validate URL path
55+
assert.Equal(t, tt.wantPath, req.URL.Path)
56+
assert.Equal(t, tt.wantPath, updatedCtx.RoutePath)
4557
})
4658
}
4759
}

0 commit comments

Comments
 (0)