-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathResourceLockTests.ps1
78 lines (64 loc) · 2.94 KB
/
ResourceLockTests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------
<#
.SYNOPSIS
Tests resource lock CRUD operations.
#>
function Test-ResourceLockCRUD
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = Get-Location "Microsoft.Resources" "resourceGroups" "West US"
$apiversion = "2014-04-01"
$rg = New-AzureRMResourceGroup -Name $rgname -Location $rglocation
$actual = New-AzureRMResourceLock -LockName $rname -LockLevel CanNotDelete -Force -Scope $rg.ResourceId
$expected = Get-AzureRMResourceLock -LockName $rname -Scope $rg.ResourceId
# Assert
Assert-AreEqual $expected.Name $actual.Name
Assert-AreEqual $expected.ResourceId $actual.ResourceId
Assert-AreEqual $expected.ResourceName $actual.ResourceName
Assert-AreEqual $expected.ResourceType $actual.ResourceType
Assert-AreEqual $expected.LockId $actual.LockId
$expectedSet = Set-AzureRMResourceLock -LockId $expected.LockId -LockLevel CanNotDelete -LockNotes test -Force
Assert-AreEqual $expectedSet.Properties.Notes "test"
$removed = Remove-AzureRMResourceLock -LockId $expectedSet.LockId -Force
Assert-AreEqual True $removed
$actual = New-AzureRMResourceLock -LockName $rname -LockLevel CanNotDelete -Force -Scope $rg.ResourceId
$removed = Remove-AzureRMResourceLock -ResourceId $actual.ResourceId -Force
Assert-AreEqual True $removed
#ReadOnly lock
$actual = New-AzureRMResourceLock -LockName $rname -LockLevel ReadOnly -Force -Scope $rg.ResourceId
Assert-AreEqual $expected.Name $actual.Name
$expected = Get-AzureRMResourceLock -LockName $rname -Scope $rg.ResourceId
Assert-AreEqual $expected.Properties.Level "ReadOnly"
$removed = Remove-AzureRMResourceLock -ResourceId $actual.ResourceId -Force
Assert-AreEqual True $removed
}
<#
.SYNOPSIS
Tests resource lock which does not exist.
#>
function Test-ResourceLockNonExisting
{
# Setup
$rgname = Get-ResourceGroupName
$rglocation = Get-Location "Microsoft.Resources" "resourceGroups" "West US"
$rg = New-AzureRMResourceGroup -Name $rgname -Location $rglocation
Assert-AreEqual $rgname $rg.ResourceGroupName
$lock = Get-AzureRMResourceLock -LockName "NonExisting" -Scope $rg.ResourceId -ErrorAction SilentlyContinue
Assert-True { $Error[0] -like "*LockNotFound : The lock 'NonExisting' could not be found." }
Assert-Null $lock
$Error.Clear()
}