MCPcopy Index your code
hub / github.com/prometheus/prometheus / TestReturnAPIError

Function TestReturnAPIError

web/api/v1/api_test.go:4635–4672  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4633}
4634
4635func TestReturnAPIError(t *testing.T) {
4636 cases := []struct {
4637 err error
4638 expected errorType
4639 }{
4640 {
4641 err: promql.ErrStorage{Err: errors.New("storage error")},
4642 expected: errorInternal,
4643 }, {
4644 err: fmt.Errorf("wrapped: %w", promql.ErrStorage{Err: errors.New("storage error")}),
4645 expected: errorInternal,
4646 }, {
4647 err: promql.ErrQueryTimeout("timeout error"),
4648 expected: errorTimeout,
4649 }, {
4650 err: fmt.Errorf("wrapped: %w", promql.ErrQueryTimeout("timeout error")),
4651 expected: errorTimeout,
4652 }, {
4653 err: promql.ErrQueryCanceled("canceled error"),
4654 expected: errorCanceled,
4655 }, {
4656 err: fmt.Errorf("wrapped: %w", promql.ErrQueryCanceled("canceled error")),
4657 expected: errorCanceled,
4658 }, {
4659 err: errors.New("exec error"),
4660 expected: errorExec,
4661 }, {
4662 err: context.Canceled,
4663 expected: errorCanceled,
4664 },
4665 }
4666
4667 for ix, c := range cases {
4668 actual := returnAPIError(c.err)
4669 require.Error(t, actual, ix)
4670 require.Equal(t, c.expected, actual.typ, ix)
4671 }
4672}
4673
4674// This is a global to avoid the benchmark being optimized away.
4675var testResponseWriter = httptest.ResponseRecorder{}

Callers

nothing calls this directly

Calls 4

ErrQueryTimeoutTypeAlias · 0.92
ErrQueryCanceledTypeAlias · 0.92
returnAPIErrorFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…