MCPcopy
hub / github.com/larksuite/cli / TestHandleResponse_NonJSONError_404

Function TestHandleResponse_NonJSONError_404

internal/client/response_test.go:333–352  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

331}
332
333func TestHandleResponse_NonJSONError_404(t *testing.T) {
334 resp := newApiRespWithStatus(404, []byte("404 page not found"), map[string]string{"Content-Type": "text/plain"})
335
336 var out, errOut bytes.Buffer
337 err := HandleResponse(resp, ResponseOptions{Out: &out, ErrOut: &errOut, FileIO: &localfileio.LocalFileIO{}})
338 if err == nil {
339 t.Fatal("expected error for 404 text/plain")
340 }
341 got := err.Error()
342 if !strings.Contains(got, "HTTP 404") || !strings.Contains(got, "404 page not found") {
343 t.Errorf("expected 'HTTP 404: 404 page not found', got: %s", got)
344 }
345 var apiErr *errs.APIError
346 if !errors.As(err, &apiErr) {
347 t.Errorf("expected *errs.APIError, got %T", err)
348 }
349 if output.ExitCodeOf(err) != output.ExitAPI {
350 t.Errorf("expected ExitAPI (%d), got %d", output.ExitAPI, output.ExitCodeOf(err))
351 }
352}
353
354func TestHandleResponse_NonJSONError_502(t *testing.T) {
355 resp := newApiRespWithStatus(502, []byte("<html>Bad Gateway</html>"), map[string]string{"Content-Type": "text/html"})

Callers

nothing calls this directly

Calls 6

ExitCodeOfFunction · 0.92
newApiRespWithStatusFunction · 0.85
HandleResponseFunction · 0.85
AsMethod · 0.80
ErrorMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected