Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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)
}
}
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"
Comment thread
hiddeco marked this conversation as resolved.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
► annotating GitRepository thrfg in thrfg namespace
✔ GitRepository annotated
◎ waiting for GitRepository reconciliation
✔ GitRepository reconciliation completed
✔ fetched revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951
► annotating HelmRelease thrfg in thrfg namespace
✔ HelmRelease annotated
◎ waiting for HelmRelease reconciliation
✔ HelmRelease reconciliation completed
✔ applied revision 6.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
► resuming helmreleases thrfg in thrfg namespace
✔ helmreleases resumed
◎ waiting for HelmRelease reconciliation
✔ HelmRelease reconciliation completed
✔ applied revision 6.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
► suspending helmreleases thrfg in thrfg namespace
✔ helmreleases suspended
11 changes: 0 additions & 11 deletions cmd/flux/testdata/install/install_extra_components.golden

This file was deleted.

9 changes: 0 additions & 9 deletions cmd/flux/testdata/install/install_no_args.golden

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
✚ generating Kustomization
► applying Kustomization
✔ Kustomization created
◎ waiting for Kustomization reconciliation
✔ Kustomization tkfg is ready
✔ applied revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951
6 changes: 6 additions & 0 deletions cmd/flux/testdata/kustomization/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 kustomizations tkfg in tkfg namespace
✔ kustomizations deleted
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME READY MESSAGE REVISION SUSPENDED
tkfg True Applied revision: 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951 False
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
► annotating GitRepository tkfg in tkfg namespace
✔ GitRepository annotated
◎ waiting for GitRepository reconciliation
✔ GitRepository reconciliation completed
✔ fetched revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951
► annotating Kustomization tkfg in tkfg namespace
✔ Kustomization annotated
◎ waiting for Kustomization reconciliation
✔ Kustomization reconciliation completed
✔ applied revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
► resuming kustomizations tkfg in tkfg namespace
✔ kustomizations resumed
◎ waiting for Kustomization reconciliation
✔ Kustomization reconciliation completed
✔ applied revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
► suspending kustomizations tkfg in tkfg namespace
✔ kustomizations suspended
Loading