@@ -20,28 +20,28 @@ function Search-AzureRmGraph-Query
20
20
{
21
21
$queryResult = Search-AzGraph " project id, tags, properties | limit 2"
22
22
23
- Assert-IsInstance $queryResult Object[]
24
- Assert-AreEqual $queryResult.Count 2
25
-
26
- Assert-IsInstance $queryResult [ 0 ] System.Management.Automation.PSCustomObject
27
- Assert-IsInstance $queryResult [ 1 ] System.Management.Automation.PSCustomObject
28
- Assert-PropertiesCount $queryResult [0 ] 4
29
- Assert-PropertiesCount $queryResult [1 ] 4
30
-
31
- Assert-IsInstance $queryResult [0 ].id String
32
- Assert-IsInstance $queryResult [1 ].id String
33
- Assert-IsInstance $queryResult [0 ].ResourceId String
34
- Assert-IsInstance $queryResult [1 ].ResourceId String
35
- Assert-IsInstance $queryResult [ 0 ].tags System.Management.Automation.PSCustomObject
36
- Assert-IsInstance $queryResult [ 1 ].tags System.Management.Automation.PSCustomObject
37
- Assert-IsInstance $queryResult [ 0 ].properties System.Management.Automation.PSCustomObject
38
- Assert-IsInstance $queryResult [ 1 ].properties System.Management.Automation.PSCustomObject
23
+ Assert-IsInstance Object[] $queryResult
24
+ Assert-AreEqual 2 $queryResult.Count
25
+
26
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [ 0 ]
27
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [ 1 ]
28
+ Assert-PropertiesCount 4 $queryResult [0 ]
29
+ Assert-PropertiesCount 4 $queryResult [1 ]
30
+
31
+ Assert-IsInstance String $queryResult [0 ].id
32
+ Assert-IsInstance String $queryResult [1 ].id
33
+ Assert-IsInstance String $queryResult [0 ].ResourceId
34
+ Assert-IsInstance String $queryResult [1 ].ResourceId
35
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [ 0 ].tags
36
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [ 1 ].tags
37
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [ 0 ].properties
38
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [ 1 ].properties
39
39
40
40
Assert-AreEqual $queryResult [0 ].id $queryResult [0 ].ResourceId
41
41
Assert-AreEqual $queryResult [1 ].id $queryResult [1 ].ResourceId
42
42
43
- Assert-PropertiesCount $queryResult [0 ].properties 6
44
- Assert-PropertiesCount $queryResult [1 ].properties 4
43
+ Assert-PropertiesCount 2 $queryResult [0 ].properties
44
+ Assert-PropertiesCount 4 $queryResult [1 ].properties
45
45
}
46
46
47
47
<#
@@ -53,24 +53,24 @@ function Search-AzureRmGraph-PagedQuery
53
53
# Page size was artificially set to 2 rows
54
54
$queryResult = Search-AzGraph " project id" - First 3 - Skip 2
55
55
56
- Assert-IsInstance $queryResult Object[]
57
- Assert-AreEqual $queryResult.Count 3
56
+ Assert-IsInstance Object[] $queryResult
57
+ Assert-AreEqual 3 $queryResult.Count
58
58
59
- Assert-IsInstance $queryResult [ 0 ] System.Management.Automation.PSCustomObject
60
- Assert-IsInstance $queryResult [ 1 ] System.Management.Automation.PSCustomObject
61
- Assert-IsInstance $queryResult [ 2 ] System.Management.Automation.PSCustomObject
59
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [ 0 ]
60
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [ 1 ]
61
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [ 2 ]
62
62
63
- Assert-PropertiesCount $queryResult [0 ] 2
64
- Assert-PropertiesCount $queryResult [1 ] 2
65
- Assert-PropertiesCount $queryResult [2 ] 2
63
+ Assert-PropertiesCount 2 $queryResult [0 ]
64
+ Assert-PropertiesCount 2 $queryResult [1 ]
65
+ Assert-PropertiesCount 2 $queryResult [2 ]
66
66
67
- Assert-IsInstance $queryResult [0 ].id String
68
- Assert-IsInstance $queryResult [1 ].id String
69
- Assert-IsInstance $queryResult [2 ].id String
67
+ Assert-IsInstance String $queryResult [0 ].id
68
+ Assert-IsInstance String $queryResult [1 ].id
69
+ Assert-IsInstance String $queryResult [2 ].id
70
70
71
- Assert-IsInstance $queryResult [0 ].ResourceId String
72
- Assert-IsInstance $queryResult [1 ].ResourceId String
73
- Assert-IsInstance $queryResult [2 ].ResourceId String
71
+ Assert-IsInstance String $queryResult [0 ].ResourceId
72
+ Assert-IsInstance String $queryResult [1 ].ResourceId
73
+ Assert-IsInstance String $queryResult [2 ].ResourceId
74
74
75
75
Assert-True { $queryResult [0 ].id.Length -gt 0 }
76
76
Assert-True { $queryResult [1 ].id.Length -gt 0 }
@@ -83,45 +83,78 @@ Run query with subscriptions explicitly passed
83
83
#>
84
84
function Search-AzureRmGraph-Subscriptions
85
85
{
86
- $testSubId1 = " 11111111-1111-1111-1111-111111111111"
87
- $testSubId2 = " 22222222-2222-2222-2222-222222222222"
88
- $mockedSubscriptionId = " 00000000-0000-0000-0000-000000000000"
86
+ $testSubId = " eaab1166-1e13-4370-a951-6ed345a48c15"
87
+ $nonExsitentTestSubId = " 000b1166-1e13-4370-a951-6ed345a48c16"
89
88
$query = " distinct subscriptionId | order by subscriptionId asc"
90
89
91
- $queryResultNoSubs = Search-AzGraph $query
92
- $queryResultOneSub = Search-AzGraph $query - Subscription $testSubId1
93
- $queryResultMultipleSubs = Search-AzGraph $query - Subscription @ ($testSubId1 , $testSubId2 )
90
+ $queryResultTenant = Search-AzGraph $query
91
+ $queryResultOneSub = Search-AzGraph $query - Subscription $testSubId
92
+ $queryResultMultipleSubs = Search-AzGraph $query - Subscription @ ($testSubId , $nonExsitentTestSubId )
94
93
95
- Assert-IsInstance $queryResultNoSubs System.Management.Automation.PSCustomObject
96
- Assert-AreEqual $queryResultNoSubs .subscriptionId $mockedSubscriptionId
94
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResultTenant
95
+ Assert-AreEqual $testSubId $queryResultTenant .subscriptionId
97
96
98
- Assert-IsInstance $queryResultOneSub System.Management.Automation.PSCustomObject
99
- Assert-AreEqual $queryResultOneSub.subscriptionId $testSubId1
97
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResultOneSub
98
+ Assert-AreEqual $testSubId $queryResultOneSub.subscriptionId
99
+
100
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResultMultipleSubs
101
+ Assert-AreEqual $testSubId $queryResultMultipleSubs.subscriptionId
102
+ }
103
+
104
+ <#
105
+ . SYNOPSIS
106
+ Run query with management groups explicitly passed
107
+ #>
108
+ function Search-AzureRmGraph-ManagementGroups
109
+ {
110
+ $testSubId = " eaab1166-1e13-4370-a951-6ed345a48c15"
111
+ $testMgId1 = " f686d426-8d16-42db-81b7-ab578e110ccd"
112
+ $testMgId2 = " makharchMg"
113
+ $nonExistentTestMgId = " nonExistentMg"
114
+ $query = " distinct subscriptionId | order by subscriptionId asc"
115
+
116
+ $queryResultTenant = Search-AzGraph $query
117
+ $queryResultOneMg = Search-AzGraph $query - ManagementGroup $testMgId1
118
+ $queryResultMultipleMgs = Search-AzGraph $query - ManagementGroup @ ($testMgId1 , $testMgId2 , $nonExistentTestMgId ) - AllowPartialScope
119
+
120
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResultTenant
121
+ Assert-AreEqual $testSubId $queryResultTenant.subscriptionId
100
122
101
- Assert-IsInstance $queryResultMultipleSubs Object[]
102
- Assert-AreEqual $queryResultMultipleSubs.Count 2
103
- Assert-AreEqual $queryResultMultipleSubs [0 ].subscriptionId $testSubId1
104
- Assert-AreEqual $queryResultMultipleSubs [1 ].subscriptionId $testSubId2
123
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResultOneMg
124
+ Assert-AreEqual $testSubId $queryResultOneMg.subscriptionId
125
+
126
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResultMultipleMgs
127
+ Assert-AreEqual $testSubId $queryResultMultipleMgs.subscriptionId
105
128
}
106
129
107
130
<#
108
131
. SYNOPSIS
109
- Run query with subscriptions explicitly passed
132
+ Run simple query with the skip token
110
133
#>
111
- function Search-AzureRmGraph-IncludeSubscriptionNames
134
+ function Search-AzureRmGraph-SkipTokenQuery
112
135
{
113
- $mockedScopeId = " 00000000-0000-0000-0000-000000000000"
114
- $mockedSubscriptionName = " Test Subscription"
115
- $mockedTenantName = " Test Tenant"
116
- $query = " project subscriptionId, tenantId, subscriptionDisplayName, tenantDisplayName"
117
-
118
- $queryResult = Search-AzGraph $query - Include " DisplayNames"
119
-
120
- Assert-IsInstance $queryResult System.Management.Automation.PSCustomObject
121
- Assert-AreEqual $queryResult.subscriptionId $mockedScopeId
122
- Assert-AreEqual $queryResult.tenantId $mockedScopeId
123
- Assert-AreEqual $queryResult.subscriptionDisplayName $mockedSubscriptionName
124
- Assert-AreEqual $queryResult.tenantDisplayName $mockedTenantName
136
+ $queryResult = Search-AzGraph " project id, properties" - SkipToken " ew0KICAiJGlkIjogIjEiLA0KICAiTWF4Um93cyI6IDMsDQogICJSb3dzVG9Ta2lwIjogNiwNCiAgIkt1c3RvQ2x1c3RlclVybCI6ICJodHRwczovL2FybXRvcG9sb2d5Lmt1c3RvLndpbmRvd3MubmV0Ig0KfQ=="
137
+
138
+ Assert-IsInstance Object[] $queryResult
139
+ Assert-AreEqual 3 $queryResult.Count
140
+
141
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [0 ]
142
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [1 ]
143
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [2 ]
144
+
145
+ Assert-IsInstance String $queryResult [0 ].id
146
+ Assert-IsInstance String $queryResult [1 ].id
147
+ Assert-IsInstance String $queryResult [2 ].id
148
+ Assert-IsInstance String $queryResult [0 ].ResourceId
149
+ Assert-IsInstance String $queryResult [1 ].ResourceId
150
+ Assert-IsInstance String $queryResult [2 ].ResourceId
151
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [0 ].properties
152
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [1 ].properties
153
+ Assert-IsInstance System.Management.Automation.PSCustomObject $queryResult [2 ].properties
154
+
155
+ Assert-AreEqual $queryResult [0 ].id $queryResult [0 ].ResourceId
156
+ Assert-AreEqual $queryResult [1 ].id $queryResult [1 ].ResourceId
157
+ Assert-AreEqual $queryResult [2 ].id $queryResult [2 ].ResourceId
125
158
}
126
159
127
160
<#
@@ -130,23 +163,30 @@ Run malformed query
130
163
#>
131
164
function Search-AzureRmGraph-QueryError
132
165
{
133
- $expectedErrorId = ' InvalidQuery ,' + [Microsoft.Azure.Commands.ResourceGraph.Cmdlets.SearchAzureRmGraph ].FullName
134
- $expectedErrorDetails = ' {
166
+ $expectedErrorId = ' BadRequest ,' + [Microsoft.Azure.Commands.ResourceGraph.Cmdlets.SearchAzureRmGraph ].FullName
167
+ $expectedErrorDetailsRegex = [ regex ]::escape( ' {
135
168
"error": {
136
- "code": "InvalidQuery ",
137
- "message": "Query validation error ",
169
+ "code": "BadRequest ",
170
+ "message": "Please provide below info when asking for support: timestamp = 2021-03-25T ' ) + ' .{17}? ' + [ regex ]::escape( ' , correlationId = ' ) + ' .{36}? ' + [ regex ]::escape( ' . ",
138
171
"details": [
172
+ {
173
+ "code": "InvalidQuery",
174
+ "message": "Query is invalid. Please refer to the documentation for the Azure Resource Graph service and fix the error before retrying."
175
+ },
139
176
{
140
177
"code": "ParserFailure",
141
- "message": "Parser failure ",
178
+ "message": "ParserFailure ",
142
179
"line": 1,
143
180
"characterPositionInLine": 11,
144
181
"token": "<EOF>",
145
- "expectedToken": "Ÿ "
182
+ "expectedToken": "Ǐ "
146
183
}
147
184
]
148
185
}
149
- }'
186
+ }' )
187
+
188
+ $expectedInnerCode = " InvalidQuery"
189
+ $expectedInnerMessage = " Query is invalid. Please refer to the documentation for the Azure Resource Graph service and fix the error before retrying."
150
190
151
191
try
152
192
{
@@ -155,43 +195,45 @@ function Search-AzureRmGraph-QueryError
155
195
}
156
196
catch [Exception ]
157
197
{
158
- Assert-AreEqual $PSItem.FullyQualifiedErrorId $expectedErrorId
159
- Assert-AreEqual $ PSItem.ErrorDetails.Message $expectedErrorDetails
160
- Assert-IsInstance $PSItem .Exception Microsoft.Azure.Management.ResourceGraph.Models.ErrorResponseException
161
- Assert-IsInstance $PSItem .Exception.Body Microsoft.Azure.Management.ResourceGraph.Models.ErrorResponse
198
+ Assert-AreEqual $expectedErrorId $ PSItem.FullyQualifiedErrorId
199
+ Assert-Match $expectedErrorDetailsRegex $ PSItem.ErrorDetails.Message
200
+ Assert-IsInstance Microsoft.Azure.Management.ResourceGraph.Models.ErrorResponseException $PSItem .Exception
201
+ Assert-IsInstance Microsoft.Azure.Management.ResourceGraph.Models.ErrorResponse $PSItem .Exception.Body
162
202
163
203
Assert-NotNull $PSItem.Exception.Body.Error.Code
164
204
Assert-NotNull $PSItem.Exception.Body.Error.Message
165
205
Assert-NotNull $PSItem.Exception.Body.Error.Details
166
- Assert-AreEqual $PSItem.Exception.Body.Error.Details.Count 1
206
+ Assert-AreEqual 2 $PSItem.Exception.Body.Error.Details.Count
207
+
208
+ Assert-AreEqual $expectedInnerCode $PSItem.Exception.Body.Error.Details [0 ].Code
209
+ Assert-AreEqual $expectedInnerMessage $PSItem.Exception.Body.Error.Details [0 ].Message
167
210
168
- Assert-NotNull $PSItem.Exception.Body.Error.Details [0 ].Code
169
- Assert-NotNull $PSItem.Exception.Body.Error.Details [0 ].Message
170
- Assert-NotNull $PSItem.Exception.Body.Error.Details [0 ].AdditionalProperties
171
- Assert-AreEqual $PSItem.Exception.Body.Error.Details [0 ].AdditionalProperties.Count 4
211
+ Assert-NotNull $PSItem.Exception.Body.Error.Details [1 ].Code
212
+ Assert-NotNull $PSItem.Exception.Body.Error.Details [1 ].Message
213
+ Assert-NotNull $PSItem.Exception.Body.Error.Details [1 ].AdditionalProperties
214
+ Assert-AreEqual 4 $PSItem.Exception.Body.Error.Details [1 ].AdditionalProperties.Count
172
215
}
173
216
}
174
217
175
218
<#
176
219
. SYNOPSIS
177
- Run query with no subscriptions
220
+ Run query with both subscriptions and management groups present
178
221
#>
179
- function Search-AzureRmGraph-SubscriptionQueryError
222
+ function Search-AzureRmGraph-SubscriptionAndManagementGroupQueryError
180
223
{
181
- $expectedErrorId = ' 400 ,' + [Microsoft.Azure.Commands.ResourceGraph.Cmdlets.SearchAzureRmGraph ].FullName
224
+ $expectedErrorId = ' AmbiguousParameterSet ,' + [Microsoft.Azure.Commands.ResourceGraph.Cmdlets.SearchAzureRmGraph ].FullName
182
225
$expectedErrorMessage =
183
- ' No subscriptions were found to run query. Please try to add them implicitly as param to your request (e.g. Search-AzGraph -Query '''' -Subscription '' 11111111-1111-1111-1111-111111111111 '' ) '
226
+ ' Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided. '
184
227
185
228
try
186
229
{
187
- Search-AzGraph " project id, type" - Subscription @ ()
230
+ Search-AzGraph " project id, type" - Subscription ' a ' - ManagementGroup ' b '
188
231
Assert-True $false # Expecting an error
189
232
}
190
233
catch [Exception ]
191
234
{
192
- Assert-AreEqual $expectedErrorId $PSItem.FullyQualifiedErrorId
235
+ Assert-AreEqual $expectedErrorId $PSItem.FullyQualifiedErrorId
193
236
Assert-AreEqual $expectedErrorMessage $PSItem.Exception.Message
194
-
195
- Assert-IsInstance $PSItem.Exception System.ArgumentException
237
+ Assert-IsInstance System.Management.Automation.ParameterBindingException $PSItem.Exception
196
238
}
197
- }
239
+ }
0 commit comments