Skip to content

Commit

Permalink
metric deletion test update
Browse files Browse the repository at this point in the history
  • Loading branch information
aaa5kameric committed Oct 14, 2024
1 parent f24ddc4 commit 8e52c02
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/certmonitor/certmonitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 8e52c02

Please sign in to comment.