Skip to content

Commit

Permalink
add unit tests for pkg/options.go and pkg/metrics.go
Browse files Browse the repository at this point in the history
Signed-off-by: Cheng Fang <cfang@redhat.com>
  • Loading branch information
chengfang committed Jul 5, 2024
1 parent 7f93ac5 commit 8b54ac8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 8 additions & 0 deletions pkg/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit 8b54ac8

Please # to comment.