mirror of
https://github.com/fluxcd/flux2.git
synced 2025-10-28 23:14:48 +08:00
Speed up unit tests by using a shared envTest. This requires each test to use its own namespace to avoid clobbering objects for other tests. Tests previously took around 8 seconds each, and now the initial test takes 2 seconds with follow up tests taking less than a second each. Also update existing tests that use a fixed namespace to use a generated namespace. Share gold file template function with yaml files. Remove the testClusterMode, and instead rely on MainTest to do the appropriate test setup and rootArgs flag setup. Move the rootArg flag setup out of NewTestEnvKubeManager to avoid side effects. A follow up change can be to push the individual setups from NewTestEnvKubeManager() into their respective TestMain since the harness share little code. Signed-off-by: Allen Porter <allen@thebends.org>
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
// +build e2e
|
|
|
|
package main
|
|
|
|
import "testing"
|
|
|
|
func TestHelmReleaseFromGit(t *testing.T) {
|
|
cases := []struct {
|
|
args string
|
|
goldenFile string
|
|
}{
|
|
{
|
|
"create source git thrfg --url=https://github.com/stefanprodan/podinfo --branch=main --tag=6.0.0",
|
|
"testdata/helmrelease/create_source_git.golden",
|
|
},
|
|
{
|
|
"create helmrelease thrfg --source=GitRepository/thrfg --chart=./charts/podinfo",
|
|
"testdata/helmrelease/create_helmrelease_from_git.golden",
|
|
},
|
|
{
|
|
"get helmrelease thrfg",
|
|
"testdata/helmrelease/get_helmrelease_from_git.golden",
|
|
},
|
|
{
|
|
"reconcile helmrelease thrfg --with-source",
|
|
"testdata/helmrelease/reconcile_helmrelease_from_git.golden",
|
|
},
|
|
{
|
|
"suspend helmrelease thrfg",
|
|
"testdata/helmrelease/suspend_helmrelease_from_git.golden",
|
|
},
|
|
{
|
|
"resume helmrelease thrfg",
|
|
"testdata/helmrelease/resume_helmrelease_from_git.golden",
|
|
},
|
|
{
|
|
"delete helmrelease thrfg --silent",
|
|
"testdata/helmrelease/delete_helmrelease_from_git.golden",
|
|
},
|
|
}
|
|
|
|
namespace := allocateNamespace("thrfg")
|
|
del, err := setupTestNamespace(namespace)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer del()
|
|
|
|
for _, tc := range cases {
|
|
cmd := cmdTestCase{
|
|
args: tc.args + " -n=" + namespace,
|
|
assert: assertGoldenTemplateFile(tc.goldenFile, map[string]string{"ns": namespace}),
|
|
}
|
|
cmd.runTestCmd(t)
|
|
}
|
|
}
|