1
0
mirror of synced 2026-02-13 13:06:56 +00:00

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:
Hidde Beydals
2023-02-15 13:11:37 +01:00
parent 1e67d75848
commit b263e14fa8
9 changed files with 167 additions and 125 deletions

View File

@@ -24,47 +24,56 @@ import (
)
func TestSourceOCI(t *testing.T) {
cases := []struct {
args string
goldenFile string
}{
{
"create source oci thrfg --url=oci://ghcr.io/stefanprodan/manifests/podinfo --tag=6.1.6 --interval 10m",
"testdata/oci/create_source_oci.golden",
},
{
"get source oci thrfg",
"testdata/oci/get_oci.golden",
},
{
"reconcile source oci thrfg",
"testdata/oci/reconcile_oci.golden",
},
{
"suspend source oci thrfg",
"testdata/oci/suspend_oci.golden",
},
{
"resume source oci thrfg",
"testdata/oci/resume_oci.golden",
},
{
"delete source oci thrfg --silent",
"testdata/oci/delete_oci.golden",
},
}
namespace := allocateNamespace("oci-test")
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 oci thrfg --url=oci://ghcr.io/stefanprodan/manifests/podinfo --tag=6.1.6 --interval 10m",
"testdata/oci/create_source_oci.golden",
nil,
},
{
"get source oci thrfg",
"testdata/oci/get_oci.golden",
nil,
},
{
"reconcile source oci thrfg",
"testdata/oci/reconcile_oci.golden",
tmpl,
},
{
"suspend source oci thrfg",
"testdata/oci/suspend_oci.golden",
tmpl,
},
{
"resume source oci thrfg",
"testdata/oci/resume_oci.golden",
tmpl,
},
{
"delete source oci thrfg --silent",
"testdata/oci/delete_oci.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)
}