diff --git a/web_service_test.go b/web_service_test.go index f316d26d..d2218169 100644 --- a/web_service_test.go +++ b/web_service_test.go @@ -327,6 +327,37 @@ func TestOptionsShortcut(t *testing.T) { } } +func TestClientWithAndWithoutTrailingSlash(t *testing.T) { + tearDown() + ws := new(WebService).Path("/test") + ws.Route(ws.PUT("/").To(return200)) + Add(ws) + + for _, tt := range []struct { + url string + wantCode int + }{ + // behavior before #520 + // {url: "http://here.com/test", wantCode: 404}, + // {url: "http://here.com/test/", wantCode: 200}, + // current behavior + {url: "http://here.com/test", wantCode: 200}, + {url: "http://here.com/test/", wantCode: 404}, + } { + t.Run(tt.url, func(t *testing.T) { + httpRequest, _ := http.NewRequest("PUT", tt.url, nil) + httpRequest.Header.Set("Accept", "*/*") + httpWriter := httptest.NewRecorder() + // override the default here + DefaultContainer.DoNotRecover(false) + DefaultContainer.dispatch(httpWriter, httpRequest) + if tt.wantCode != httpWriter.Code { + t.Errorf("Expected %d, got %d", tt.wantCode, httpWriter.Code) + } + }) + } +} + func newPanicingService() *WebService { ws := new(WebService).Path("") ws.Route(ws.GET("/fire").To(doPanic))