diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index be988156..16fc6a56 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -176,26 +176,6 @@ jobs: --chart=podinfo \ --chart-version="5.0.x" \ --service-account=dev-team - - name: flux create image repository - run: | - /tmp/flux create image repository podinfo \ - --image=ghcr.io/stefanprodan/podinfo \ - --interval=1m - - name: flux create image policy - run: | - /tmp/flux create image policy podinfo \ - --image-ref=podinfo \ - --interval=1m \ - --select-semver=5.0.x - - name: flux create image policy podinfo-select-alpha - run: | - /tmp/flux create image policy podinfo-alpha \ - --image-ref=podinfo \ - --interval=1m \ - --select-alpha=desc - - name: flux get image policy - run: | - /tmp/flux get image policy podinfo | grep '5.0.3' - name: flux2-kustomize-helm-example run: | /tmp/flux create source git flux-system \ diff --git a/cmd/flux/image_test.go b/cmd/flux/image_test.go new file mode 100644 index 00000000..d4ed7b49 --- /dev/null +++ b/cmd/flux/image_test.go @@ -0,0 +1,49 @@ +// +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 := "tis" + del, err := setupTestNamespace(namespace) + if err != nil { + t.Fatal(err) + } + defer del() + + for _, tc := range cases { + cmd := cmdTestCase{ + args: tc.args + " -n=" + namespace, + goldenFile: tc.goldenFile, + testClusterMode: ExistingClusterMode, + } + cmd.runTestCmd(t) + } +} diff --git a/cmd/flux/testdata/image/create_image_policy.golden b/cmd/flux/testdata/image/create_image_policy.golden new file mode 100644 index 00000000..d08caac6 --- /dev/null +++ b/cmd/flux/testdata/image/create_image_policy.golden @@ -0,0 +1,5 @@ +✚ generating ImagePolicy +► applying ImagePolicy +✔ ImageRepository created +◎ waiting for ImagePolicy reconciliation +✔ ImagePolicy reconciliation completed diff --git a/cmd/flux/testdata/image/create_image_repository.golden b/cmd/flux/testdata/image/create_image_repository.golden new file mode 100644 index 00000000..594fdba9 --- /dev/null +++ b/cmd/flux/testdata/image/create_image_repository.golden @@ -0,0 +1,5 @@ +✚ generating ImageRepository +► applying ImageRepository +✔ ImageRepository created +◎ waiting for ImageRepository reconciliation +✔ ImageRepository reconciliation completed diff --git a/cmd/flux/testdata/image/get_image_policy_regex.golden b/cmd/flux/testdata/image/get_image_policy_regex.golden new file mode 100644 index 00000000..8486fb1f --- /dev/null +++ b/cmd/flux/testdata/image/get_image_policy_regex.golden @@ -0,0 +1,2 @@ +NAME READY MESSAGE LATEST IMAGE +podinfo-regex True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.0 ghcr.io/stefanprodan/podinfo:5.0.0 diff --git a/cmd/flux/testdata/image/get_image_policy_semver.golden b/cmd/flux/testdata/image/get_image_policy_semver.golden new file mode 100644 index 00000000..6f8a17dd --- /dev/null +++ b/cmd/flux/testdata/image/get_image_policy_semver.golden @@ -0,0 +1,2 @@ +NAME READY MESSAGE LATEST IMAGE +podinfo-semver True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.3 ghcr.io/stefanprodan/podinfo:5.0.3