tests: only provide template values when used
As otherwise the `.golden` values can not be automatically updated using `-update` as documented in `CONTRIBUTING.md`. Also ensure we do not use `defer` but rather `t.Cleanup` in tests, as this will always be called even if e.g. `t.Fatal` absruptly stops the test. Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
@@ -22,51 +22,61 @@ package main
|
||||
import "testing"
|
||||
|
||||
func TestKustomizationFromGit(t *testing.T) {
|
||||
cases := []struct {
|
||||
args string
|
||||
goldenFile string
|
||||
}{
|
||||
{
|
||||
"create source git tkfg --url=https://github.com/stefanprodan/podinfo --branch=main --tag=6.0.0",
|
||||
"testdata/kustomization/create_source_git.golden",
|
||||
},
|
||||
{
|
||||
"create kustomization tkfg --source=tkfg --path=./deploy/overlays/dev --prune=true --interval=5m --health-check=Deployment/frontend.dev --health-check=Deployment/backend.dev --health-check-timeout=3m",
|
||||
"testdata/kustomization/create_kustomization_from_git.golden",
|
||||
},
|
||||
{
|
||||
"get kustomization tkfg",
|
||||
"testdata/kustomization/get_kustomization_from_git.golden",
|
||||
},
|
||||
{
|
||||
"reconcile kustomization tkfg --with-source",
|
||||
"testdata/kustomization/reconcile_kustomization_from_git.golden",
|
||||
},
|
||||
{
|
||||
"suspend kustomization tkfg",
|
||||
"testdata/kustomization/suspend_kustomization_from_git.golden",
|
||||
},
|
||||
{
|
||||
"resume kustomization tkfg",
|
||||
"testdata/kustomization/resume_kustomization_from_git.golden",
|
||||
},
|
||||
{
|
||||
"delete kustomization tkfg --silent",
|
||||
"testdata/kustomization/delete_kustomization_from_git.golden",
|
||||
},
|
||||
}
|
||||
|
||||
namespace := allocateNamespace("tkfg")
|
||||
del, err := setupTestNamespace(namespace)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer del()
|
||||
t.Cleanup(del)
|
||||
|
||||
tmpl := map[string]string{"ns": namespace}
|
||||
|
||||
cases := []struct {
|
||||
args string
|
||||
goldenFile string
|
||||
tmpl map[string]string
|
||||
}{
|
||||
{
|
||||
"create source git tkfg --url=https://github.com/stefanprodan/podinfo --branch=main --tag=6.0.0",
|
||||
"testdata/kustomization/create_source_git.golden",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"create kustomization tkfg --source=tkfg --path=./deploy/overlays/dev --prune=true --interval=5m --health-check=Deployment/frontend.dev --health-check=Deployment/backend.dev --health-check-timeout=3m",
|
||||
"testdata/kustomization/create_kustomization_from_git.golden",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"get kustomization tkfg",
|
||||
"testdata/kustomization/get_kustomization_from_git.golden",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"reconcile kustomization tkfg --with-source",
|
||||
"testdata/kustomization/reconcile_kustomization_from_git.golden",
|
||||
tmpl,
|
||||
},
|
||||
{
|
||||
"suspend kustomization tkfg",
|
||||
"testdata/kustomization/suspend_kustomization_from_git.golden",
|
||||
tmpl,
|
||||
},
|
||||
{
|
||||
"resume kustomization tkfg",
|
||||
"testdata/kustomization/resume_kustomization_from_git.golden",
|
||||
tmpl,
|
||||
},
|
||||
{
|
||||
"delete kustomization tkfg --silent",
|
||||
"testdata/kustomization/delete_kustomization_from_git.golden",
|
||||
tmpl,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
cmd := cmdTestCase{
|
||||
args: tc.args + " -n=" + namespace,
|
||||
assert: assertGoldenTemplateFile(tc.goldenFile, map[string]string{"ns": namespace}),
|
||||
assert: assertGoldenTemplateFile(tc.goldenFile, tc.tmpl),
|
||||
}
|
||||
cmd.runTestCmd(t)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user