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

Function TestResponse_Form

response_test.go:993–1101  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

991}
992
993func TestResponse_Form(t *testing.T) {
994 t.Run("basic", func(t *testing.T) {
995 reporter := newMockReporter(t)
996
997 headers := map[string][]string{
998 "Content-Type": {"application/x-www-form-urlencoded"},
999 }
1000
1001 body := `a=1&b=2`
1002
1003 httpResp := &http.Response{
1004 StatusCode: http.StatusOK,
1005 Header: http.Header(headers),
1006 Body: io.NopCloser(bytes.NewBufferString(body)),
1007 }
1008
1009 resp := NewResponse(reporter, httpResp)
1010 assert.Equal(t, body, resp.Body().Raw())
1011 resp.chain.assert(t, success)
1012
1013 respForm := resp.Form()
1014 respForm.chain.assert(t, success)
1015 resp.chain.assert(t, success)
1016 assert.Equal(t,
1017 map[string]interface{}{"a": "1", "b": "2"}, respForm.Raw())
1018
1019 NewResponse(reporter, httpResp).HasContentType("application/x-www-form-urlencoded").
1020 chain.assert(t, success)
1021
1022 NewResponse(reporter, httpResp).HasContentType("application/x-www-form-urlencoded", "").
1023 chain.assert(t, success)
1024
1025 NewResponse(reporter, httpResp).HasContentType("text/plain").
1026 chain.assert(t, failure)
1027 })
1028
1029 t.Run("bad body", func(t *testing.T) {
1030 reporter := newMockReporter(t)
1031
1032 headers := map[string][]string{
1033 "Content-Type": {"application/x-www-form-urlencoded"},
1034 }
1035
1036 body := "%"
1037
1038 httpResp := &http.Response{
1039 StatusCode: http.StatusOK,
1040 Header: http.Header(headers),
1041 Body: io.NopCloser(bytes.NewBufferString(body)),
1042 }
1043
1044 resp := NewResponse(reporter, httpResp)
1045 resp.chain.assert(t, success)
1046
1047 respForm := resp.Form()
1048 respForm.chain.assert(t, failure)
1049 resp.chain.assert(t, failure)
1050 assert.Nil(t, respForm.Raw())

Callers

nothing calls this directly

Calls 10

BodyMethod · 0.95
FormMethod · 0.95
newMockReporterFunction · 0.85
NewResponseFunction · 0.85
newMockBodyFunction · 0.85
HeaderMethod · 0.80
assertMethod · 0.80
HasContentTypeMethod · 0.80
EqualMethod · 0.45
RawMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…