Support setting headers on requests to Prometheus

This commit is contained in:
Johannes 'fish' Ziemke 2021-07-13 14:56:37 +02:00
parent 93450fc29f
commit d84340cc85
3 changed files with 64 additions and 5 deletions

View file

@ -20,6 +20,7 @@ import (
"net/http"
"os"
"path/filepath"
"reflect"
"testing"
)
@ -146,3 +147,41 @@ func TestMakePrometheusCAClient(t *testing.T) {
}
}
}
func TestParseHeaderArgs(t *testing.T) {
tests := []struct {
args []string
headers http.Header
}{
{
headers: http.Header{},
},
{
args: []string{"foo=bar"},
headers: http.Header{
"Foo": []string{"bar"},
},
},
{
args: []string{"foo"},
headers: http.Header{
"Foo": []string{""},
},
},
{
args: []string{"foo=bar", "foo=baz", "bux=baz=23"},
headers: http.Header{
"Foo": []string{"bar", "baz"},
"Bux": []string{"baz=23"},
},
},
}
for _, test := range tests {
got := parseHeaderArgs(test.args)
if !reflect.DeepEqual(got, test.headers) {
t.Errorf("Expected %#v but got %#v", test.headers, got)
}
}
}