-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add accept header check for prometheus mime type (#7958)
* Add accept header check for prometheus mime type * Fix small header filter bug. Add test
- Loading branch information
1 parent
73fd8f3
commit e1b6971
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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) | ||
} | ||
} | ||
} |