@@ -3,15 +3,18 @@ package app
33import (
44 "context"
55 "errors"
6+ "reflect"
7+ "testing"
8+
69 "github.com/golang/mock/gomock"
710 "github.com/stretchr/testify/suite"
811 "github.com/temporalio/tcld/protogen/api/auth/v1"
912 "github.com/temporalio/tcld/protogen/api/authservice/v1"
1013 "github.com/temporalio/tcld/protogen/api/request/v1"
1114 authservicemock "github.com/temporalio/tcld/protogen/apimock/authservice/v1"
1215 "github.com/urfave/cli/v2"
13- "reflect "
14- "testing "
16+ "google.golang.org/grpc/codes "
17+ "google.golang.org/grpc/status "
1518)
1619
1720func TestUser (t * testing.T ) {
@@ -41,6 +44,7 @@ func (s *UserTestSuite) SetupTest() {
4144 }
4245 flags := []cli.Flag {
4346 AutoConfirmFlag ,
47+ IdempotentFlag ,
4448 }
4549 s .cliApp , _ = NewTestApp (s .T (), cmds , flags )
4650}
@@ -543,3 +547,56 @@ func (s *UserTestSuite) TestSetNamespacePermissionsEmpty() {
543547 }, nil )
544548 s .NoError (s .RunCmd ("user" , "set-namespace-permissions" , "--user-email" , "test@example.com" ))
545549}
550+
551+ func (s * UserTestSuite ) TestSetNamespacePermissionsNoChanges () {
552+ s .mockAuthService .EXPECT ().GetUser (gomock .Any (), gomock .Any ()).Return (& authservice.GetUserResponse {
553+ User : & auth.User {
554+ Id : "test-user-id" ,
555+ Spec : & auth.UserSpec {
556+ Email : "test@example.com" ,
557+ },
558+ },
559+ }, nil ).Times (1 )
560+ s .mockAuthService .EXPECT ().GetRoles (gomock .Any (), gomock .Any ()).Return (& authservice.GetRolesResponse {
561+ Roles : []* auth.Role {
562+ {
563+ Id : "test-account-developer-role" ,
564+ Type : auth .ROLE_TYPE_PREDEFINED ,
565+ Spec : & auth.RoleSpec {
566+ AccountRole : & auth.AccountRoleSpec {
567+ ActionGroup : auth .ACCOUNT_ACTION_GROUP_DEVELOPER ,
568+ },
569+ },
570+ },
571+ },
572+ }, nil ).Times (1 )
573+ s .mockAuthService .EXPECT ().GetRolesByPermissions (gomock .Any (), gomock .Any ()).Return (& authservice.GetRolesByPermissionsResponse {
574+ Roles : []* auth.Role {
575+ {
576+ Id : "test-ns1-admin-role" ,
577+ Type : auth .ROLE_TYPE_PREDEFINED ,
578+ Spec : & auth.RoleSpec {
579+ NamespaceRoles : []* auth.NamespaceRoleSpec {
580+ {
581+ Namespace : "ns1" ,
582+ ActionGroup : auth .NAMESPACE_ACTION_GROUP_ADMIN ,
583+ },
584+ },
585+ },
586+ },
587+ },
588+ }, nil ).Times (1 )
589+ s .mockAuthService .EXPECT ().UpdateUser (gomock .Any (), gomock .All (& updateUserRequestMatcher {
590+ request : & authservice.UpdateUserRequest {
591+ UserId : "test-user-id" ,
592+ Spec : & auth.UserSpec {
593+ Email : "test@example.com" ,
594+ Roles : []string {
595+ "test-account-developer-role" ,
596+ "test-ns1-admin-role" ,
597+ },
598+ },
599+ },
600+ })).Return (nil , status .Error (codes .InvalidArgument , "nothing to change" )).Times (1 )
601+ s .NoError (s .RunCmd ("--idempotent" , "user" , "set-namespace-permissions" , "--user-email" , "test@example.com" , "-p" , "ns1=Admin" , "-p" , "ns2=Write" , "-p" , "ns3=Read" ))
602+ }
0 commit comments