(t *testing.T)
| 134 | } |
| 135 | |
| 136 | func TestClient_ReadResponse(t *testing.T) { |
| 137 | // Setup a test server |
| 138 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 139 | w.WriteHeader(http.StatusOK) |
| 140 | w.Write([]byte("response body")) |
| 141 | })) |
| 142 | defer ts.Close() |
| 143 | |
| 144 | client := NewClient() |
| 145 | req := client.Request() |
| 146 | req.SetRequestURI(ts.URL).SetMethod("GET") |
| 147 | |
| 148 | if err := client.SendRequest(); err != nil { |
| 149 | t.Fatalf("expected no error, got %v", err) |
| 150 | } |
| 151 | |
| 152 | code, body, err := client.ReadResponse() |
| 153 | if err != nil { |
| 154 | t.Fatalf("expected no error, got %v", err) |
| 155 | } |
| 156 | if code != http.StatusOK { |
| 157 | t.Fatalf("expected status code 200, got %d", code) |
| 158 | } |
| 159 | if string(body) != "response body" { |
| 160 | t.Fatalf("expected body 'response body', got %s", body) |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | func TestClient_ReadResponse_NoResponse(t *testing.T) { |
| 165 | client := NewClient() |
nothing calls this directly
no test coverage detected