Skip to content

Commit

Permalink
test: add test for kepler method spec
Browse files Browse the repository at this point in the history
Signed-off-by: Bastien Grasnick <bastien.grasnick@deutschebahn.com>
  • Loading branch information
BGrasnick committed Oct 23, 2023
1 parent 7d2ba6d commit a67870e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/components/exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,40 @@ func TestSCCAllows(t *testing.T) {
})
}
}

func TestSpecMethod(t *testing.T) {

tt := []struct {
deploymentSpec v1alpha1.ExporterDeploymentSpec
method string
image string
scenario string
}{{
deploymentSpec: v1alpha1.ExporterDeploymentSpec{},
method: "libbpf",
scenario: "libbpf",
image: "quay.io/sustainable_computing_io/kepler:release-0.6.1" + "-libbpf",
}, {
deploymentSpec: v1alpha1.ExporterDeploymentSpec{},
method: "bcc",
scenario: "bcc",
image: "quay.io/sustainable_computing_io/kepler:release-0.6.1",
}}

for _, tc := range tt {
tc := tc
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()
k := v1alpha1.Kepler{
Spec: v1alpha1.KeplerSpec{
Exporter: v1alpha1.ExporterSpec{
Deployment: tc.deploymentSpec,
Method: tc.method,
},
},
}
actual := k8s.ContainerImageFromDS(NewDaemonSet(components.Full, &k))
assert.Equal(t, actual, tc.image)
})
}
}
4 changes: 4 additions & 0 deletions pkg/utils/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,7 @@ func AllowsFromSCC(SCC *secv1.SecurityContextConstraints) SCCAllows {
AllowHostPorts: SCC.AllowHostPorts,
}
}

func ContainerImageFromDS(ds *appsv1.DaemonSet) string {
return ds.Spec.Template.Spec.Containers[0].Image
}

0 comments on commit a67870e

Please sign in to comment.