MCPcopy Index your code
hub / github.com/docker/docker-agent / TestStatusError

Function TestStatusError

pkg/modelerrors/modelerrors_test.go:689–715  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

687}
688
689func TestStatusError(t *testing.T) {
690 t.Parallel()
691
692 t.Run("Error() includes status code and wrapped message", func(t *testing.T) {
693 t.Parallel()
694 underlying := errors.New("rate limit exceeded")
695 se := &StatusError{StatusCode: 429, Err: underlying}
696 assert.Equal(t, "HTTP 429: rate limit exceeded", se.Error())
697 })
698
699 t.Run("Unwrap() allows errors.Is traversal", func(t *testing.T) {
700 t.Parallel()
701 sentinel := errors.New("sentinel")
702 se := &StatusError{StatusCode: 500, Err: sentinel}
703 assert.ErrorIs(t, se, sentinel)
704 })
705
706 t.Run("errors.As finds StatusError in chain", func(t *testing.T) {
707 t.Parallel()
708 se := &StatusError{StatusCode: 429, RetryAfter: 10 * time.Second, Err: errors.New("rate limited")}
709 wrapped := fmt.Errorf("outer: %w", se)
710 var found *StatusError
711 require.ErrorAs(t, wrapped, &found)
712 assert.Equal(t, 429, found.StatusCode)
713 assert.Equal(t, 10*time.Second, found.RetryAfter)
714 })
715}
716
717func TestWrapHTTPError(t *testing.T) {
718 t.Parallel()

Callers

nothing calls this directly

Calls 3

ErrorMethod · 0.95
RunMethod · 0.65
NewMethod · 0.45

Tested by

no test coverage detected