Skip to content

Commit

Permalink
Test redirection for URLs with trailing slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
tchssk committed Sep 26, 2023
1 parent 09e20be commit ab57d85
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions http/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ func TestResolvePattern(t *testing.T) {
w := httptest.NewRecorder()
mux.ServeHTTP(w, req)
assert.True(t, called)
// Make sure the URL with a trailing slash is redirected.
called = false // Reset.
req, _ = http.NewRequest("GET", c.URL+"/", nil)
w = httptest.NewRecorder()
mux.ServeHTTP(w, req)
assert.Equal(t, http.StatusMovedPermanently, w.Code)
req, _ = http.NewRequest("GET", w.Header().Get("Location"), nil)
w = httptest.NewRecorder()
mux.ServeHTTP(w, req)
assert.True(t, called)
})
}
}

0 comments on commit ab57d85

Please sign in to comment.