Skip to content

Commit

Permalink
chore(e2e): kustomize util refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Aug 23, 2023
1 parent 93ddeb2 commit 78a0a06
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 117 deletions.
117 changes: 0 additions & 117 deletions e2e/install/kustomize/common.go

This file was deleted.

26 changes: 26 additions & 0 deletions e2e/install/kustomize/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ import (
. "github.com/onsi/gomega"
)

const (
// v1.Build, v1.Integration
// v1.IntegrationKit, v1.IntegrationPlatform
// v1.Kamelet, v1.Pipe,
// v1alpha1.Kamelet, v1alpha1.KameletBinding
ExpectedCRDs = 8

// camel-k-operator, camel-k-operator-events,
// camel-k-operator-knative, camel-k-operator-leases,
// camel-k-operator-podmonitors, camel-k-operator-strimzi,
// camel-k-operator-keda
ExpectedKubePromoteRoles = 7

// camel-k-edit
// camel-k-operator-custom-resource-definitions
// camel-k-operator-bind-addressable-resolver
// camel-k-operator-local-registry
ExpectedKubeClusterRoles = 4

// camel-k-operator-openshift
ExpectedOSPromoteRoles = 1

// camel-k-operator-console-openshift
ExpectedOSClusterRoles = 1
)

func TestSetupKustomizeBasic(t *testing.T) {
RegisterTestingT(t)
makeDir := testutil.MakeTempCopyDir(t, "../../../install")
Expand Down
62 changes: 62 additions & 0 deletions e2e/support/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ package support

import (
"os"
"os/exec"
"strings"
"testing"

. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
. "github.com/onsi/gomega/gstruct"
"github.com/onsi/gomega/types"
"github.com/stretchr/testify/assert"
)

func init() {
Expand All @@ -50,3 +55,60 @@ func GetEnvOrDefault(key string, deflt string) string {
return deflt
}
}

func ExpectExecSucceed(t *testing.T, command *exec.Cmd) {
t.Helper()

var cmdOut strings.Builder
var cmdErr strings.Builder

defer func() {
if t.Failed() {
t.Logf("Output from make command:\n%s\n", cmdOut.String())
t.Logf("Error from make command:\n%s\n", cmdErr.String())
}
}()

session, err := gexec.Start(command, &cmdOut, &cmdErr)
session.Wait()
Eventually(session).Should(gexec.Exit(0))
assert.NoError(t, err)
assert.NotContains(t, strings.ToUpper(cmdErr.String()), "ERROR")
}

//
// Expect a command error with an exit code of 1
//
func ExpectExecError(t *testing.T, command *exec.Cmd) {
t.Helper()

var cmdOut strings.Builder
var cmdErr strings.Builder

defer func() {
if t.Failed() {
t.Logf("Output from make command:\n%s\n", cmdOut.String())
t.Logf("Error from make command:\n%s\n", cmdErr.String())
}
}()

session, err := gexec.Start(command, &cmdOut, &cmdErr)
session.Wait()
Eventually(session).ShouldNot(gexec.Exit(0))
assert.NoError(t, err)
assert.Contains(t, strings.ToUpper(cmdErr.String()), "ERROR")
}

// Clean up the cluster ready for the next set of tests
func Cleanup() {
// Remove the locally installed operator
UninstallAll()

// Ensure the CRDs & ClusterRoles are reinstalled if not already
Kamel("install", "--olm=false", "--cluster-setup").Execute()
}

// Removes all items
func UninstallAll() {
Kamel("uninstall", "--olm=false", "--all").Execute()
}

0 comments on commit 78a0a06

Please sign in to comment.