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

Function TestAuthErrWithBody

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

Source from the content-addressed store, hash-verified

12)
13
14func TestAuthErrWithBody(t *testing.T) {
15 var called uint32
16 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17 if r.URL.String() != "/test" {
18 w.WriteHeader(http.StatusNotFound)
19 return
20 }
21
22 atomic.AddUint32(&called, 1)
23 w.Header().Set("Content-Type", "application/json")
24 w.WriteHeader(401)
25 w.Write([]byte(`{"message":"custom auth error"}`))
26 }))
27 defer srv.Close()
28
29 req, err := http.NewRequest("GET", srv.URL+"/test", nil)
30 assert.Nil(t, err)
31
32 c, _ := NewClient(nil)
33 _, err = c.Do(req)
34 assert.NotNil(t, err)
35 assert.True(t, errors.IsAuthError(err))
36 assert.Equal(t, "Authentication required: custom auth error", err.Error())
37 assert.EqualValues(t, 1, called)
38}
39
40func TestFatalWithBody(t *testing.T) {
41 var called uint32

Callers

nothing calls this directly

Calls 10

DoMethod · 0.95
IsAuthErrorFunction · 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