|
| 1 | +package metrics |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/prometheus/client_golang/prometheus" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +func TestMetricsInitialization(t *testing.T) { |
| 11 | + t.Run("NewEndpointMetrics", func(t *testing.T) { |
| 12 | + prometheus.DefaultRegisterer = prometheus.NewRegistry() |
| 13 | + epm := NewEndpointMetrics() |
| 14 | + assert.NotNil(t, epm) |
| 15 | + assert.NotNil(t, epm.requestsTotal) |
| 16 | + assert.NotNil(t, epm.requestsFailed) |
| 17 | + |
| 18 | + prometheus.DefaultRegisterer = nil |
| 19 | + epm = NewEndpointMetrics() |
| 20 | + assert.NotNil(t, epm) |
| 21 | + assert.NotNil(t, epm.requestsTotal) |
| 22 | + assert.NotNil(t, epm.requestsFailed) |
| 23 | + }) |
| 24 | + |
| 25 | + t.Run("NewClientMetrics", func(t *testing.T) { |
| 26 | + prometheus.DefaultRegisterer = prometheus.NewRegistry() |
| 27 | + cpm := NewClientMetrics() |
| 28 | + assert.NotNil(t, cpm) |
| 29 | + assert.NotNil(t, cpm.argoCDRequestsTotal) |
| 30 | + assert.NotNil(t, cpm.argoCDRequestsErrorsTotal) |
| 31 | + assert.NotNil(t, cpm.kubeAPIRequestsTotal) |
| 32 | + assert.NotNil(t, cpm.kubeAPIRequestsErrorsTotal) |
| 33 | + |
| 34 | + prometheus.DefaultRegisterer = nil |
| 35 | + cpm = NewClientMetrics() |
| 36 | + assert.NotNil(t, cpm) |
| 37 | + assert.NotNil(t, cpm.argoCDRequestsTotal) |
| 38 | + assert.NotNil(t, cpm.argoCDRequestsErrorsTotal) |
| 39 | + assert.NotNil(t, cpm.kubeAPIRequestsTotal) |
| 40 | + assert.NotNil(t, cpm.kubeAPIRequestsErrorsTotal) |
| 41 | + }) |
| 42 | +} |
0 commit comments