(t *testing.T)
| 927 | } |
| 928 | |
| 929 | func TestResponse_Text(t *testing.T) { |
| 930 | t.Run("basic", func(t *testing.T) { |
| 931 | reporter := newMockReporter(t) |
| 932 | |
| 933 | headers := map[string][]string{ |
| 934 | "Content-Type": {"text/plain; charset=utf-8"}, |
| 935 | } |
| 936 | |
| 937 | body := `hello, world!` |
| 938 | |
| 939 | httpResp := &http.Response{ |
| 940 | StatusCode: http.StatusOK, |
| 941 | Header: http.Header(headers), |
| 942 | Body: io.NopCloser(bytes.NewBufferString(body)), |
| 943 | } |
| 944 | |
| 945 | resp := NewResponse(reporter, httpResp) |
| 946 | assert.Equal(t, body, resp.Body().Raw()) |
| 947 | resp.chain.assert(t, success) |
| 948 | |
| 949 | respText := resp.Text() |
| 950 | respText.chain.assert(t, success) |
| 951 | resp.chain.assert(t, success) |
| 952 | assert.Equal(t, "hello, world!", respText.Raw()) |
| 953 | |
| 954 | NewResponse(reporter, httpResp).HasContentType("text/plain"). |
| 955 | chain.assert(t, success) |
| 956 | |
| 957 | NewResponse(reporter, httpResp).HasContentType("text/plain", "utf-8"). |
| 958 | chain.assert(t, success) |
| 959 | |
| 960 | NewResponse(reporter, httpResp).HasContentType("application/json"). |
| 961 | chain.assert(t, failure) |
| 962 | |
| 963 | NewResponse(reporter, httpResp). |
| 964 | chain.assert(t, success) |
| 965 | }) |
| 966 | |
| 967 | t.Run("read failure", func(t *testing.T) { |
| 968 | reporter := newMockReporter(t) |
| 969 | |
| 970 | headers := map[string][]string{ |
| 971 | "Content-Type": {"text/plain; charset=utf-8"}, |
| 972 | } |
| 973 | |
| 974 | body := newMockBody(`hello, world!`) |
| 975 | body.readErr = errors.New("read error") |
| 976 | |
| 977 | httpResp := &http.Response{ |
| 978 | StatusCode: http.StatusOK, |
| 979 | Header: http.Header(headers), |
| 980 | Body: body, |
| 981 | } |
| 982 | |
| 983 | resp := NewResponse(reporter, httpResp) |
| 984 | resp.chain.assert(t, success) |
| 985 | |
| 986 | respText := resp.Text() |
nothing calls this directly
no test coverage detected
searching dependent graphs…