remote_write: add a unit test to make sure the write client sends

the extra http headers as expected

This will help letting prometheus off the hook from situations like
https://github.com/prometheus/prometheus/issues/13030

Signed-off-by: machine424 <ayoubmrini424@gmail.com>
This commit is contained in:
machine424 2023-11-09 15:38:35 +01:00
parent ab2a7bb74f
commit 0996b78326
No known key found for this signature in database
GPG Key ID: A4B001A4FDEE017D
1 changed files with 40 additions and 0 deletions

View File

@ -168,3 +168,43 @@ func TestRetryAfterDuration(t *testing.T) {
require.Equal(t, c.expected, retryAfterDuration(c.tInput), c.name)
}
}
func TestClientHeaders(t *testing.T) {
headersToSend := map[string]string{"Foo": "Bar", "Baz": "qux"}
var called bool
server := httptest.NewServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
called = true
receivedHeaders := r.Header
for name, value := range headersToSend {
require.Equal(
t,
[]string{value},
receivedHeaders.Values(name),
"expected %v to be part of the received headers %v",
headersToSend,
receivedHeaders,
)
}
}),
)
defer server.Close()
serverURL, err := url.Parse(server.URL)
require.NoError(t, err)
conf := &ClientConfig{
URL: &config_util.URL{URL: serverURL},
Timeout: model.Duration(time.Second),
Headers: headersToSend,
}
c, err := NewWriteClient("c", conf)
require.NoError(t, err)
err = c.Store(context.Background(), []byte{}, 0)
require.NoError(t, err)
require.True(t, called, "The remote server wasn't called")
}