-
Notifications
You must be signed in to change notification settings - Fork 721
Refactor e2e tests #1721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Refactor e2e tests #1721
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // +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 := "thrfg" | ||
| 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) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // +build e2e | ||
|
|
||
| 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 --validation=client --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 := "tkfg" | ||
| 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) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // +build e2e | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/fluxcd/flux2/internal/utils" | ||
| ) | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| // Ensure tests print consistent timestamps regardless of timezone | ||
| os.Setenv("TZ", "UTC") | ||
|
|
||
| // Install Flux | ||
| km, err := NewTestEnvKubeManager(ExistingClusterMode) | ||
| if err != nil { | ||
| panic(fmt.Errorf("error creating kube manager: '%w'", err)) | ||
| } | ||
| rootCtx.kubeManager = km | ||
| output, err := executeCommand("install --components-extra=image-reflector-controller,image-automation-controller") | ||
| if err != nil { | ||
| panic(fmt.Errorf("install falied: %s error:'%w'", output, err)) | ||
| } | ||
|
|
||
| // Run tests | ||
| code := m.Run() | ||
|
|
||
| // Uninstall Flux | ||
| output, err = executeCommand("uninstall -s --keep-namespace") | ||
| if err != nil { | ||
| panic(fmt.Errorf("uninstall falied: %s error:'%w'", output, err)) | ||
| } | ||
|
|
||
| // Delete namespace and wait for finalisation | ||
| kubectlArgs := []string{"delete", "namespace", "flux-system"} | ||
| _, err = utils.ExecKubectlCommand(context.TODO(), utils.ModeStderrOS, rootArgs.kubeconfig, rootArgs.kubecontext, kubectlArgs...) | ||
| if err != nil { | ||
| panic(fmt.Errorf("delete namespace error:'%w'", err)) | ||
| } | ||
|
|
||
| os.Exit(code) | ||
| } | ||
|
|
||
| func setupTestNamespace(namespace string) (func(), error) { | ||
| kubectlArgs := []string{"create", "namespace", namespace} | ||
| _, err := utils.ExecKubectlCommand(context.TODO(), utils.ModeStderrOS, rootArgs.kubeconfig, rootArgs.kubecontext, kubectlArgs...) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return func() { | ||
| kubectlArgs := []string{"delete", "namespace", namespace} | ||
| utils.ExecKubectlCommand(context.TODO(), utils.ModeCapture, rootArgs.kubeconfig, rootArgs.kubecontext, kubectlArgs...) | ||
| }, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // +build unit | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| // Ensure tests print consistent timestamps regardless of timezone | ||
| os.Setenv("TZ", "UTC") | ||
| os.Exit(m.Run()) | ||
| } |
6 changes: 6 additions & 0 deletions
6
cmd/flux/testdata/helmrelease/create_helmrelease_from_git.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ✚ generating HelmRelease | ||
| ► applying HelmRelease | ||
| ✔ HelmRelease created | ||
| ◎ waiting for HelmRelease reconciliation | ||
| ✔ HelmRelease thrfg is ready | ||
| ✔ applied revision 6.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ✚ generating GitRepository source | ||
| ► applying GitRepository source | ||
| ✔ GitRepository source created | ||
| ◎ waiting for GitRepository source reconciliation | ||
| ✔ GitRepository source reconciliation completed | ||
| ✔ fetched revision: 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951 |
2 changes: 2 additions & 0 deletions
2
cmd/flux/testdata/helmrelease/delete_helmrelease_from_git.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ► deleting helmreleases thrfg in thrfg namespace | ||
| ✔ helmreleases deleted |
2 changes: 2 additions & 0 deletions
2
cmd/flux/testdata/helmrelease/get_helmrelease_from_git.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| NAME READY MESSAGE REVISION SUSPENDED | ||
| thrfg True Release reconciliation succeeded 6.0.0 False |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.