4444 "subject" : SubjectHandle ,
4545 "permissions" : AllPermissions ,
4646 }
47+ ExpectedSourcesJson = map [string ]interface {}{
48+ "subject" : SubjectHandle ,
49+ "permissions" : AllPermissions ,
50+ "sources" : []string {"Static" },
51+ }
4752)
4853
4954func TestPermissionsDescribeJson (t * testing.T ) {
@@ -112,6 +117,22 @@ func TestPermissionsDescribeFilterPermission(t *testing.T) {
112117 assert .Nil (t , calls [0 ].Presource )
113118}
114119
120+ func TestPermissionsDescribeFilterSource (t * testing.T ) {
121+ cli := di .NewMockDeps (t )
122+ cmd := DescribePermissionsCommand (& cli .Deps )
123+
124+ cli .MockClient .ApiMocks .PermissionsApi .DescribePermissionsResponse .Result = * Description
125+
126+ di .ExecuteCommandWithContextUnsafe (& cli .Deps , cmd , "--subject" , SubjectHandle , "--source" , "static" )
127+
128+ s := stackstate_api .SUBJECTSOURCE_STATIC
129+ calls := * cli .MockClient .ApiMocks .PermissionsApi .DescribePermissionsCalls
130+ assert .Len (t , calls , 1 )
131+ assert .Equal (t , SubjectHandle , calls [0 ].Psubject )
132+ assert .Equal (t , & s , calls [0 ].Psource )
133+ assert .Nil (t , calls [0 ].Presource )
134+ }
135+
115136func TestPermissionsDescribeFilterResourceAndPermission (t * testing.T ) {
116137 cli := di .NewMockDeps (t )
117138 cmd := DescribePermissionsCommand (& cli .Deps )
@@ -126,3 +147,40 @@ func TestPermissionsDescribeFilterResourceAndPermission(t *testing.T) {
126147 assert .Equal (t , "foo" , * calls [0 ].Ppermission )
127148 assert .Equal (t , Resource1 , * calls [0 ].Presource )
128149}
150+
151+ func TestPermissionsDescribeWithSourcesJson (t * testing.T ) {
152+ cli := di .NewMockDeps (t )
153+ cmd := DescribePermissionsCommand (& cli .Deps )
154+
155+ cli .MockClient .ApiMocks .PermissionsApi .DescribePermissionsResponse .Result = * Description
156+ cli .MockClient .ApiMocks .PermissionsApi .DescribePermissionsResponse .Result .FromSources = []stackstate_api.SubjectSource {stackstate_api .SUBJECTSOURCE_STATIC }
157+
158+ di .ExecuteCommandWithContextUnsafe (& cli .Deps , cmd , "--subject" , SubjectHandle , "-o" , "json" )
159+
160+ calls := * cli .MockClient .ApiMocks .PermissionsApi .DescribePermissionsCalls
161+ assert .Len (t , calls , 1 )
162+
163+ expected := []map [string ]interface {}{
164+ ExpectedSourcesJson ,
165+ }
166+ assert .Equal (t , expected , * cli .MockPrinter .PrintJsonCalls )
167+ }
168+
169+ func TestPermissionsDescribeWithSourcesTable (t * testing.T ) {
170+ cli := di .NewMockDeps (t )
171+ cmd := DescribePermissionsCommand (& cli .Deps )
172+
173+ cli .MockClient .ApiMocks .PermissionsApi .DescribePermissionsResponse .Result = * Description
174+ cli .MockClient .ApiMocks .PermissionsApi .DescribePermissionsResponse .Result .FromSources = []stackstate_api.SubjectSource {stackstate_api .SUBJECTSOURCE_STATIC }
175+
176+ di .ExecuteCommandWithContextUnsafe (& cli .Deps , cmd , "--subject" , SubjectHandle )
177+
178+ assert .Len (t , * cli .MockClient .ApiMocks .PermissionsApi .DescribePermissionsCalls , 1 )
179+
180+ expected := []printer.TableData {
181+ ExpectedTable ,
182+ }
183+
184+ assert .Equal (t , expected , * cli .MockPrinter .TableCalls )
185+ assert .Equal (t , []string ([]string {"Got subject from the following subject sources: Static" , "" }), * cli .MockPrinter .PrintLnCalls )
186+ }
0 commit comments