diff options
| author | Zubair Haque <zhaque@easydynamics.com> | 2024-06-13 15:05:07 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-13 16:05:07 -0400 |
| commit | cd973931cc144fbfd290ac68afc0978ef5b84601 (patch) | |
| tree | 8da9695cd324eaf16f627eea4493317d14f8317e | |
| parent | 2a065fad543c5bdac22b13869401d1b47eac0972 (diff) | |
chore: adding test coverage for NewClientMetrics & NewEndpointMetrics (#743)
* adding test coverage for NewClientMetrics & NewEndpointMetrics
Signed-off-by: zhaque44 <haque.zubair@gmail.com>
* chore: forgot to run go tidy
Signed-off-by: zhaque44 <haque.zubair@gmail.com>
---------
Signed-off-by: zhaque44 <haque.zubair@gmail.com>
| -rw-r--r-- | pkg/metrics/metrics_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/pkg/metrics/metrics_test.go b/pkg/metrics/metrics_test.go new file mode 100644 index 0000000..8ffbbf6 --- /dev/null +++ b/pkg/metrics/metrics_test.go @@ -0,0 +1,42 @@ +package metrics + +import ( + "testing" + + "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/assert" +) + +func TestMetricsInitialization(t *testing.T) { + t.Run("NewEndpointMetrics", func(t *testing.T) { + prometheus.DefaultRegisterer = prometheus.NewRegistry() + epm := NewEndpointMetrics() + assert.NotNil(t, epm) + assert.NotNil(t, epm.requestsTotal) + assert.NotNil(t, epm.requestsFailed) + + prometheus.DefaultRegisterer = nil + epm = NewEndpointMetrics() + assert.NotNil(t, epm) + assert.NotNil(t, epm.requestsTotal) + assert.NotNil(t, epm.requestsFailed) + }) + + t.Run("NewClientMetrics", func(t *testing.T) { + prometheus.DefaultRegisterer = prometheus.NewRegistry() + cpm := NewClientMetrics() + assert.NotNil(t, cpm) + assert.NotNil(t, cpm.argoCDRequestsTotal) + assert.NotNil(t, cpm.argoCDRequestsErrorsTotal) + assert.NotNil(t, cpm.kubeAPIRequestsTotal) + assert.NotNil(t, cpm.kubeAPIRequestsErrorsTotal) + + prometheus.DefaultRegisterer = nil + cpm = NewClientMetrics() + assert.NotNil(t, cpm) + assert.NotNil(t, cpm.argoCDRequestsTotal) + assert.NotNil(t, cpm.argoCDRequestsErrorsTotal) + assert.NotNil(t, cpm.kubeAPIRequestsTotal) + assert.NotNil(t, cpm.kubeAPIRequestsErrorsTotal) + }) +} |
