Skip to content

Instantly share code, notes, and snippets.

@jwillker
Last active May 8, 2022 21:57
Show Gist options
  • Save jwillker/77e62e448eecb89072302f751a77298d to your computer and use it in GitHub Desktop.
Save jwillker/77e62e448eecb89072302f751a77298d to your computer and use it in GitHub Desktop.
func TestDeployTemplateRendersMetadata(t *testing.T) {
t.Parallel()
var (
// Default Helm values
// Work as values.yaml for tests purposes
deployDefaultValues = map[string]string{
"app.version": "0.1.0",
"app.replicas": "2",
"app.component": "api",
"app.env": "dev",
"app.owner": "john.doe",
"app.project": "test",
"app.bu": "eng",
"app.labels.foo": "bar",
"app.annotations.foo": "bar",
"containers.image": "hashicorp/http-echo",
"containers.port": "5678",
"containers.command[0]": "sleep",
"containers.args[0]": "infinity",
}
// The expected labels in Deployment and Pod metadata
deployExpectedLabels = map[string]string{
"app.kubernetes.io/name": "my-api",
"app.kubernetes.io/instance": "my-api-0.1.0",
"app.kubernetes.io/component": "api",
"app.kubernetes.io/version": "0.1.0",
"app.kubernetes.io/managed-by": "Helm",
"env": "dev",
"app": "my-api",
"version": "0.1.0",
"foo": "bar",
}
)
helmChartPath := "../"
// Passing values to helm chart.
options := &helm.Options{
SetValues: deployDefaultValues,
}
output := helm.RenderTemplate(t, options, helmChartPath, "my-api", []string{"templates/deployment.yaml"})
// ensure the deployment resource is rendered correctly.
var deployment appsv1.Deployment
helm.UnmarshalK8SYaml(t, output, &deployment)
assert.Equal(
t,
"my-api",
deployment.Name,
"Rendered Deployment name is not the expected!",
)
// Validate all Deployment labels
for k, v := range deployExpectedLabels {
assert.Equal(
t,
v,
deployment.Labels[k],
"Rendered Deployment '%s' label is not the expected!", k,
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment