Skip to content

Commit

Permalink
🔧 Reviews
Browse files Browse the repository at this point in the history
Signed-off-by: afreyermuth98 <[email protected]>
  • Loading branch information
afreyermuth98 committed Sep 13, 2024
1 parent ab43d47 commit 01287e3
Showing 1 changed file with 65 additions and 6 deletions.
71 changes: 65 additions & 6 deletions charts/falco/tests/unit/serviceTemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,77 @@ func (s *serviceTemplateTest) TestCreationDefaultValues() {
s.Equal("error while running command: exit status 1; Error: could not find template templates/service.yaml in chart", err.Error())
}


func (s *serviceTemplateTest) TestDefaultLabelsValues() {
// Render the service and check that it has not been rendered.
output, err := helm.RenderTemplateE(s.T(), &helm.Options{}, s.chartPath, s.releaseName, s.templates)
s.Error(err, "should error")
s.Equal("error while running command: exit status 1; Error: could not find template templates/service.yaml in chart", err.Error())


cInfo, err := chartInfo(s.T(), s.chartPath)

Check failure on line 67 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

undefined: chartInfo
s.NoError(err)
// Get app version.
appVersion, found := cInfo["appVersion"]
s.True(found, "should find app version in chart info")
appVersion = appVersion.(string)
// Get chart version.
chartVersion, found := cInfo["version"]
s.True(found, "should find chart version in chart info")
// Get chart name.
chartName, found := cInfo["name"]
s.True(found, "should find chart name in chart info")
chartName = chartName.(string)
expectedLabels := map[string]string{
"helm.sh/chart": fmt.Sprintf("%s-%s", chartName, chartVersion),

Check failure on line 81 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

undefined: fmt
"app.kubernetes.io/name": chartName.(string),
"app.kubernetes.io/instance": s.releaseName,
"app.kubernetes.io/version": appVersion.(string),
"app.kubernetes.io/managed-by": "Helm",
}
var svc corev1.Service
helm.UnmarshalK8SYaml(s.T(), output, &svc)
s.Equal("falco", svc.Metadata.Labels["app.kubernetes.io/name"])
s.Equal("Helm", svc.Metadata.Labels["app.kubernetes.io/managed-by"])
s.Equal("0.38.2", svc.Metadata.Labels["app.kubernetes.io/version"])
s.Equal("falco-4.8.1", svc.Metadata.Labels["helm.sh/chart"])
s.Equal("falco-metrics", svc.Metadata.Labels["type"])
labels := svc.GetLabels()
for key, value := range labels {
expectedVal := expectedLabels[key]
s.Equal(expectedVal, value)
}
}


func (s *serviceTemplateTest) TestCustomLabelsValues() {
// Render the service and check that it has not been rendered.
options := &helm.Options{SetValues: map[string]string{"metrics.service.labels" : {"custom-label": "falco-label"}}}

Check failure on line 99 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

options declared and not used

Check failure on line 99 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

invalid composite literal type string
output, err := helm.RenderTemplateE(s.T(), &helm.Options{}, s.chartPath, s.releaseName, s.templates)
s.Error(err, "should error")
s.Equal("error while running command: exit status 1; Error: could not find template templates/service.yaml in chart", err.Error())


cInfo, err := chartInfo(s.T(), s.chartPath)

Check failure on line 105 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

undefined: chartInfo
s.NoError(err)
// Get app version.
appVersion, found := cInfo["appVersion"]
s.True(found, "should find app version in chart info")
appVersion = appVersion.(string)
// Get chart version.
chartVersion, found := cInfo["version"]
s.True(found, "should find chart version in chart info")
// Get chart name.
chartName, found := cInfo["name"]
s.True(found, "should find chart name in chart info")
chartName = chartName.(string)
expectedLabels := map[string]string{
"helm.sh/chart": fmt.Sprintf("%s-%s", chartName, chartVersion),

Check failure on line 119 in charts/falco/tests/unit/serviceTemplate_test.go

View workflow job for this annotation

GitHub Actions / go-unit-tests

undefined: fmt
"app.kubernetes.io/name": chartName.(string),
"app.kubernetes.io/instance": s.releaseName,
"app.kubernetes.io/version": appVersion.(string),
"app.kubernetes.io/managed-by": "Helm",
}
var svc corev1.Service
helm.UnmarshalK8SYaml(s.T(), output, &svc)
labels := svc.GetLabels()
for key, value := range labels {
expectedVal := expectedLabels[key]
s.Equal(expectedVal, value)
}
s.Equal("falco-label", labels["custom-label"])
}

0 comments on commit 01287e3

Please sign in to comment.