Skip to content

test: cover debug log container detection#15

Open
guoqqqi wants to merge 1 commit intoapi7:mainfrom
guoqqqi:codex/debug-log-test-coverage
Open

test: cover debug log container detection#15
guoqqqi wants to merge 1 commit intoapi7:mainfrom
guoqqqi:codex/debug-log-test-coverage

Conversation

@guoqqqi
Copy link
Copy Markdown

@guoqqqi guoqqqi commented Apr 7, 2026

Summary

  • add unit coverage for debug log container selection edge cases
  • add E2E coverage for the auto-detect debug logs path used by CI
  • skip the E2E auto-detect assertion when no CI-style apisix container is running locally

Validation

  • go test ./pkg/cmd/debug/logs
  • go test ./pkg/cmd/debug/logs ./test/e2e -run 'TestDebugLogs_AutoDetectContainer' -tags e2e -count=1 -v -timeout 10m

Refs #14

Summary by CodeRabbit

  • Tests
    • Added unit tests for container selection logic in the debug logs command, covering single and multiple container scenarios.
    • Added end-to-end test for debug logs command with automatic container detection.

Copilot AI review requested due to automatic review settings April 7, 2026 09:48
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a779d430-5b91-4c6c-8458-f2c313be008f

📥 Commits

Reviewing files that changed from the base of the PR and between 85d58d7 and 19db128.

📒 Files selected for processing (2)
  • pkg/cmd/debug/logs/logs_test.go
  • test/e2e/debug_logs_test.go

📝 Walkthrough

Walkthrough

Added unit tests verifying chooseContainer behavior for single and multiple container scenarios, and an e2e test validating auto-detection of APISIX containers in debug logs commands without explicit container specification.

Changes

Cohort / File(s) Summary
Unit tests for container selection
pkg/cmd/debug/logs/logs_test.go
Added two test cases verifying chooseContainer function: one for single container input returning the container name, another for multiple containers returning a formatted error message.
E2E test for auto-detection
test/e2e/debug_logs_test.go
Added test TestDebugLogs_AutoDetectContainer that invokes debug logs command without container flag and validates successful execution or graceful skip when containers are unavailable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the changeset: adding test coverage for debug log container detection, which is precisely what both the unit tests and E2E test accomplish.
E2e Test Quality Review ✅ Passed E2E test adequately covers the primary business flow of auto-detecting APISIX containers for the debug logs command using real service execution.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds test coverage around a6 debug logs container auto-detection and container selection edge cases, aligning with CI’s “auto-detect container name” behavior and the follow-up testing gaps noted in #14.

Changes:

  • Added an E2E test that runs a6 debug logs without --container to validate CI-style auto-detection behavior.
  • Added unit tests for chooseContainer covering single-container and multiple-container selection outcomes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/e2e/debug_logs_test.go Adds an E2E test for debug logs container auto-detection behavior.
pkg/cmd/debug/logs/logs_test.go Adds unit coverage for chooseContainer single/multiple container edge cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +20 to +27
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)
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants