2019-12-11 19:59:19 +00:00
|
|
|
package metricsutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-01-09 22:56:34 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2019-12-11 19:59:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|