MCPcopy
hub / github.com/git-lfs/git-lfs / TestFatalWithBody

Function TestFatalWithBody

lfsapi/response_test.go:40–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestFatalWithBody(t *testing.T) {
41 var called uint32
42 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
43 if r.URL.String() != "/test" {
44 w.WriteHeader(http.StatusNotFound)
45 return
46 }
47
48 atomic.AddUint32(&called, 1)
49 w.Header().Set("Content-Type", "application/json")
50 w.WriteHeader(500)
51 w.Write([]byte(`{"message":"custom fatal error"}`))
52 }))
53 defer srv.Close()
54
55 req, err := http.NewRequest("GET", srv.URL+"/test", nil)
56 assert.Nil(t, err)
57
58 c, _ := NewClient(nil)
59 _, err = c.Do(req)
60 assert.NotNil(t, err)
61 assert.True(t, errors.IsFatalError(err))
62 assert.Equal(t, "Fatal error: custom fatal error", err.Error())
63 assert.EqualValues(t, 1, called)
64}
65
66func TestWithNonFatal500WithBody(t *testing.T) {
67 c, _ := NewClient(nil)

Callers

nothing calls this directly

Calls 10

DoMethod · 0.95
IsFatalErrorFunction · 0.92
NewClientFunction · 0.70
StringMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.65
WriteMethod · 0.45
NewRequestMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected