Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions pkg/cmd/debug/logs/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ func TestLogs_NoContainerNoFile(t *testing.T) {
require.Error(t, err)
assert.Contains(t, err.Error(), "no APISIX container found")
}

func TestLogs_ChooseContainerSingle(t *testing.T) {
container, err := chooseContainer([]string{"apisix"})
require.NoError(t, err)
assert.Equal(t, "apisix", container)
}

func TestLogs_ChooseContainerMultiple(t *testing.T) {
_, err := chooseContainer([]string{"apisix", "apisix-staging"})
require.Error(t, err)
assert.Contains(t, err.Error(), "multiple APISIX containers found")
assert.Contains(t, err.Error(), "apisix, apisix-staging")
}
11 changes: 11 additions & 0 deletions test/e2e/debug_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package e2e

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -16,6 +17,16 @@ func TestDebugLogs_DockerMode(t *testing.T) {
assert.NotEmpty(t, stdout)
}

func TestDebugLogs_AutoDetectContainer(t *testing.T) {
env := setupRouteEnv(t)
stdout, stderr, err := runA6WithEnv(env, "debug", "logs", "--tail", "10")
if err != nil && strings.Contains(stderr, "no APISIX container found") {
t.Skipf("skipping auto-detect test because no CI-style apisix container is running: %s", stderr)
}
require.NoError(t, err, "debug logs auto-detect failed: stdout=%s stderr=%s", stdout, stderr)
assert.NotEmpty(t, stdout)
Comment on lines +20 to +27
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

TestDebugLogs_AutoDetectContainer only skips when the CLI reports "no APISIX container found". However, the auto-detect path (docker ps --filter name=apisix) can also fail with "multiple APISIX containers found" in common local setups (e.g., running apisix plus apisix-dashboard/apisix-* containers), which would make this new E2E test fail even though it’s simply not a CI-style environment. Consider extending the skip condition to also cover the multiple-containers case (or more generally, skip when auto-detect fails due to non-CI container topology).

Copilot uses AI. Check for mistakes.
}

func TestDebugLogs_DockerModeWithSince(t *testing.T) {
env := setupRouteEnv(t)
stdout, stderr, err := runA6WithEnv(env, "debug", "logs", "--container", "apisix", "--tail", "5", "--since", "1h")
Expand Down
Loading