Merge pull request #13117 from machine424/remote-headers

remote_write: add a unit test to make sure the write client sends the extra http headers as expected
This commit is contained in:
Julien Pivotto 2023-11-09 09:52:23 -06:00 committed by GitHub
commit 8b2b7d3d7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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")
}