Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ cleanup-kind:
rm $(TEST_KUBECONFIG)

test: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet
go test ./... -coverprofile cover.out
go test ./... -coverprofile cover.out --tags=unit

e2e: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet
TEST_KUBECONFIG=$(TEST_KUBECONFIG) go test ./cmd/flux/... -coverprofile cover.out --tags=e2e -parallel=1
TEST_KUBECONFIG=$(TEST_KUBECONFIG) go test ./cmd/flux/... -coverprofile e2e.cover.out --tags=e2e -v -failfast

test-with-kind: setup-envtest
make setup-kind
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
return err
}

utils.PrintTable(os.Stdout, header, rows)
utils.PrintTable(cmd.OutOrStderr(), header, rows)

if getAll {
fmt.Println()
Expand Down
57 changes: 57 additions & 0 deletions cmd/flux/helmrelease_test.go
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)
}
}
49 changes: 49 additions & 0 deletions cmd/flux/image_test.go
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)
}
}
54 changes: 0 additions & 54 deletions cmd/flux/install_test.go

This file was deleted.

57 changes: 57 additions & 0 deletions cmd/flux/kustomization_test.go
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)
}
}
59 changes: 59 additions & 0 deletions cmd/flux/main_e2e_test.go
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
}
14 changes: 0 additions & 14 deletions cmd/flux/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
)

func TestMain(m *testing.M) {
// Ensure tests print consistent timestamps regardless of timezone
os.Setenv("TZ", "UTC")
os.Exit(m.Run())
}

func readYamlObjects(objectFile string) ([]client.Object, error) {
obj, err := os.ReadFile(objectFile)
if err != nil {
Expand Down Expand Up @@ -245,11 +239,3 @@ func executeCommand(cmd string) (string, error) {

return result, err
}

func TestVersion(t *testing.T) {
cmd := cmdTestCase{
args: "--version",
goldenValue: "flux version 0.0.0-dev.0\n",
}
cmd.runTestCmd(t)
}
14 changes: 14 additions & 0 deletions cmd/flux/main_unit_test.go
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())
}
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
6 changes: 6 additions & 0 deletions cmd/flux/testdata/helmrelease/create_source_git.golden
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
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 cmd/flux/testdata/helmrelease/get_helmrelease_from_git.golden
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
Loading