-
Notifications
You must be signed in to change notification settings - Fork 21
[test] Add tests for cmd.newProxyCmd and cmd.detectGuardWasm #3839
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,370 @@ | ||||||||||||
| package cmd | ||||||||||||
|
|
||||||||||||
| import ( | ||||||||||||
| "os" | ||||||||||||
| "strings" | ||||||||||||
| "testing" | ||||||||||||
|
|
||||||||||||
| "github.com/spf13/cobra" | ||||||||||||
| "github.com/stretchr/testify/assert" | ||||||||||||
| "github.com/stretchr/testify/require" | ||||||||||||
|
|
||||||||||||
| "github.com/github/gh-aw-mcpg/internal/config" | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| // TestDetectGuardWasm_FileNotFound tests that detectGuardWasm returns empty string | ||||||||||||
| // when the baked-in guard at containerGuardWasmPath does not exist. | ||||||||||||
| // In standard test environments (non-container), the baked-in guard is absent. | ||||||||||||
| func TestDetectGuardWasm_FileNotFound(t *testing.T) { | ||||||||||||
| // Confirm the baked-in path does not exist in this environment | ||||||||||||
| _, err := os.Stat(containerGuardWasmPath) | ||||||||||||
| if err == nil { | ||||||||||||
| t.Skipf("baked-in guard found at %s (running in container) — skipping 'not found' test", containerGuardWasmPath) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| result := detectGuardWasm() | ||||||||||||
| assert.Empty(t, result, "detectGuardWasm should return empty string when guard file does not exist") | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // TestDetectGuardWasm_FileExists verifies that detectGuardWasm returns the | ||||||||||||
| // containerGuardWasmPath when that file is present on the filesystem. | ||||||||||||
| // This test creates a temporary file at the expected path to simulate the container environment. | ||||||||||||
|
||||||||||||
| // This test creates a temporary file at the expected path to simulate the container environment. | |
| // It only validates environments where the baked-in guard already exists | |
| // (for example, inside the container image); otherwise the test is skipped. |
Copilot
AI
Apr 15, 2026
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.
In TestNewProxyCmd_DefaultFlagValues, the expectedType field in the test-case struct is never used. Dropping it would reduce noise and make the table test easier to maintain.
| flagName string | |
| expectedType string | |
| validate func(t *testing.T, cmd *cobra.Command) | |
| flagName string | |
| validate func(t *testing.T, cmd *cobra.Command) |
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.
TestDetectGuardWasm_FileNotFoundtreats anyos.Staterror as “file not present”. If the stat fails for reasons other than non-existence (e.g., permission issues), the test’s precondition isn’t met but it will still proceed. Consider checkingos.IsNotExist(err)(orerrors.Is(err, os.ErrNotExist)) and skipping/failing on unexpected errors to avoid false positives/flaky behavior.