(t *testing.T)
| 825 | } |
| 826 | |
| 827 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…