test(cli): add artifact CLI tests using mock-based golden framework#6419
test(cli): add artifact CLI tests using mock-based golden framework#6419sachin9058 wants to merge 22 commits intomindersec:mainfrom
Conversation
|
@evankanderson Thanks I see that the recent changes in #6386 and #6414 move toward a more realistic CLI testing framework using full command execution and mock injection. I’ll take a look at those and rework this PR to align with that approach instead of focusing on help output. |
|
@evankanderson Updated this to align with the testing approach from #6386/#6414.
Keeping the scope focused on artifact commands to validate the approach before expanding further. |
|
Fixed the CI timeout issue. Root cause was Updated the command to use a direct Tests no longer trigger login or xdg-open in CI. |
evankanderson
left a comment
There was a problem hiding this comment.
Can you add tests for artifact get in this PR, as well as list?
|
@evankanderson Thanks for the suggestion. I noticed profile/status golden tests are already being added in #6420, so to avoid duplication I added golden-output tests for the artifact commands affected in this PR (specifically This should now cover output validation without overlapping with existing work. |
|
I’ve addressed the remaining points:
Both commands now use direct Let me know if you’d like any additional coverage or adjustments. |
evankanderson
left a comment
There was a problem hiding this comment.
Sorry that you're colliding with the somewhat-broader #6420; there are a few things you'll probably want to pick up from that PR. I think that's probably the last golden-file-testing related infrastructure change at the moment.
dfaa74f to
745cd1b
Compare
|
@evankanderson Thanks I’ve rebased this PR onto the latest branch and aligned it with the pattern from #6420.
All CLI tests pass locally: Let me know if anything still needs adjustment. |
|
I also updated the artifact get goldens (the failure was due to JSON formatting differences only spacing changes, not data changes). Locally everything is passing:
However, CI is still failing on the artifact tests, and I’m not able to reproduce the failure locally. Could you help point out what’s different in CI or if there’s something I might be missing (e.g., environment-specific formatting or test expectations)? Happy to adjust once I understand the discrepancy. |
|
This is also affected by #6430 |
|
@evankanderson Thanks This PR was still using JSON golden tests, so it was hitting the same protojson instability tracked in #6430. I’ve removed the JSON test cases and goldens here as well and kept table/yaml outputs. All CLI tests are now passing locally. |
- add reasoning column to CLI output - aggregate details, guidance, remediation, alerts, and output - centralize reasoning formatting helpers - improve readability with bullet formatting - remove previous explain-mode implementation
… RPC injection - add golden-output tests for artifact get (table/json/yaml + error) - add fixtures and goldens for CLI output validation - inject RPC clients via context for test isolation - short-circuit gRPC setup when injected clients are present to avoid login/network in tests
… pattern - switch artifact get to use cli.GetCLIClient for both artifact and profile clients - remove custom injection logic and align with upstream CLI patterns - add golden-output tests for artifact get (table/json/yaml + error case) - use gomock-based clients with realistic evaluation data - update goldens to reflect current CLI formatting - regenerate profile/status goldens after rebase to match latest output
- add table/json/yaml golden tests for - use injected RPC client to avoid login flow in CI - keep artifact list tests unchanged (already covered)
…tructure - add golden tests for artifact get - add --from test case for artifact list - move getArtifactClient to artifact.go - split tests into artifact_list_test.go and artifact_get_test.go - remove outdated profile tests to avoid duplication
- keep table/yaml goldens - remove JSON goldens (see mindersec#6430) - update profile status table outputs to match current renderer
684cf15 to
231a024
Compare
|
@evankanderson Rebased onto latest upstream/main and resolved the conflicts.
Let me know if anything else needs adjustment. |
There was a problem hiding this comment.
Changes in this file don't appear meaningful?
There was a problem hiding this comment.
This adds one newline, removes one newline, and removes a useful comment about why json output is not tested.
I don't understand why this comment was resolved.
There was a problem hiding this comment.
Ahh sorry Evan actually i forget to address this comment and resolved this comment accidently. Now i have fixed this file so that it matches exactly with the upstream.
…ction - replace getArtifactClient with cli.GetCLIClient - remove custom context injection logic - clean up unnecessary test changes
|
@evankanderson Thanks addressed these points:
All CLI tests are passing locally. Let me know if anything else needs adjustment. |
sachin9058
left a comment
There was a problem hiding this comment.
Now i have restored the comments and all the lines now it looks good and same as upstream
|
@evankanderson I’m not able to reproduce these lint failures locally. Running This looks like a mismatch between local and CI lint environments (possibly different golangci-lint versions or config). Would you like me to align with the CI setup and investigate further, or should these be handled separately? |
| fromFilter := viper.GetString("from") | ||
| return nil | ||
| }, | ||
| RunE: func(cmd *cobra.Command, _ []string) error { |
There was a problem hiding this comment.
Converting this from a function named listCommand to an anonymous function adjusts the indentation in a way that makes the GitHub diff very hard to review. Please put this back to listCommand, in the same style as every other command.
Summary
This PR aligns CLI tests with the testing framework introduced in #6386 and #6414 by replacing help-output based tests with full command execution tests using mocked RPC clients and golden file assertions.
Key changes:
cli.CmdTestCase+cli.RunCmdTestscli.LoadFixtureartifactcommands (list, supporting multiple output formats)The scope is intentionally limited to validate the pattern before expanding it to other CLI commands.
Testing
Ran:
go test ./cmd/cli/app/artifact -run TestArtifactListCommand -vgo test ./cmd/cli/... -vRegenerated golden files using:
go test ./cmd/cli/app/artifact -run TestArtifactListCommand -v -args -updateVerified:
Ensured all CLI tests pass locally without regressions