Skip to content

Commit

Permalink
Add test for client request with and without trailing slash. (#522)
Browse files Browse the repository at this point in the history
* Add test for client request with and without trailing slash.

* Correction.
  • Loading branch information
Gerrit91 committed Feb 28, 2023
1 parent 91574ed commit daf9981
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions web_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit daf9981

Please sign in to comment.