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

Function TestWithNonFatal500WithBody

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

Source from the content-addressed store, hash-verified

64}
65
66func TestWithNonFatal500WithBody(t *testing.T) {
67 c, _ := NewClient(nil)
68
69 var called uint32
70
71 nonFatalCodes := map[int]string{
72 501: "custom 501 error",
73 507: "custom 507 error",
74 509: "custom 509 error",
75 }
76
77 for nonFatalCode, expectedErr := range nonFatalCodes {
78 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
79 if r.URL.String() != "/test" {
80 w.WriteHeader(http.StatusNotFound)
81 return
82 }
83
84 atomic.AddUint32(&called, 1)
85 w.Header().Set("Content-Type", "application/json")
86 w.WriteHeader(nonFatalCode)
87 w.Write([]byte(`{"message":"` + expectedErr + `"}`))
88 }))
89
90 req, err := http.NewRequest("GET", srv.URL+"/test", nil)
91 assert.Nil(t, err)
92
93 _, err = c.Do(req)
94 t.Logf("non fatal code %d", nonFatalCode)
95 assert.NotNil(t, err)
96 assert.Equal(t, expectedErr, err.Error())
97 srv.Close()
98 }
99
100 assert.EqualValues(t, 3, called)
101}
102
103func TestAuthErrWithoutBody(t *testing.T) {
104 var called uint32

Callers

nothing calls this directly

Calls 10

DoMethod · 0.95
LogfMethod · 0.80
NewClientFunction · 0.70
StringMethod · 0.65
SetMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.45
NewRequestMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected