mirror of
https://github.com/fluxcd/flux2.git
synced 2025-10-30 07:47:09 +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>
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
// +build e2e
|
|
|
|
package main
|
|
|
|
import "testing"
|
|
|
|
func TestImageScanning(t *testing.T) {
|
|
cases := []struct {
|
|
args string
|
|
goldenFile string
|
|
}{
|
|
{
|
|
"create image repository podinfo --image=ghcr.io/stefanprodan/podinfo --interval=10m",
|
|
"testdata/image/create_image_repository.golden",
|
|
},
|
|
{
|
|
"create image policy podinfo-semver --image-ref=podinfo --interval=10m --select-semver=5.0.x",
|
|
"testdata/image/create_image_policy.golden",
|
|
},
|
|
{
|
|
"get image policy podinfo-semver",
|
|
"testdata/image/get_image_policy_semver.golden",
|
|
},
|
|
{
|
|
`create image policy podinfo-regex --image-ref=podinfo --interval=10m --select-semver=">4.0.0" --filter-regex="5\.0\.0"`,
|
|
"testdata/image/create_image_policy.golden",
|
|
},
|
|
{
|
|
"get image policy podinfo-regex",
|
|
"testdata/image/get_image_policy_regex.golden",
|
|
},
|
|
}
|
|
|
|
namespace := allocateNamespace("tis")
|
|
del, err := setupTestNamespace(namespace)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer del()
|
|
|
|
for _, tc := range cases {
|
|
cmd := cmdTestCase{
|
|
args: tc.args + " -n=" + namespace,
|
|
assert: assertGoldenFile(tc.goldenFile),
|
|
}
|
|
cmd.runTestCmd(t)
|
|
}
|
|
}
|