Skip to content

Commit

Permalink
Fix helmchart gather unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ncaak committed Feb 20, 2024
1 parent 9309816 commit 3cb4b64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 11 additions & 3 deletions pkg/gatherers/workloads/gather_helm_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ import (

const labelChartNameKey = "helm.sh/chart"

// GatherHelmInfo Collects summarized info about the helm usage on a cluster
// in a generic fashion
// GatherHelmInfo Collects statistics about resources deployed via HelmChart, counting only the resources
// with `app.kubernetes.io/managed-by=Helm` and `helm.sh/chart` labels. The data is then summarized
// and grouped by hashed namespace.
//
// Resource types included:
// - ReplicaSets
// - DaemonSets
// - StatefulSets
// - Services
// - Deployments
//
// ### API Reference
// None
Expand Down Expand Up @@ -84,7 +92,7 @@ func gatherHelmInfo(
// Anonymize the namespace to make it unique identifier
hash, err := createHash(item.GetNamespace())
if err != nil {
klog.Errorf("unable to hash the namespace '%s': %v", labels[labelChartNameKey], err)
klog.Errorf("unable to hash the namespace '%s': %v", item.GetNamespace(), err)
continue
}

Expand Down
9 changes: 6 additions & 3 deletions pkg/gatherers/workloads/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ func TestAddItem(t *testing.T) {
for _, testCase := range tests {
tt := testCase
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

helmList := newHelmChartInfoList()
for namespace, resources := range tt.info {
for resource, charts := range resources {
Expand All @@ -99,7 +97,12 @@ func TestAddItem(t *testing.T) {
}
}

assert.Equal(t, tt.expectedList, helmList.Namespaces, "expected '%v', got '%v'", tt.expectedList, helmList.Namespaces)
// check equality of elements in slices, ignoring order
for namespace, expectedCharts := range tt.expectedList {
actualCharts, ok := helmList.Namespaces[namespace]
assert.True(t, ok, "expected namespace '%s' not found", namespace)
assert.ElementsMatch(t, expectedCharts, actualCharts, "unexpected charts for namespace '%s'", namespace)
}
})
}
}

0 comments on commit 3cb4b64

Please sign in to comment.