Skip to content
Merged
Changes from all commits
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
80 changes: 80 additions & 0 deletions test/e2e/debug_ginkgo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//go:build e2e

package e2e

import (
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("debug logs command", func() {
It("reads APISIX container logs when Docker access is available", func() {
g := NewWithT(GinkgoT())
env := setupCLIEnvWithKey(g, adminKey)

stdout, stderr, err := runA6WithEnv(env, "debug", "logs", "--container", "apisix", "--tail", "10")
skipIfDockerLogsUnavailable(stdout, stderr, err)
g.Expect(err).NotTo(HaveOccurred(), "stdout=%s stderr=%s", stdout, stderr)
g.Expect(strings.TrimSpace(stdout)).NotTo(BeEmpty())

stdout, stderr, err = runA6WithEnv(env, "debug", "logs", "--container", "apisix", "--tail", "5", "--since", "1h")
skipIfDockerLogsUnavailable(stdout, stderr, err)
g.Expect(err).NotTo(HaveOccurred(), "stdout=%s stderr=%s", stdout, stderr)
})

It("auto-detects APISIX containers when available", func() {
g := NewWithT(GinkgoT())
env := setupCLIEnvWithKey(g, adminKey)

stdout, stderr, err := runA6WithEnv(env, "debug", "logs", "--tail", "10")
skipIfDockerLogsUnavailable(stdout, stderr, err)
if err != nil && strings.Contains(stderr, "no APISIX container found") {
Skip("no auto-detectable APISIX container is running")
}
Comment on lines +33 to +35
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Skip("no auto-detectable APISIX container is running") branch is redundant/unreachable because skipIfDockerLogsUnavailable already skips on the same condition (no apisix container found). Consider removing this if block, or move the no APISIX container found handling before calling skipIfDockerLogsUnavailable if you want a more specific skip message here.

Suggested change
if err != nil && strings.Contains(stderr, "no APISIX container found") {
Skip("no auto-detectable APISIX container is running")
}

Copilot uses AI. Check for mistakes.
g.Expect(err).NotTo(HaveOccurred(), "stdout=%s stderr=%s", stdout, stderr)
g.Expect(strings.TrimSpace(stdout)).NotTo(BeEmpty())
})

It("surfaces missing container errors", func() {
g := NewWithT(GinkgoT())
env := setupCLIEnvWithKey(g, adminKey)

_, stderr, err := runA6WithEnv(env, "debug", "logs", "--container", "non-existent-container-xyz", "--tail", "5")
g.Expect(err).To(HaveOccurred())
g.Expect(stderr).To(SatisfyAny(
ContainSubstring("No such container"),
ContainSubstring("not found"),
))
})
})

var _ = Describe("debug trace command", func() {
It("surfaces not-found errors without proxy traffic", func() {
g := NewWithT(GinkgoT())
env := setupCLIEnvWithKey(g, adminKey)

_, stderr, err := runA6WithEnv(env, "debug", "trace", "non-existent-debug-route")
g.Expect(err).To(HaveOccurred())
g.Expect(strings.ToLower(stderr)).To(SatisfyAny(
ContainSubstring("resource not found"),
ContainSubstring("not found"),
ContainSubstring("404"),
))
})
})

func skipIfDockerLogsUnavailable(stdout, stderr string, err error) {
if err == nil {
return
}

combined := strings.ToLower(stdout + stderr)
if strings.Contains(combined, "cannot connect to the docker daemon") ||
strings.Contains(combined, "permission denied") ||
strings.Contains(combined, "no such container") ||
strings.Contains(combined, "no apisix container found") {
Skip("Docker logs are unavailable in this environment: " + strings.TrimSpace(stdout+stderr))
}
Comment on lines +73 to +79
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skipIfDockerLogsUnavailable doesn't currently skip when Docker isn't installed (the CLI returns "docker binary not found in PATH"), which can cause these tests to fail in environments without Docker. It may also be worth handling the CLI's "multiple APISIX containers found" auto-detect error as a skip condition for the auto-detect test to avoid flakiness when multiple containers are running.

Copilot uses AI. Check for mistakes.
}
Loading