MCPcopy Create free account
hub / github.com/containers/image / TestHandleErrorResponse401ValidBody

Function TestHandleErrorResponse401ValidBody

docker/distribution_error_test.go:147–160  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestHandleErrorResponse401ValidBody(t *testing.T) {
148 json := []byte("{\"errors\":[{\"code\":\"UNAUTHORIZED\",\"message\":\"action requires authentication\"}]}")
149 response := &http.Response{
150 Status: "401 Unauthorized",
151 StatusCode: 401,
152 Body: io.NopCloser(bytes.NewReader(json)),
153 }
154 err := handleErrorResponse(response)
155
156 expectedMsg := "unauthorized: action requires authentication"
157 if !strings.Contains(err.Error(), expectedMsg) {
158 t.Errorf("Expected \"%s\", got: \"%s\"", expectedMsg, err.Error())
159 }
160}
161
162func TestHandleErrorResponse401WithInvalidBody(t *testing.T) {
163 json := []byte("{invalid json}")

Callers

nothing calls this directly

Calls 3

handleErrorResponseFunction · 0.85
ContainsMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…