-
Notifications
You must be signed in to change notification settings - Fork 107
test(cli): add artifact CLI tests using mock-based golden framework #6419
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
Open
sachin9058
wants to merge
22
commits into
mindersec:main
Choose a base branch
from
sachin9058:test/cli-standardize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
299d3af
feat(cli): improve evaluation reasoning output using existing fields
sachin9058 46ea753
refactor(cli): simplify evaluation details rendering and apply review…
sachin9058 e2fba50
chore: trigger CI rerun
sachin9058 156b8f7
refactor(cli): address review feedback and simplify details rendering
sachin9058 1268cee
test(cli): add golden tests for artifact get and enable test-friendly…
sachin9058 662d3fa
feat(cli): add artifact get command tests and align with GetCLIClient…
sachin9058 b806f75
test(cli): standardize CLI tests and improve validation
sachin9058 50167d8
Standardize artifact and profile CLI tests
sachin9058 1854d92
test(cli): align artifact tests with CmdTestCase + golden pattern
sachin9058 fbcda82
fix(cli): avoid GRPC wrapper in artifact list to prevent login flow i…
sachin9058 fb333b5
test(cli): add golden tests for artifact get and fix CI login issue
sachin9058 d85ea5d
test(cli): add artifact get tests, from filter case, and align test s…
sachin9058 0d81ca5
test(cli): refresh artifact get golden tests
sachin9058 00599e6
fix(cli): format generated artifact mock
sachin9058 2728e07
chore: trigger CI
sachin9058 f6cc27a
test(cli): remove JSON golden tests due to protojson instability (see…
sachin9058 231a024
test(cli): update goldens after rebase and renderer changes
sachin9058 f503cb3
refactor(cli): inline artifact list logic into RunE
sachin9058 8c4ab04
test(cli): remove remaining JSON goldens and finalize CLI test cleanup
sachin9058 0fba74f
refactor(cli): align with cli.GetCLIClient and remove custom RPC inje…
sachin9058 4556e51
chore(test): restore upstream comments in artifact_get_test.go
sachin9058 9aa2a52
chore: retrigger CI
sachin9058 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2026 The Minder Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package artifact | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "go.uber.org/mock/gomock" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
|
|
||
| "github.com/mindersec/minder/internal/util/cli" | ||
| minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1" | ||
| mockv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1/mock" | ||
| ) | ||
|
|
||
| //nolint:paralleltest // Cannot run in parallel because it swaps global Viper/Stdout state | ||
| func TestArtifactListCommand(t *testing.T) { | ||
| setupSuccess := func(t *testing.T, ctrl *gomock.Controller) context.Context { | ||
| t.Helper() | ||
| client := mockv1.NewMockArtifactServiceClient(ctrl) | ||
|
|
||
| mockResp := &minderv1.ListArtifactsResponse{} | ||
| cli.LoadFixture(t, "mock_artifact_list.json", mockResp) | ||
|
|
||
| client.EXPECT(). | ||
| ListArtifacts(gomock.Any(), gomock.Any()). | ||
| Return(mockResp, nil). | ||
| Times(1) | ||
|
|
||
| return cli.WithRPCClient[minderv1.ArtifactServiceClient](context.Background(), client) | ||
| } | ||
|
|
||
| tests := []cli.CmdTestCase{ | ||
| { | ||
| Name: "list artifacts - table output", | ||
| Args: []string{"artifact", "list", "-o", "table"}, | ||
| MockSetup: setupSuccess, | ||
| GoldenFileName: "artifact_list.table", | ||
| }, | ||
| { | ||
| Name: "list artifacts - yaml output", | ||
| Args: []string{"artifact", "list", "-o", "yaml"}, | ||
| MockSetup: setupSuccess, | ||
| GoldenFileName: "artifact_list.yaml", | ||
| }, | ||
| { | ||
| Name: "list artifacts with from filter", | ||
| Args: []string{"artifact", "list", "--from", "repository=org/repo", "-o", "table"}, | ||
| MockSetup: setupSuccess, | ||
| GoldenFileName: "artifact_list_from.table", | ||
| }, | ||
| { | ||
| Name: "server error handling", | ||
| Args: []string{"artifact", "list"}, | ||
| MockSetup: func(t *testing.T, ctrl *gomock.Controller) context.Context { | ||
| t.Helper() | ||
| client := mockv1.NewMockArtifactServiceClient(ctrl) | ||
| client.EXPECT(). | ||
| ListArtifacts(gomock.Any(), gomock.Any()). | ||
| Return(nil, status.Error(codes.Internal, "internal server error")). | ||
| Times(1) | ||
|
|
||
| return cli.WithRPCClient[minderv1.ArtifactServiceClient](context.Background(), client) | ||
| }, | ||
| ExpectedError: "internal server error", | ||
| }, | ||
| } | ||
|
|
||
| cli.RunCmdTests(t, tests, ArtifactCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "results": [ | ||
| { | ||
| "artifactPk": "111", | ||
| "name": "artifact-1", | ||
| "type": "image", | ||
| "owner": "owner-1", | ||
| "repository": "org/repo", | ||
| "visibility": "public", | ||
| "createdAt": "2024-01-02T15:04:05Z" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ID │ TYPE │ OWNER │ NAME │ REPOSITORY │ VISIBILITY │ CREATION DATE | ||
| ───────┼────────┼──────────┼──────────────┼──────────────┼──────────────┼─────────────────────────── | ||
| 111 │ image │ owner-1 │ artifact-1 │ org/repo │ public │ 2024-01-02T15:04:05Z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| results: | ||
| - artifactPk: "111" | ||
| createdAt: "2024-01-02T15:04:05Z" | ||
| name: artifact-1 | ||
| owner: owner-1 | ||
| repository: org/repo | ||
| type: image | ||
| visibility: public | ||
|
|
3 changes: 3 additions & 0 deletions
3
cmd/cli/app/artifact/testdata/artifact_list_from.table.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ID │ TYPE │ OWNER │ NAME │ REPOSITORY │ VISIBILITY │ CREATION DATE | ||
| ───────┼────────┼──────────┼──────────────┼──────────────┼──────────────┼─────────────────────────── | ||
| 111 │ image │ owner-1 │ artifact-1 │ org/repo │ public │ 2024-01-02T15:04:05Z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Converting this from a function named
listCommandto an anonymous function adjusts the indentation in a way that makes the GitHub diff very hard to review. Please put this back tolistCommand, in the same style as every other command.