MCPcopy
hub / github.com/gin-gonic/gin / TestContextQuery

Function TestContextQuery

context_test.go:726–759  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

724}
725
726func TestContextQuery(t *testing.T) {
727 c, _ := CreateTestContext(httptest.NewRecorder())
728 c.Request, _ = http.NewRequest(http.MethodGet, "http://example.com/?foo=bar&page=10&id=", nil)
729
730 value, ok := c.GetQuery("foo")
731 assert.True(t, ok)
732 assert.Equal(t, "bar", value)
733 assert.Equal(t, "bar", c.DefaultQuery("foo", "none"))
734 assert.Equal(t, "bar", c.Query("foo"))
735
736 value, ok = c.GetQuery("page")
737 assert.True(t, ok)
738 assert.Equal(t, "10", value)
739 assert.Equal(t, "10", c.DefaultQuery("page", "0"))
740 assert.Equal(t, "10", c.Query("page"))
741
742 value, ok = c.GetQuery("id")
743 assert.True(t, ok)
744 assert.Empty(t, value)
745 assert.Empty(t, c.DefaultQuery("id", "nada"))
746 assert.Empty(t, c.Query("id"))
747
748 value, ok = c.GetQuery("NoKey")
749 assert.False(t, ok)
750 assert.Empty(t, value)
751 assert.Equal(t, "nada", c.DefaultQuery("NoKey", "nada"))
752 assert.Empty(t, c.Query("NoKey"))
753
754 // postform should not mess
755 value, ok = c.GetPostForm("page")
756 assert.False(t, ok)
757 assert.Empty(t, value)
758 assert.Empty(t, c.PostForm("foo"))
759}
760
761func TestContextInitQueryCache(t *testing.T) {
762 validURL, err := url.Parse("https://github.com/gin-gonic/gin/pull/3969?key=value&otherkey=othervalue")

Callers

nothing calls this directly

Calls 6

CreateTestContextFunction · 0.85
GetQueryMethod · 0.80
DefaultQueryMethod · 0.80
QueryMethod · 0.80
GetPostFormMethod · 0.80
PostFormMethod · 0.80

Tested by

no test coverage detected