CLI : added unit test files for project and project role#6418
Conversation
Signed-off-by: DharunMR <maddharun56@gmail.com>
evankanderson
left a comment
There was a problem hiding this comment.
See also my comment on #6420 about having a generic cmd -> grpc client function.
|
#6420 got merged, but we probably need to address #6417 (comment) -- coordinate with @sachin9058 on who's going to fix it. (TL;DR - Google deliberately makes |
|
Thanks for the heads up! I’ve been working on this in #6417 the issue comes from protojson output not being stable across environments, which causes flaky golden tests due to spacing differences. In my PR, I removed JSON golden tests and kept table/yaml outputs to avoid this instability. Happy to coordinate here we can either follow the same approach (skip JSON golden tests) or decide on a shared normalization strategy if we want to keep them. |
|
@sachin9058 filed #6430 to track the JSON golden test problem. |
evankanderson
left a comment
There was a problem hiding this comment.
Sorry for missing the comments on this earlier in the protojson-is-nondeterministic excitement.
| { | ||
| "displayName": "Mock Admin", | ||
| "subject": "admin-subject-123", | ||
| "role": "admin", | ||
| "project": "00000000-0000-0000-0000-000000000001" | ||
| } |
There was a problem hiding this comment.
Can we add a github action "user" here?
| { | |
| "displayName": "Mock Admin", | |
| "subject": "admin-subject-123", | |
| "role": "admin", | |
| "project": "00000000-0000-0000-0000-000000000001" | |
| } | |
| { | |
| "displayName": "Mock Admin", | |
| "subject": "admin-subject-123", | |
| "role": "admin", | |
| "project": "00000000-0000-0000-0000-000000000001" | |
| }, | |
| { | |
| "displayName": "githubactions/repo:myorg/myrepo:ref:refs/heads/main", | |
| "subject": "githubactions/repo+myorg/myrepo+ref+refs/heads/main", | |
| "role": "editor", | |
| "project": "00000000-0000-0000-0000-000000000001" | |
| }, |
| // GetPermissionsClient is a helper to get the PermissionsServiceClient, supporting mocks | ||
| func GetPermissionsClient(cmd *cobra.Command) (minderv1.PermissionsServiceClient, func(), error) { |
There was a problem hiding this comment.
Switch this to cli.GetGRPCClient?
| // DenyCommand is the command for removing a role assignment from a project | ||
| func DenyCommand(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc.ClientConn) error { | ||
| client := minderv1.NewPermissionsServiceClient(conn) | ||
| func DenyCommand(cmd *cobra.Command, _ []string) error { |
There was a problem hiding this comment.
I wonder why this function is exported. Can you switch it to denyCommand?
| // GrantCommand is the command for granting roles | ||
| func GrantCommand(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc.ClientConn) error { | ||
| client := minderv1.NewPermissionsServiceClient(conn) | ||
| func GrantCommand(cmd *cobra.Command, _ []string) error { |
There was a problem hiding this comment.
Ditto on unexporting this unless we need it exported (you'll also need to fix line 32)
| func GrantCommand(cmd *cobra.Command, _ []string) error { | |
| func grantCommand(cmd *cobra.Command, _ []string) error { |
| t.Render() | ||
| if len(resp.Invitations) > 0 { | ||
| t := initializeTableForGrantListInvitations(cmd.OutOrStdout()) | ||
| t2 := initializeTableForGrantListInvitations(cmd.OutOrStdout()) |
There was a problem hiding this comment.
Why change this name? I see that this t is shadowing the one in the outer scope, but that doesn't seem to be a problem.
| // listCommand is the command for listing projects | ||
| func createCommand(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc.ClientConn) error { | ||
| client := minderv1.NewProjectsServiceClient(conn) | ||
| // createCommand is the command for listing projects |
There was a problem hiding this comment.
| // createCommand is the command for listing projects | |
| // createCommand is the command for creating a new project |
| client := minderv1.NewProjectsServiceClient(conn) | ||
| // createCommand is the command for listing projects | ||
| func createCommand(cmd *cobra.Command, _ []string) error { | ||
| client, cleanup, err := GetProjectsClient(cmd) |
There was a problem hiding this comment.
Switch to cli.GetGRPCClient
| // listCommand is the command for listing projects | ||
| func deleteCommand(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc.ClientConn) error { | ||
| client := minderv1.NewProjectsServiceClient(conn) | ||
| // deleteCommand is the command for listing projects |
There was a problem hiding this comment.
| // deleteCommand is the command for listing projects | |
| // deleteCommand is the command to permanently delete a project |
Description
Continuing the pattern in #6386:
This PR introduces a comprehensive refactor of the
cmd/cli/app/projectandcmd/cli/app/project/rolepackage to modernize its testing architecture, improve separation of concerns. Stripped out manualctxandgrpc.ClientConnarguments from command execution functions to align with standard CobraRunEsignatures. Implemented the "backpack" pattern usingcmd.SetContext(ctx)andcli.WithRPCClientto inject mock clients cleanly during testing.🧪 How to Test
go test ./...(Should PASS)-updateflag:go test ./cmd/cli/app/project/ -updateandgo test ./cmd/cli/app/project/role -update