You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package metrics
|
|
|
|
// Tests for Prometheus metrics registration with a custom registry.
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestNewMetrics_WithCustomRegistry ensures new metrics with custom registry behavior is handled correctly.
|
|
func TestNewMetrics_WithCustomRegistry(t *testing.T) {
|
|
registry := prometheus.NewRegistry()
|
|
m := NewMetrics(Config{ServiceName: "svc", Enabled: true, Registry: registry})
|
|
|
|
require.NotNil(t, m)
|
|
require.NotNil(t, m.HTTPRequestsTotal)
|
|
require.NotNil(t, m.DBConnectionsActive)
|
|
require.NotNil(t, m.ScoreDistribution)
|
|
}
|
|
|
|
// TestConfigFromEnvDefaults ensures config from env defaults behavior is handled correctly.
|
|
func TestConfigFromEnvDefaults(t *testing.T) {
|
|
t.Setenv("METRICS_ENABLED", "")
|
|
t.Setenv("METRICS_SERVICE_NAME", "")
|
|
|
|
cfg := ConfigFromEnv()
|
|
def := DefaultConfig()
|
|
|
|
require.Equal(t, def, cfg)
|
|
}
|
|
|
|
// TestConfigFromEnvOverrides ensures config from env overrides behavior is handled correctly.
|
|
func TestConfigFromEnvOverrides(t *testing.T) {
|
|
t.Setenv("METRICS_ENABLED", "false")
|
|
t.Setenv("METRICS_SERVICE_NAME", "admin-service")
|
|
|
|
cfg := ConfigFromEnv()
|
|
require.False(t, cfg.Enabled)
|
|
require.Equal(t, "admin-service", cfg.ServiceName)
|
|
}
|