MCPcopy Create free account
hub / github.com/imroc/req / testError

Function testError

request_test.go:725–759  ·  view source on GitHub ↗
(t *testing.T, c *Client)

Source from the content-addressed store, hash-verified

723}
724
725func testError(t *testing.T, c *Client) {
726 var errMsg ErrorMessage
727 resp, err := c.R().
728 SetQueryParam("username", "").
729 SetErrorResult(&errMsg).
730 Get("/search")
731 assertIsError(t, resp, err)
732 tests.AssertEqual(t, 10000, errMsg.ErrorCode)
733
734 errMsg = ErrorMessage{}
735 resp, err = c.R().
736 SetQueryParam("username", "test").
737 SetErrorResult(&errMsg).
738 Get("/search")
739 assertIsError(t, resp, err)
740 tests.AssertEqual(t, 10001, errMsg.ErrorCode)
741
742 errMsg = ErrorMessage{}
743 resp, err = c.R().
744 SetQueryParam("username", "test").
745 SetQueryParam("type", "xml"). // auto unmarshal to xml
746 SetErrorResult(&errMsg).
747 Get("/search")
748 assertIsError(t, resp, err)
749 tests.AssertEqual(t, 10001, errMsg.ErrorCode)
750
751 c.SetCommonErrorResult(&errMsg)
752 resp, err = c.R().
753 SetQueryParam("username", "").
754 Get("/search")
755 assertIsError(t, resp, err)
756 em, ok := resp.Error().(*ErrorMessage)
757 tests.AssertEqual(t, true, ok)
758 tests.AssertEqual(t, 10000, em.ErrorCode)
759}
760
761func TestForm(t *testing.T) {
762 testWithAllTransport(t, testForm)

Callers

nothing calls this directly

Calls 8

AssertEqualFunction · 0.92
assertIsErrorFunction · 0.85
SetErrorResultMethod · 0.80
SetQueryParamMethod · 0.80
RMethod · 0.80
SetCommonErrorResultMethod · 0.80
GetMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…