Skip to content

Commit c0dc48c

Browse files
authored
Merge pull request #6829 from cormacpayne/resources-test
Fix Resources tests that used static queue by adding id property
2 parents b2a1f92 + d758d1a commit c0dc48c

File tree

11 files changed

+344
-168
lines changed

11 files changed

+344
-168
lines changed

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/AzureRM.Resources.ps1

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function New-AzureRmResourceGroupDeployment
9696
END {}
9797
}
9898

99-
function Remove-AzureRmResourceGroup
99+
function Remove-AzureRmResourceGroup
100100
{
101101
[CmdletBinding()]
102102
param(
@@ -113,6 +113,124 @@ function Remove-AzureRmResourceGroup
113113
END {}
114114
}
115115

116+
function New-AzureRmRoleAssignmentWithId
117+
{
118+
[CmdletBinding()]
119+
param(
120+
[Guid] [Parameter()] [alias("Id", "PrincipalId")] $ObjectId,
121+
[string] [Parameter()] [alias("Email", "UserPrincipalName")] $SignInName,
122+
[string] [Parameter()] [alias("SPN", "ServicePrincipalName")] $ApplicationId,
123+
[string] [Parameter()] $ResourceGroupName,
124+
[string] [Parameter()] $ResourceName,
125+
[string] [Parameter()] $ResourceType,
126+
[string] [Parameter()] $ParentResource,
127+
[string] [Parameter()] $Scope,
128+
[string] [Parameter()] $RoleDefinitionName,
129+
[Guid] [Parameter()] $RoleDefinitionId,
130+
[switch] [Parameter()] $AllowDelegation,
131+
[Guid] [Parameter()] $RoleAssignmentId
132+
)
133+
134+
$profile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
135+
$cmdlet = New-Object -TypeName Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand
136+
$cmdlet.DefaultProfile = $profile
137+
$cmdlet.CommandRuntime = $PSCmdlet.CommandRuntime
138+
139+
if ($ObjectId -ne $null -and $ObjectId -ne [System.Guid]::Empty)
140+
{
141+
$cmdlet.ObjectId = $ObjectId
142+
}
143+
144+
if (-not ([string]::IsNullOrEmpty($SignInName)))
145+
{
146+
$cmdlet.SignInName = $SignInName
147+
}
148+
149+
if (-not ([string]::IsNullOrEmpty($ApplicationId)))
150+
{
151+
$cmdlet.ApplicationId = $ApplicationId
152+
}
153+
154+
if (-not ([string]::IsNullOrEmpty($ResourceGroupName)))
155+
{
156+
$cmdlet.ResourceGroupName = $ResourceGroupName
157+
}
158+
159+
if (-not ([string]::IsNullOrEmpty($ResourceName)))
160+
{
161+
$cmdlet.ResourceName = $ResourceName
162+
}
163+
164+
if (-not ([string]::IsNullOrEmpty($ResourceType)))
165+
{
166+
$cmdlet.ResourceType = $ResourceType
167+
}
168+
169+
if (-not ([string]::IsNullOrEmpty($ParentResource)))
170+
{
171+
$cmdlet.ParentResource = $ParentResource
172+
}
173+
174+
if (-not ([string]::IsNullOrEmpty($Scope)))
175+
{
176+
$cmdlet.Scope = $Scope
177+
}
178+
179+
if (-not ([string]::IsNullOrEmpty($RoleDefinitionName)))
180+
{
181+
$cmdlet.RoleDefinitionName = $RoleDefinitionName
182+
}
183+
184+
if ($RoleDefinitionId -ne $null -and $RoleDefinitionId -ne [System.Guid]::Empty)
185+
{
186+
$cmdlet.RoleDefinitionId = $RoleDefinitionId
187+
}
188+
189+
if ($AllowDelegation.IsPresent)
190+
{
191+
$cmdlet.AllowDelegation = $true
192+
}
193+
194+
if ($RoleAssignmentId -ne $null -and $RoleAssignmentId -ne [System.Guid]::Empty)
195+
{
196+
$cmdlet.RoleAssignmentId = $RoleAssignmentId
197+
}
198+
199+
$cmdlet.ExecuteCmdlet()
200+
}
201+
202+
function New-AzureRmRoleDefinitionWithId
203+
{
204+
[CmdletBinding()]
205+
param(
206+
[Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleDefinition] [Parameter()] $Role,
207+
[string] [Parameter()] $InputFile,
208+
[Guid] [Parameter()] $RoleDefinitionId
209+
)
210+
211+
$profile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
212+
$cmdlet = New-Object -TypeName Microsoft.Azure.Commands.Resources.NewAzureRoleDefinitionCommand
213+
$cmdlet.DefaultProfile = $profile
214+
$cmdlet.CommandRuntime = $PSCmdlet.CommandRuntime
215+
216+
if (-not ([string]::IsNullOrEmpty($InputFile)))
217+
{
218+
$cmdlet.InputFile = $InputFile
219+
}
220+
221+
if ($Role -ne $null)
222+
{
223+
$cmdlet.Role = $Role
224+
}
225+
226+
if ($RoleDefinitionId -ne $null -and $RoleDefinitionId -ne [System.Guid]::Empty)
227+
{
228+
$cmdlet.RoleDefinitionId = $RoleDefinitionId
229+
}
230+
231+
$cmdlet.ExecuteCmdlet()
232+
}
233+
116234
function Get-Context
117235
{
118236
return [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext
@@ -122,7 +240,7 @@ function Get-ResourcesClient
122240
{
123241
param([Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContext] $context)
124242
$factory = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.ClientFactory
125-
[System.Type[]]$types = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContext],
243+
[System.Type[]]$types = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContext],
126244
[string]
127245
$method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory].GetMethod("CreateArmClient", $types)
128246
$closedMethod = $method.MakeGenericMethod([Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient])

src/ResourceManager/DataFactoryV2/Commands.DataFactoryV2.Test/ScenarioTests/DataFactoriesScenarioTestsBase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ protected void SetupManagementClients(MockContext context)
5656
subscriptionsClient,
5757
graphClient,
5858
authorizationManagementClient);
59-
60-
AuthorizationClient.RoleAssignmentNames.Enqueue(new Guid("6558f9a7-689c-41d3-93bd-3281fbe3d26f"));
6159
}
6260

