Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for client request with and without trailing slash. #522

Merged
merged 2 commits into from
Feb 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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