Skip to content

Commit 02633f8

Browse files
committed
test: added test for kmeshctl authz
Signed-off-by: ravjot07 <[email protected]>
1 parent f783cd2 commit 02633f8

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

test/e2e/kmeshctl_test.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,5 +392,46 @@ func TestKmeshctlDump(t *testing.T) {
392392
}
393393
}
394394

395+
func runAuthzCmd(args ...string) (string, error) {
396+
cmdArgs := append([]string{"authz"}, args...)
397+
cmd := exec.Command("kmeshctl", cmdArgs...)
398+
out, err := cmd.CombinedOutput()
399+
return string(out), err
400+
}
395401

396-
402+
func TestKmeshctlAuthzEnableDisable(t *testing.T) {
403+
pod := findKmeshPod(t)
404+
waitForPodRunning(t, pod)
405+
406+
t.Run("enable-cluster", func(t *testing.T) {
407+
out, err := runAuthzCmd("enable")
408+
t.Logf("Output of 'kmeshctl authz enable':\n%s", out)
409+
if err != nil {
410+
t.Fatalf("cluster-wide enable failed: %v", err)
411+
}
412+
})
413+
414+
t.Run("disable-cluster", func(t *testing.T) {
415+
out, err := runAuthzCmd("disable")
416+
t.Logf("Output of 'kmeshctl authz disable':\n%s", out)
417+
if err != nil {
418+
t.Fatalf("cluster-wide disable failed: %v", err)
419+
}
420+
})
421+
422+
t.Run("enable-pod", func(t *testing.T) {
423+
out, err := runAuthzCmd("enable", pod)
424+
t.Logf("Output of 'kmeshctl authz enable %s':\n%s", pod, out)
425+
if err != nil {
426+
t.Fatalf("per-pod enable failed: %v", err)
427+
}
428+
})
429+
430+
t.Run("disable-pod", func(t *testing.T) {
431+
out, err := runAuthzCmd("disable", pod)
432+
t.Logf("Output of 'kmeshctl authz disable %s':\n%s", pod, out)
433+
if err != nil {
434+
t.Fatalf("per-pod disable failed: %v", err)
435+
}
436+
})
437+
}

0 commit comments

Comments
 (0)