summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng Fang <cfang@redhat.com>2024-07-05 18:40:15 -0400
committerGitHub <noreply@github.com>2024-07-05 18:40:15 -0400
commit3e7dc57bc8805c7da5176283fbab985ed9acab61 (patch)
treed0207ae84397be9d6a3af1c6f32198248fa9ac9a
parent7f93ac538917325afd05e5ca6a18f423fa503195 (diff)
tests: add unit tests for pkg/options.go and pkg/metrics.go (#768)
Signed-off-by: Cheng Fang <cfang@redhat.com>
-rw-r--r--pkg/metrics/metrics_test.go27
-rw-r--r--pkg/options/options_test.go8
2 files changed, 35 insertions, 0 deletions
diff --git a/pkg/metrics/metrics_test.go b/pkg/metrics/metrics_test.go
index 8ffbbf6..be204cd 100644
--- a/pkg/metrics/metrics_test.go
+++ b/pkg/metrics/metrics_test.go
@@ -39,4 +39,31 @@ func TestMetricsInitialization(t *testing.T) {
assert.NotNil(t, cpm.kubeAPIRequestsTotal)
assert.NotNil(t, cpm.kubeAPIRequestsErrorsTotal)
})
+
+ t.Run("NewApplicationsMetrics", func(t *testing.T) {
+ apm := NewApplicationsMetrics()
+ assert.NotNil(t, apm)
+ assert.NotNil(t, apm.applicationsTotal)
+ assert.NotNil(t, apm.imagesWatchedTotal)
+ assert.NotNil(t, apm.imagesUpdatedTotal)
+ assert.NotNil(t, apm.imagesUpdatedErrorsTotal)
+ })
+}
+
+func TestMetricsOperations(t *testing.T) {
+ epm := Endpoint()
+ epm.IncreaseRequest("/registry1", false)
+ epm.IncreaseRequest("/registry1", true)
+
+ cpm := Clients()
+ cpm.IncreaseArgoCDClientRequest("server1", 1)
+ cpm.IncreaseArgoCDClientError("server1", 2)
+ cpm.IncreaseK8sClientRequest(3)
+ cpm.IncreaseK8sClientError(4)
+
+ apm := Applications()
+ apm.IncreaseImageUpdate("app1", 1)
+ apm.IncreaseUpdateErrors("app1", 2)
+ apm.SetNumberOfApplications(3)
+ apm.SetNumberOfImagesWatched("app1", 4)
}
diff --git a/pkg/options/options_test.go b/pkg/options/options_test.go
index a89fc1b..8f1efdd 100644
--- a/pkg/options/options_test.go
+++ b/pkg/options/options_test.go
@@ -72,3 +72,11 @@ func Test_Platforms(t *testing.T) {
assert.Equal(t, ps[1], PlatformKey("linux", "arm", "v8"))
})
}
+
+func Test_WithLogger(t *testing.T) {
+ opts := NewManifestOptions()
+ logger := opts.Logger()
+ assert.NotNil(t, logger)
+ opts = opts.WithLogger(logger)
+ assert.Equal(t, logger, opts.Logger())
+}