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

Function TestStoreHTTPErrorHandling

storage/remote/client_test.go:43–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

41var longErrMessage = strings.Repeat("error message", maxErrMsgLen)
42
43func TestStoreHTTPErrorHandling(t *testing.T) {
44 tests := []struct {
45 code int
46 err error
47 }{
48 {
49 code: 200,
50 err: nil,
51 },
52 {
53 code: 300,
54 err: errors.New("server returned HTTP status 300 Multiple Choices: " + longErrMessage[:maxErrMsgLen]),
55 },
56 {
57 code: 404,
58 err: errors.New("server returned HTTP status 404 Not Found: " + longErrMessage[:maxErrMsgLen]),
59 },
60 {
61 code: 500,
62 err: RecoverableError{errors.New("server returned HTTP status 500 Internal Server Error: " + longErrMessage[:maxErrMsgLen]), defaultBackoff},
63 },
64 }
65
66 for _, test := range tests {
67 server := httptest.NewServer(
68 http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
69 http.Error(w, longErrMessage, test.code)
70 }),
71 )
72
73 serverURL, err := url.Parse(server.URL)
74 require.NoError(t, err)
75
76 conf := &ClientConfig{
77 URL: &config_util.URL{URL: serverURL},
78 Timeout: model.Duration(time.Second),
79 }
80
81 hash, err := toHash(conf)
82 require.NoError(t, err)
83 c, err := NewWriteClient(hash, conf)
84 require.NoError(t, err)
85
86 _, err = c.Store(context.Background(), []byte{}, 0)
87 if test.err != nil {
88 require.EqualError(t, err, test.err.Error())
89 } else {
90 require.NoError(t, err)
91 }
92
93 server.Close()
94 }
95}
96
97func TestClientRetryAfter(t *testing.T) {
98 setupServer := func(statusCode int) *httptest.Server {

Callers

nothing calls this directly

Calls 7

StoreMethod · 0.95
toHashFunction · 0.85
NewWriteClientFunction · 0.85
DurationMethod · 0.80
ErrorMethod · 0.65
ParseMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…