Skip to content

Commit

Permalink
Add unit tests to prevent panicing on missing Request
Browse files Browse the repository at this point in the history
  • Loading branch information
pofl committed Jun 15, 2020
1 parent fcbde60 commit f44dd35
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions context_test.go
Expand Up @@ -410,6 +410,21 @@ func TestContextQuery(t *testing.T) {
assert.Empty(t, c.PostForm("foo"))
}

func TestContextDefaultQueryOnEmptyRequest(t *testing.T) {
c, _ := CreateTestContext(httptest.NewRecorder()) // here c.Request == nil
assert.NotPanics(t, func() {
value, ok := c.GetQuery("NoKey")
assert.False(t, ok)
assert.Empty(t, value)
})
assert.NotPanics(t, func() {
assert.Equal(t, "nada", c.DefaultQuery("NoKey", "nada"))
})
assert.NotPanics(t, func() {
assert.Empty(t, c.Query("NoKey"))
})
}

func TestContextQueryAndPostForm(t *testing.T) {
c, _ := CreateTestContext(httptest.NewRecorder())
body := bytes.NewBufferString("foo=bar&page=11&both=&foo=second")
Expand Down

0 comments on commit f44dd35

Please sign in to comment.