Skip to content

Commit b7c4b6c

Browse files
test: add new e2e test cases for kubectl plugin
Signed-off-by: Venkatesh Jayagopal <venkatesh.jayagopal@suse.com>
1 parent ee1c132 commit b7c4b6c

3 files changed

Lines changed: 781 additions & 2 deletions

File tree

test/e2e/e2e_suite_test.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"log/slog"
77
"os"
8+
"os/exec"
9+
"path/filepath"
810
"slices"
911
"strings"
1012
"testing"
@@ -49,6 +51,19 @@ func installDependencies() bool {
4951
return os.Getenv("E2E_SKIP_DEPENDENCIES") != "true"
5052
}
5153

54+
func makeKubectlPlugin() error {
55+
projectRoot := filepath.Join("..", "..")
56+
cmd := exec.Command("make", "kubectl-plugin")
57+
cmd.Dir = projectRoot
58+
cmd.Stdout = os.Stdout
59+
cmd.Stderr = os.Stderr
60+
61+
if err := cmd.Run(); err != nil {
62+
return fmt.Errorf("failed to run make kubectl-plugin: %w", err)
63+
}
64+
return nil
65+
}
66+
5267
type helmChart struct {
5368
name string
5469
namespace string
@@ -115,7 +130,11 @@ func getCharts() []helmChart {
115130
}
116131

117132
func TestMain(m *testing.M) {
133+
// we build kubectl_runtime-enforcer binary to run plugin e2e tests
134+
makeKubectlPlugin()
135+
118136
charts := getCharts()
137+
119138
commonSetupFuncs := []env.Func{
120139
// we uninstall here as a defensive check but nothing should be left behind
121140
uninstallHelmRepos(charts),
@@ -226,11 +245,19 @@ func installHelmRepos(charts []helmChart) env.Func {
226245
if strings.HasPrefix(chartPath, "/") {
227246
// First we try to add the repo.
228247
if err = manager.RunRepo(helm.WithArgs("add", chart.repoLocalName, chart.repoURL)); err != nil {
229-
return ctx, fmt.Errorf("failed to add local repo '%s': %w", chart.repoLocalName, err)
248+
return ctx, fmt.Errorf(
249+
"failed to add local repo '%s': %w",
250+
chart.repoLocalName,
251+
err,
252+
)
230253
}
231254
// Update the repo.
232255
if err = manager.RunRepo(helm.WithArgs("update")); err != nil {
233-
return ctx, fmt.Errorf("failed to update local repo '%s': %w", chart.repoLocalName, err)
256+
return ctx, fmt.Errorf(
257+
"failed to update local repo '%s': %w",
258+
chart.repoLocalName,
259+
err,
260+
)
234261
}
235262
// The final chart path will be the name of repoLocalName + chartPath
236263
chartPath = chart.repoLocalName + chartPath

test/e2e/e2e_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,37 @@ func TestOtelCollector(t *testing.T) {
6464

6565
testEnv.Test(t, getOtelCollectorTest())
6666
}
67+
68+
func TestKubectlPluginProposalPromoteTest(t *testing.T) {
69+
t.Log("test kubectl runtime-enforcer proposal promote PROPOSAL_NAME [flags]")
70+
71+
testEnv.Test(t, getKubectlPluginProposalPromoteTest())
72+
}
73+
74+
func TestKubectlPluginPolicyModeTest(t *testing.T) {
75+
t.Log("test kubectl runtime-enforcer policy monitor POLICY_NAME [flags]")
76+
77+
testEnv.Test(t, getKubectlPluginPolicyModeTest())
78+
}
79+
80+
func TestKubectlPluginPolicyExecAllowTest(t *testing.T) {
81+
t.Log(
82+
"test kubectl runtime-enforcer policy allow POLICY_NAME <container-name> <executable-name> [<executable-name>...] [flags]",
83+
)
84+
85+
testEnv.Test(t, getKubectlPluginPolicyExecAllowTest())
86+
}
87+
88+
func TestKubectlPluginPolicyExecDenyTest(t *testing.T) {
89+
t.Log(
90+
"test kubectl runtime-enforcer policy deny POLICY_NAME <container-name> <executable-name> [<executable-name>...] [flags]",
91+
)
92+
93+
testEnv.Test(t, getKubectlPluginPolicyExecDenyTest())
94+
}
95+
96+
func TestKubectlPluginErrorHandlingTest(t *testing.T) {
97+
t.Log("test kubectl runtime-enforcer ERROR handling")
98+
99+
testEnv.Test(t, getKubectlPluginErrorHandlingTest())
100+
}

0 commit comments

Comments
 (0)