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