-
Notifications
You must be signed in to change notification settings - Fork 1
test: add debug command ginkgo e2e #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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") | ||
| } | ||
| 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
|
||
| } | ||
There was a problem hiding this comment.
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 becauseskipIfDockerLogsUnavailablealready skips on the same condition (no apisix container found). Consider removing thisifblock, or move theno APISIX container foundhandling before callingskipIfDockerLogsUnavailableif you want a more specific skip message here.