mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-13 06:47:28 -08:00
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:
commit
8b2b7d3d7a
|
@ -168,3 +168,43 @@ func TestRetryAfterDuration(t *testing.T) {
|
||||||
require.Equal(t, c.expected, retryAfterDuration(c.tInput), c.name)
|
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")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue