mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-28 18:06:34 +02:00
metrics: restore global registry in unit tests (#5399)
Currently there appears to be a test order dependency between a couple of the info_test.go test cases and the Test_PrometheusHandler test. This can be exposed by running: go test -count 2 ./internal/telemetry/metrics The test cases in info_test.go overwrite the global 'registry' variable, which seems to prevent Test_PrometheusHandler from being able to export the internal Go metrics. Add a helper method to restore the original registry after these test cases.
This commit is contained in:
parent
69cb6f53de
commit
247cd175fe
1 changed files with 8 additions and 2 deletions
|
@ -65,7 +65,7 @@ func Test_SetDBConfigInfo(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_SetBuildInfo(t *testing.T) {
|
||||
registry = newMetricRegistry()
|
||||
initTemporaryMetricsRegistry(t)
|
||||
|
||||
version.Version = "v0.0.1"
|
||||
version.GitCommit = "deadbeef"
|
||||
|
@ -84,7 +84,7 @@ func Test_SetBuildInfo(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_AddPolicyCountCallback(t *testing.T) {
|
||||
registry = newMetricRegistry()
|
||||
initTemporaryMetricsRegistry(t)
|
||||
|
||||
wantValue := int64(42)
|
||||
wantLabels := []metricdata.LabelValue{
|
||||
|
@ -106,3 +106,9 @@ func Test_RegisterInfoMetrics(t *testing.T) {
|
|||
t.Error("Did not find enough registries")
|
||||
}
|
||||
}
|
||||
|
||||
func initTemporaryMetricsRegistry(t *testing.T) {
|
||||
original := registry
|
||||
registry = newMetricRegistry()
|
||||
t.Cleanup(func() { registry = original })
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue