diff --git a/internal/certmonitor/certmonitor_test.go b/internal/certmonitor/certmonitor_test.go index 6ec5a8603..fe40080f2 100644 --- a/internal/certmonitor/certmonitor_test.go +++ b/internal/certmonitor/certmonitor_test.go @@ -345,7 +345,6 @@ func TestCertMonitor_Secret(t *testing.T) { verifyPrometheusMetricDelete(t, "namespace-1", "secret-1", "tls.crt") } -// TestCertMonitor func tests certificates event handlers + prometheus metrics handling func TestCertMonitor_Namespace(t *testing.T) { fleetshardmetrics.MetricsInstance().CertificatesExpiry.Reset() @@ -374,10 +373,19 @@ func TestCertMonitor_Namespace(t *testing.T) { }, }, } + now1 := time.Now().UTC() + expirytime := now1.Add(1 * time.Hour) mockNamespace := &v1.Namespace{ // pragma: allowlist secret - ObjectMeta: metav1.ObjectMeta{Namespace: "namespace-1"}, + ObjectMeta: metav1.ObjectMeta{Name: "namespace-1"}, } + secret := &v1.Secret{ // pragma: allowlist secret + ObjectMeta: metav1.ObjectMeta{Namespace: mockNamespace.Name, Name: "secret-1"}, + Data: map[string][]byte{"tls.crt": generateCertWithExpiration(t, expirytime)}, + } + expirationUnix := float64(expirytime.Unix()) + certMonitor.handleSecretCreation(secret) + verifyPrometheusMetric(t, "namespace-1", "secret-1", "tls.crt", expirationUnix) certMonitor.handleNamespaceDeletion(mockNamespace) verifyPrometheusMetricDelete(t, "namespace-1", "secret-1", "tls.crt")