MCPcopy Index your code
hub / github.com/imroc/req / TestAutoDetectRequestContentType

Function TestAutoDetectRequestContentType

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

Source from the content-addressed store, hash-verified

874}
875
876func TestAutoDetectRequestContentType(t *testing.T) {
877 c := tc()
878 resp, err := c.R().SetBody(getTestFileContent(t, "sample-image.png")).Post("/content-type")
879 assertSuccess(t, resp, err)
880 tests.AssertEqual(t, "image/png", resp.String())
881
882 resp, err = c.R().SetBodyJsonString(`{"msg": "test"}`).Post("/content-type")
883 assertSuccess(t, resp, err)
884 tests.AssertEqual(t, header.JsonContentType, resp.String())
885
886 resp, err = c.R().SetContentType(header.XmlContentType).SetBody(`{"msg": "test"}`).Post("/content-type")
887 assertSuccess(t, resp, err)
888 tests.AssertEqual(t, header.XmlContentType, resp.String())
889
890 resp, err = c.R().SetBody(`<html><body><h1>hello</h1></body></html>`).Post("/content-type")
891 assertSuccess(t, resp, err)
892 tests.AssertEqual(t, "text/html; charset=utf-8", resp.String())
893
894 resp, err = c.R().SetBody(`hello world`).Post("/content-type")
895 assertSuccess(t, resp, err)
896 tests.AssertEqual(t, header.PlainTextContentType, resp.String())
897}
898
899func TestSetFileUploadCheck(t *testing.T) {
900 c := tc()

Callers

nothing calls this directly

Calls 10

AssertEqualFunction · 0.92
tcFunction · 0.85
getTestFileContentFunction · 0.85
assertSuccessFunction · 0.85
RMethod · 0.80
SetBodyJsonStringMethod · 0.80
SetContentTypeMethod · 0.80
PostMethod · 0.45
SetBodyMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…