Skip to content

Commit 22cff07

Browse files
committed
update test
1 parent e0fbf5a commit 22cff07

File tree

2 files changed

+424
-408
lines changed

2 files changed

+424
-408
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,21 +386,25 @@ Tests verifies creation and validation of RoleAssignment properties for not null
386386
function Test-RaPropertiesValidation
387387
{
388388
# Setup
389-
$definitionName = 'CustomRole Tests Role'
390-
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleDefinitionNames.Enqueue("8D7DD69E-9AE2-44A1-94D8-F7BC8E12645E")
391-
New-AzureRmRoleDefinition -InputFile .\Resources\NewRoleDefinition.json
392389
$users = Get-AzureRmADUser | Select-Object -First 1 -Wait
393390
$subscription = Get-AzureRmSubscription
394-
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 1 -Wait
395391
$scope = '/subscriptions/'+$subscription[0].Id
396-
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."
397-
$rd = Get-AzureRmRoleDefinition -Name $definitionName
392+
$roleDef = Get-AzureRmRoleDefinition -Name "Reader"
393+
$roleDef.Id = $null
394+
$roleDef.Name = "Custom Reader Test"
395+
$roleDef.Actions.Add("Microsoft.ClassicCompute/virtualMachines/restart/action")
396+
$roleDef.Description = "Read, monitor and restart virtual machines"
397+
$roleDef.AssignableScopes[0] = "/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f"
398+
399+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleDefinitionNames.Enqueue("032F61D2-ED09-40C9-8657-26A273DA7BAE")
400+
New-AzureRmRoleDefinition -Role $roleDef
401+
$rd = Get-AzureRmRoleDefinition -Name "Custom Reader Test"
398402

399403
# Test
400404
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("fa1a4d3b-2cca-406b-8956-6b6b32377641")
401405
$newAssignment = New-AzureRmRoleAssignment `
402406
-ObjectId $users[0].Id.Guid `
403-
-RoleDefinitionName $definitionName `
407+
-RoleDefinitionName $roleDef.Name `
404408
-Scope $scope
405409
$newAssignment.Scope = $scope.toUpper()
406410

@@ -418,7 +422,7 @@ function Test-RaPropertiesValidation
418422

419423
# Assert
420424
Assert-NotNull $newAssignment
421-
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
425+
Assert-AreEqual $roleDef.Name $newAssignment.RoleDefinitionName
422426
Assert-AreEqual $scope $newAssignment.Scope
423427
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
424428

0 commit comments

Comments
 (0)