MCPcopy Create free account
hub / github.com/gavv/httpexpect / TestRequest_URLQuery

Function TestRequest_URLQuery

request_test.go:827–955  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

825}
826
827func TestRequest_URLQuery(t *testing.T) {
828 client := &mockClient{}
829
830 config := Config{
831 BaseURL: "http://example.com",
832 Client: client,
833 Reporter: newMockReporter(t),
834 }
835
836 checkOK := func(req *Request, url string) {
837 client.req = nil
838 req.Expect()
839 req.chain.assert(t, success)
840 assert.Equal(t, url, client.req.URL.String())
841 }
842
843 checkFailed := func(req *Request) {
844 req.chain.assert(t, failure)
845 }
846
847 t.Run("WithQuery", func(t *testing.T) {
848 req := NewRequestC(config, "GET", "/path").
849 WithQuery("aa", "foo").WithQuery("bb", 123).WithQuery("cc", "*&@")
850 checkOK(req,
851 "http://example.com/path?aa=foo&bb=123&cc=%2A%26%40")
852 })
853
854 t.Run("WithQueryObject map", func(t *testing.T) {
855 req := NewRequestC(config, "GET", "/path").
856 WithQuery("aa", "foo").
857 WithQueryObject(map[string]interface{}{
858 "bb": 123,
859 "cc": "*&@",
860 })
861 checkOK(req,
862 "http://example.com/path?aa=foo&bb=123&cc=%2A%26%40")
863 })
864
865 type S struct {
866 B int `url:"bb"`
867 C string `url:"cc"`
868 D string `url:"-"`
869 }
870
871 t.Run("WithQueryObject struct", func(t *testing.T) {
872 req := NewRequestC(config, "GET", "/path").
873 WithQueryObject(S{123, "*&@", "dummy"}).WithQuery("aa", "foo")
874 checkOK(req,
875 "http://example.com/path?aa=foo&bb=123&cc=%2A%26%40")
876 })
877
878 t.Run("WithQueryObject pointer to struct", func(t *testing.T) {
879 req := NewRequestC(config, "GET", "/path").
880 WithQueryObject(&S{123, "*&@", "dummy"}).WithQuery("aa", "foo")
881 checkOK(req,
882 "http://example.com/path?aa=foo&bb=123&cc=%2A%26%40")
883 })
884

Callers

nothing calls this directly

Calls 11

newMockReporterFunction · 0.85
NewRequestCFunction · 0.85
mockQueryEncoderTypeAlias · 0.85
assertMethod · 0.80
WithQueryMethod · 0.80
WithQueryObjectMethod · 0.80
WithQueryEncoderMethod · 0.80
WithQueryStringMethod · 0.80
ExpectMethod · 0.45
EqualMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…