MCPcopy Create free account
hub / github.com/amp-labs/connectors / TestJSONHTTPClient_Get_ErrorResponse

Function TestJSONHTTPClient_Get_ErrorResponse

common/json_test.go:198–223  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

196}
197
198func TestJSONHTTPClient_Get_ErrorResponse(t *testing.T) {
199 t.Parallel()
200
201 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
202 w.Header().Set("Content-Type", "application/json")
203 w.WriteHeader(http.StatusNotFound)
204 _, _ = w.Write([]byte(`{"error":"not found"}`))
205 }))
206 defer server.Close()
207
208 httpClient := &HTTPClient{
209 Client: &mockAuthClient{
210 doFunc: server.Client().Do,
211 },
212 }
213
214 client := &JSONHTTPClient{
215 HTTPClient: httpClient,
216 }
217
218 ctx := context.Background()
219 _, err := client.Get(ctx, server.URL)
220
221 require.Error(t, err)
222 assert.Contains(t, err.Error(), "not found")
223}
224
225func TestJSONHTTPClient_Get_ErrorPostProcessor(t *testing.T) {
226 t.Parallel()

Callers

nothing calls this directly

Calls 6

GetMethod · 0.95
ContainsMethod · 0.80
WriteMethod · 0.65
SetMethod · 0.45
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected