Skip to content

Commit 43d7bb7

Browse files
committed
Updated dump test
Signed-off-by: ravjot07 <[email protected]>
1 parent 02633f8 commit 43d7bb7

File tree

1 file changed

+55
-40
lines changed

1 file changed

+55
-40
lines changed

test/e2e/kmeshctl_test.go

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -120,46 +120,61 @@ func runDumpCmd(args ...string) (string, error) {
120120
return string(out), err
121121
}
122122

123-
func TestKmeshctlDump(t *testing.T) {
124-
pod := findKmeshPod(t)
125-
waitForPodRunning(t, pod)
126-
127-
128-
t.Run("kernel-native", func(t *testing.T) {
129-
out, err := runDumpCmd(pod, "kernel-native")
130-
t.Logf("Output of 'kmeshctl dump %s kernel-native':\n%s", pod, out)
131-
if err != nil {
132-
t.Fatalf("dump kernel-native failed: %v", err)
133-
}
134-
if strings.TrimSpace(out) == "" {
135-
t.Errorf("expected non-empty output for kernel-native, got empty")
136-
}
137-
})
138-
139-
140-
t.Run("dual-engine", func(t *testing.T) {
141-
out, err := runDumpCmd(pod, "dual-engine")
142-
t.Logf("Output of 'kmeshctl dump %s dual-engine':\n%s", pod, out)
143-
if err != nil {
144-
t.Fatalf("dump dual-engine failed: %v", err)
145-
}
146-
if strings.TrimSpace(out) == "" {
147-
t.Errorf("expected non-empty output for dual-engine, got empty")
148-
}
149-
})
150-
151-
152-
t.Run("invalid-mode", func(t *testing.T) {
153-
out, err := runDumpCmd(pod, "invalid-mode")
154-
t.Logf("Output of 'kmeshctl dump %s invalid-mode':\n%s", pod, out)
155-
if err == nil {
156-
t.Fatal("expected error for invalid mode, but command succeeded")
157-
}
158-
if !strings.Contains(out, "Argument must be 'kernel-native' or 'dual-engine'") {
159-
t.Errorf("expected error message about valid modes, got:\n%s", out)
160-
}
161-
})
162-
}
123+
func TestKmeshctlDump(t *testing.T) {
124+
pod := findKmeshPod(t)
125+
waitForPodRunning(t, pod)
126+
127+
t.Run("kernel-native", func(t *testing.T) {
128+
out, err := runDumpCmd(pod, "kernel-native")
129+
t.Logf("Output of 'kmeshctl dump %s kernel-native':\n%s", pod, out)
130+
131+
if strings.Contains(out, "Invalid Client Mode") {
132+
t.Log("kernel-native not supported; got expected error")
133+
return
134+
}
135+
if err != nil {
136+
t.Fatalf("dump kernel-native failed: %v\n%s", err, out)
137+
}
138+
if !strings.Contains(out, `"workloads"`) {
139+
t.Errorf("expected JSON to contain \"workloads\" array, got:\n%s", out)
140+
}
141+
if !strings.Contains(out, `"services"`) {
142+
t.Errorf("expected JSON to contain \"services\" array, got:\n%s", out)
143+
}
144+
})
145+
146+
t.Run("dual-engine", func(t *testing.T) {
147+
out, err := runDumpCmd(pod, "dual-engine")
148+
t.Logf("Output of 'kmeshctl dump %s dual-engine':\n%s", pod, out)
149+
if err != nil {
150+
t.Fatalf("dump dual-engine failed: %v\n%s", err, out)
151+
}
152+
if !strings.Contains(out, `"workloads"`) {
153+
t.Errorf("expected JSON to contain \"workloads\" array, got:\n%s", out)
154+
}
155+
if !strings.Contains(out, `"services"`) {
156+
t.Errorf("expected JSON to contain \"services\" array, got:\n%s", out)
157+
}
158+
})
159+
160+
t.Run("invalid-mode", func(t *testing.T) {
161+
out, err := runDumpCmd(pod, "invalid-mode")
162+
t.Logf("Output of 'kmeshctl dump %s invalid-mode':\n%s", pod, out)
163+
if err == nil {
164+
t.Fatal("expected error for invalid mode, but command succeeded")
165+
}
166+
if !strings.Contains(out, "Argument must be 'kernel-native' or 'dual-engine'") {
167+
t.Errorf("expected usage error, got:\n%s", out)
168+
}
169+
})
170+
}
171+
172+
func runAccesslogCmd(args ...string) (string, error) {
173+
cmdArgs := append([]string{"monitoring"}, args...)
174+
cmd := exec.Command("kmeshctl", cmdArgs...)
175+
out, err := cmd.CombinedOutput()
176+
return string(out), err
177+
}
163178

164179
func runAccesslogCmd(args ...string) (string, error) {
165180
cmdArgs := append([]string{"monitoring"}, args...)

0 commit comments

Comments
 (0)