6361
protected void RunPowerShellTest(XunitTracingInterceptor logger, params string[] scripts)

src/ResourceManager/DataFactoryV2/Commands.DataFactoryV2.Test/ScenarioTests/IntegrationRuntimeTests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ function Test-SsisAzure-IntegrationRuntime
122122
}
123123

124124
if ($catalogAdminPassword -eq $null){
125+
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Fake password to resource that has been deleted.")]#>
125126
$catalogAdminPassword = 'fakepassord'
126127
}
127128

@@ -285,10 +286,11 @@ function Test-Shared-IntegrationRuntime
285286
-Type 'SelfHosted' `
286287
-Force
287288

288-
New-AzureRMRoleAssignment `
289+
New-AzureRMRoleAssignmentWithId `
289290
-ObjectId $linkeddf.Identity.PrincipalId `
290291
-RoleDefinitionId 'b24988ac-6180-42a0-ab88-20f7382dd24c' `
291-
-Scope $shared.Id
292+
-Scope $shared.Id `
293+
-RoleAssignmentId 6558f9a7-689c-41d3-93bd-3281fbe3d26f
292294

293295
Wait-Seconds 20
294296

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/Common.ps1

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,122 @@ function Clean-ResourceGroup($rgname)
6060
-or [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback) {
6161
Remove-AzureRmResourceGroup -Name $rgname -Force
6262
}
63+
}
64+
65+
function New-AzureRmRoleAssignmentWithId
66+
{
67+
[CmdletBinding()]
68+
param(
69+
[Guid] [Parameter()] [alias("Id", "PrincipalId")] $ObjectId,
70+
[string] [Parameter()] [alias("Email", "UserPrincipalName")] $SignInName,
71+
[string] [Parameter()] [alias("SPN", "ServicePrincipalName")] $ApplicationId,
72+
[string] [Parameter()] $ResourceGroupName,
73+
[string] [Parameter()] $ResourceName,
74+
[string] [Parameter()] $ResourceType,
75+
[string] [Parameter()] $ParentResource,
76+
[string] [Parameter()] $Scope,
77+
[string] [Parameter()] $RoleDefinitionName,
78+
[Guid] [Parameter()] $RoleDefinitionId,
79+
[switch] [Parameter()] $AllowDelegation,
80+
[Guid] [Parameter()] $RoleAssignmentId
81+
)
82+
83+
$profile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
84+
$cmdlet = New-Object -TypeName Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand
85+
$cmdlet.DefaultProfile = $profile
86+
$cmdlet.CommandRuntime = $PSCmdlet.CommandRuntime
87+
88+
if ($ObjectId -ne $null -and $ObjectId -ne [System.Guid]::Empty)
89+
{
90+
$cmdlet.ObjectId = $ObjectId
91+
}
92+
93+
if (-not ([string]::IsNullOrEmpty($SignInName)))
94+
{
95+
$cmdlet.SignInName = $SignInName
96+
}
97+
98+
if (-not ([string]::IsNullOrEmpty($ApplicationId)))
99+
{
100+
$cmdlet.ApplicationId = $ApplicationId
101+
}
102+
103+
if (-not ([string]::IsNullOrEmpty($ResourceGroupName)))
104+
{
105+
$cmdlet.ResourceGroupName = $ResourceGroupName
106+
}
107+
108+
if (-not ([string]::IsNullOrEmpty($ResourceName)))
109+
{
110+
$cmdlet.ResourceName = $ResourceName
111+
}
112+
113+
if (-not ([string]::IsNullOrEmpty($ResourceType)))
114+
{
115+
$cmdlet.ResourceType = $ResourceType
116+
}
117+
118+
if (-not ([string]::IsNullOrEmpty($ParentResource)))
119+
{
120+
$cmdlet.ParentResource = $ParentResource
121+
}
122+
123+
if (-not ([string]::IsNullOrEmpty($Scope)))
124+
{
125+
$cmdlet.Scope = $Scope
126+
}
127+
128+
if (-not ([string]::IsNullOrEmpty($RoleDefinitionName)))
129+
{
130+
$cmdlet.RoleDefinitionName = $RoleDefinitionName
131+
}
132+
133+
if ($RoleDefinitionId -ne $null -and $RoleDefinitionId -ne [System.Guid]::Empty)
134+
{
135+
$cmdlet.RoleDefinitionId = $RoleDefinitionId
136+
}
137+
138+
if ($AllowDelegation.IsPresent)
139+
{
140+
$cmdlet.AllowDelegation = $true
141+
}
142+
143+
if ($RoleAssignmentId -ne $null -and $RoleAssignmentId -ne [System.Guid]::Empty)
144+
{
145+
$cmdlet.RoleAssignmentId = $RoleAssignmentId
146+
}
147+
148+
$cmdlet.ExecuteCmdlet()
149+
}
150+
151+
function New-AzureRmRoleDefinitionWithId
152+
{
153+
[CmdletBinding()]
154+
param(
155+
[Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleDefinition] [Parameter()] $Role,
156+
[string] [Parameter()] $InputFile,
157+
[Guid] [Parameter()] $RoleDefinitionId
158+
)
159+
160+
$profile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
161+
$cmdlet = New-Object -TypeName Microsoft.Azure.Commands.Resources.NewAzureRoleDefinitionCommand
162+
$cmdlet.DefaultProfile = $profile
163+
$cmdlet.CommandRuntime = $PSCmdlet.CommandRuntime
164+
165+
if (-not ([string]::IsNullOrEmpty($InputFile)))
166+
{
167+
$cmdlet.InputFile = $InputFile
168+
}
169+
170+
if ($Role -ne $null)
171+
{
172+
$cmdlet.Role = $Role
173+
}
174+
175+
if ($RoleDefinitionId -ne $null -and $RoleDefinitionId -ne [System.Guid]::Empty)
176+
{
177+
$cmdlet.RoleDefinitionId = $RoleDefinitionId
178+
}
179+
180+
$cmdlet.ExecuteCmdlet()
63181
}

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/RoleAssignmentTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,8 @@ public void RaDeletedPrincipals()
5454
ResourcesController.NewInstance.RunPsTest(_logger, "Test-RaDeletedPrincipals");
5555
}
5656

57-
#if NETSTANDARD
58-
[Fact(Skip = "DisableTestParallelization disabled on .NET Core: Test uses RoleDefinitionNames")]
59-
[Trait(Category.RunType, Category.DesktopOnly)]
60-
#else
6157
[Fact]
62-
#endif
63-
[Trait(Category.AcceptanceType, Category.Flaky)]
58+
[Trait(Category.AcceptanceType, Category.CheckIn)]
6459
public void RaPropertiesValidation() {
6560
ResourcesController.NewInstance.RunPsTest(_logger, "Test-RaPropertiesValidation");
6661
}

0 commit comments

Comments
 (0)