Skip to content

Commit 3e7dc57

Browse files
authored
tests: add unit tests for pkg/options.go and pkg/metrics.go (argoproj-labs#768)
Signed-off-by: Cheng Fang <[email protected]>
1 parent 7f93ac5 commit 3e7dc57

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

pkg/metrics/metrics_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,31 @@ func TestMetricsInitialization(t *testing.T) {
3939
assert.NotNil(t, cpm.kubeAPIRequestsTotal)
4040
assert.NotNil(t, cpm.kubeAPIRequestsErrorsTotal)
4141
})
42+
43+
t.Run("NewApplicationsMetrics", func(t *testing.T) {
44+
apm := NewApplicationsMetrics()
45+
assert.NotNil(t, apm)
46+
assert.NotNil(t, apm.applicationsTotal)
47+
assert.NotNil(t, apm.imagesWatchedTotal)
48+
assert.NotNil(t, apm.imagesUpdatedTotal)
49+
assert.NotNil(t, apm.imagesUpdatedErrorsTotal)
50+
})
51+
}
52+
53+
func TestMetricsOperations(t *testing.T) {
54+
epm := Endpoint()
55+
epm.IncreaseRequest("/registry1", false)
56+
epm.IncreaseRequest("/registry1", true)
57+
58+
cpm := Clients()
59+
cpm.IncreaseArgoCDClientRequest("server1", 1)
60+
cpm.IncreaseArgoCDClientError("server1", 2)
61+
cpm.IncreaseK8sClientRequest(3)
62+
cpm.IncreaseK8sClientError(4)
63+
64+
apm := Applications()
65+
apm.IncreaseImageUpdate("app1", 1)
66+
apm.IncreaseUpdateErrors("app1", 2)
67+
apm.SetNumberOfApplications(3)
68+
apm.SetNumberOfImagesWatched("app1", 4)
4269
}

pkg/options/options_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,11 @@ func Test_Platforms(t *testing.T) {
7272
assert.Equal(t, ps[1], PlatformKey("linux", "arm", "v8"))
7373
})
7474
}
75+
76+
func Test_WithLogger(t *testing.T) {
77+
opts := NewManifestOptions()
78+
logger := opts.Logger()
79+
assert.NotNil(t, logger)
80+
opts = opts.WithLogger(logger)
81+
assert.Equal(t, logger, opts.Logger())
82+
}

0 commit comments

Comments
 (0)