open-vault/helper/metricsutil/metricsutil_test.go
Michel Vocks a3fd1a5f3c Add accept header check for prometheus mime type (#7958)
* Add accept header check for prometheus mime type

* Fix small header filter bug. Add test
2019-12-11 11:59:19 -08:00

46 lines
921 B
Go

package metricsutil
import (
"github.com/hashicorp/vault/sdk/logical"
"testing"
)
func TestFormatFromRequest(t *testing.T) {
testCases := []struct {
original *logical.Request
expected string
}{
{
original: &logical.Request{Headers: map[string][]string{
"Accept": {
"application/vnd.google.protobuf",
"schema=\"prometheus/telemetry\"",
},
}},
expected: "prometheus",
},
{
original: &logical.Request{Headers: map[string][]string{
"Accept": {
"schema=\"prometheus\"",
},
}},
expected: "",
},
{
original: &logical.Request{Headers: map[string][]string{
"Accept": {
"application/openmetrics-text",
},
}},
expected: "prometheus",
},
}
for _, tCase := range testCases {
if metricsType := FormatFromRequest(tCase.original); metricsType != tCase.expected {
t.Fatalf("expected %s but got %s", tCase.expected, metricsType)
}
}
}