Last active
May 8, 2022 22:23
-
-
Save jwillker/b29d92afb62db6441171af72929fa2d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestDeployTemplateRenders(t *testing.T) { | |
t.Parallel() | |
type args struct { | |
Release string | |
Values map[string]string | |
} | |
type want struct { | |
DeployName string | |
DeployLabels map[string]string | |
} | |
tests := []struct { | |
name string | |
args args | |
want want | |
}{ | |
{ | |
name: "my-api", | |
args: args{ | |
Release: "my-api", | |
Values: 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", | |
}, | |
}, | |
want: want{ | |
DeployName: "my-api", | |
DeployLabels: 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", | |
}, | |
}, | |
}, | |
} | |
for _, tt := range tests { | |
t.Run(tt.name, func(t *testing.T) { | |
var deployment appsv1.Deployment | |
// Render the deployment object | |
err := Render(t, "../", "deployment.yaml", tt.args.Release, tt.args.Values, &deployment) | |
if err != nil { | |
fmt.Println(err) | |
} | |
assert.Equal( | |
t, | |
tt.want.DeployName, | |
deployment.Name, | |
"Rendered Deployment name is not the expected!", | |
) | |
// Validate all Deployment labels | |
for k, v := range tt.want.DeployLabels { | |
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