(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func 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 | |
| 40 | func TestFatalWithBody(t *testing.T) { |
| 41 | var called uint32 |
nothing calls this directly
no test coverage detected