Skip to content

Commit 6e22ce1

Browse files
BenDavMSbganapa
authored andcommitted
fix tests for recording and add recordings
1 parent bc3f7cf commit 6e22ce1

12 files changed

+6474
-579
lines changed

src/Azs.InfrastructureInsights.Admin/test/Close-AzsAlert.Tests.ps1

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@ while(-not $mockingPath) {
1111
}
1212
. ($mockingPath | Select-Object -First 1).FullName
1313

14-
InModuleScope Azs.InfrastructureInsights.Admin {
1514

16-
Describe "Alerts" -Tags @('Alert', 'InfrastructureInsightsAdmin') {
15+
Describe "Alerts" -Tags @('Alert', 'InfrastructureInsightsAdmin') {
1716

18-
it "TestCloseAlert" -Skip:$('TestCloseAlert' -in $global:SkippedTests) {
17+
. $PSScriptRoot\Common.ps1
1918

20-
$global:TestName = 'TestCloseAlert'
19+
it "TestCloseAlert" -Skip:$('TestCloseAlert' -in $global:SkippedTests) {
2120

22-
$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $global:location
21+
$global:TestName = 'TestCloseAlert'
2322

24-
$Alerts | Should Not Be $null
23+
$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $global:location
2524

26-
foreach ($Alert in $Alerts) {
25+
$Alerts | Should Not Be $null
26+
27+
foreach ($Alert in $Alerts) {
2728

28-
$Alert | Should not be $null
29-
$Alert.State | Should not be $null
29+
$Alert | Should not be $null
30+
$Alert.State | Should not be $null
3031

31-
if ($Alert.State -eq "Active") {
32+
if ($Alert.State -eq "Active") {
3233

33-
$Alert | Close-AzsAlert -Location $global:location -User "foobar"
34+
$Alert | Close-AzsAlert -Location $global:location -User "foobar"
3435

35-
return
36-
}
36+
return
3737
}
38-
}
39-
}
40-
}
38+
}
39+
}
40+
}

src/Azs.InfrastructureInsights.Admin/test/Get-AzsAlert.Recording.json

Lines changed: 2322 additions & 0 deletions
Large diffs are not rendered by default.

src/Azs.InfrastructureInsights.Admin/test/Get-AzsAlert.Tests.ps1

Lines changed: 36 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -12,220 +12,73 @@ while(-not $mockingPath) {
1212
}
1313
. ($mockingPath | Select-Object -First 1).FullName
1414

15-
InModuleScope Azs.InfrastructureInsights.Admin {
15+
Describe "Alerts" -Tags @('Alert', 'InfrastructureInsightsAdmin') {
1616

17-
Describe "Alerts" -Tags @('Alert', 'InfrastructureInsightsAdmin') {
17+
. $PSScriptRoot\Common.ps1
1818

19-
BeforeEach {
19+
it "TestListAlerts" -Skip:$('TestListAlerts' -in $global:SkippedTests) {
2020

21-
function ValidateAlert {
21+
$global:TestName = 'TestListAlerts'
2222

23-
param(
23+
$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $global:Location
2424

25-
[Parameter(Mandatory = $true)]
26-
27-
$Alert
28-
29-
)
30-
31-
$Alert | Should Not Be $null
32-
33-
# Resource
34-
$Alert.Id | Should Not Be $null
35-
$Alert.Location | Should Not Be $null
36-
$Alert.Name | Should Not Be $null
37-
$Alert.Type | Should Not Be $null
38-
39-
# Alert
40-
$Alert.AlertId | Should Not Be $null
41-
$Alert.AlertProperty | Should Not Be $null
42-
$Alert.CreatedTimestamp | Should Not Be $null
43-
$Alert.Description | Should Not Be $null
44-
$Alert.FaultTypeId | Should Not Be $null
45-
$Alert.ImpactedResourceDisplayName | Should Not Be $null
46-
$Alert.ImpactedResourceId | Should Not Be $null
47-
$Alert.LastUpdatedTimestamp | Should Not Be $null
48-
$Alert.Remediation | Should Not Be $null
49-
$Alert.ResourceProviderRegistrationId | Should Not Be $null
50-
$Alert.Severity | Should Not Be $null
51-
$Alert.State | Should Not Be $null
52-
$Alert.Title | Should Not Be $null
53-
}
54-
55-
function AssertAlertsAreSame {
56-
param(
57-
[Parameter(Mandatory = $true)]
58-
$Expected,
59-
60-
[Parameter(Mandatory = $true)]
61-
$Found
62-
)
63-
64-
if ($Expected -eq $null) {
65-
$Found | Should Be $null
66-
}
67-
else {
68-
$Found | Should Not Be $null
69-
70-
# Resource
71-
$Found.Id | Should Be $Expected.Id
72-
$Found.Location | Should Be $Expected.Location
73-
$Found.Name | Should Be $Expected.Name
74-
$Found.Type | Should Be $Expected.Type
75-
76-
# Alert
77-
$Found.AlertId | Should Be $Expected.AlertId
78-
79-
if ($Expected.AlertProperties -eq $null) {
80-
81-
$Found.AlertProperties | Should Be $null
82-
83-
}
84-
85-
else {
86-
87-
$Found.AlertProperties | Should Not Be $null
88-
89-
$Found.AlertProperties.Count | Should Be $Expected.AlertProperties.Count
90-
91-
}
92-
93-
94-
95-
$Found.ClosedByUserAlias | Should Be $Expected.ClosedByUserAlias
96-
97-
$Found.ClosedTimestamp | Should Be $Expected.ClosedTimestamp
98-
99-
$Found.CreatedTimestamp | Should Be $Expected.CreatedTimestamp
100-
101-
102-
103-
if ($Expected.Description -eq $null) {
104-
105-
$Found.Description | Should Be $null
106-
107-
}
108-
109-
else {
110-
111-
$Found.Description | Should Not Be $null
112-
113-
$Found.Description.Count | Should Be $Expected.Description.Count
114-
115-
}
116-
117-
118-
119-
$Found.FaultId | Should Be $Expected.FaultId
120-
121-
$Found.FaultTypeId | Should Be $Expected.FaultTypeId
122-
123-
$Found.ImpactedResourceDisplayName | Should Be $Expected.ImpactedResourceDisplayName
124-
125-
$Found.ImpactedResourceId | Should Be $Expected.ImpactedResourceId
126-
127-
$Found.LastUpdatedTimestamp | Should Be $Expected.LastUpdatedTimestamp
128-
129-
130-
131-
if ($Expected.Remediation -eq $null) {
132-
133-
$Found.Remediation | Should Be $null
134-
135-
}
136-
137-
else {
138-
139-
$Found.Remediation | Should Not Be $null
140-
141-
$Found.Remediation.Count | Should Be $Expected.Remediation.Count
142-
143-
}
144-
145-
146-
147-
$Found.ResourceProviderRegistrationId | Should Be $Expected.ResourceProviderRegistrationId
148-
149-
$Found.ResourceRegistrationId | Should Be $Expected.ResourceRegistrationId
150-
151-
$Found.Severity | Should Be $Expected.Severity
152-
153-
$Found.State | Should Be $Expected.State
154-
155-
$Found.Title | Should Be $Expected.Title
156-
157-
158-
159-
}
160-
161-
}
162-
163-
}
164-
165-
it "TestListAlerts" -Skip:$('TestListAlerts' -in $global:SkippedTests) {
166-
167-
$global:TestName = 'TestListAlerts'
168-
169-
$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $global:Location
170-
171-
foreach ($Alert in $Alerts) {
172-
ValidateAlert -Alert $Alert
173-
}
25+
foreach ($Alert in $Alerts) {
26+
ValidateAlert -Alert $Alert
17427
}
28+
}
17529

176-
it "TestGetAlert" -Skip:$('TestGetAlert' -in $global:SkippedTests) {
30+
it "TestGetAlert" -Skip:$('TestGetAlert' -in $global:SkippedTests) {
17731

178-
$global:TestName = 'TestGetAlert'
32+
$global:TestName = 'TestGetAlert'
17933

180-
$Regions = Get-AzsRegionHealth -ResourceGroupName $global:ResourceGroupName -Location $global:Location
34+
$Regions = Get-AzsRegionHealth -ResourceGroupName $global:ResourceGroupName -Location $global:Location
18135

182-
foreach ($Region in $Regions) {
36+
foreach ($Region in $Regions) {
18337

184-
$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $Region.Name
38+
$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $Region.Name
18539

186-
foreach ($Alert in $Alerts) {
40+
foreach ($Alert in $Alerts) {
18741

188-
$retrieved = Get-AzsAlert -Location $Region.Name -Name $Alert.AlertId
189-
AssertAlertsAreSame -Expected $Alert -Found $retrieved
190-
return
191-
}
42+
$retrieved = Get-AzsAlert -Location $Region.Name -Name $Alert.AlertId
43+
AssertAlertsAreSame -Expected $Alert -Found $retrieved
44+
return
19245
}
19346
}
47+
}
19448

195-
it "TestGetAllAlerts" -Skip:$('TestGetAllAlerts' -in $global:SkippedTests) {
49+
it "TestGetAllAlerts" -Skip:$('TestGetAllAlerts' -in $global:SkippedTests) {
19650

197-
$global:TestName = 'TestGetAllAlerts'
51+
$global:TestName = 'TestGetAllAlerts'
19852

199-
$Regions = Get-AzsRegionHealth -ResourceGroupName $global:ResourceGroupName -Location $global:Location
53+
$Regions = Get-AzsRegionHealth -ResourceGroupName $global:ResourceGroupName -Location $global:Location
20054

201-
foreach ($Region in $Regions) {
55+
foreach ($Region in $Regions) {
20256

203-
$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $Region.Name
57+
$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $Region.Name
20458

205-
foreach ($Alert in $Alerts) {
206-
$retrieved = Get-AzsAlert -Location $Region.Name -Name $Alert.AlertId
59+
foreach ($Alert in $Alerts) {
60+
$retrieved = Get-AzsAlert -Location $Region.Name -Name $Alert.AlertId
20761

208-
AssertAlertsAreSame -Expected $Alert -Found $retrieved
209-
}
62+
AssertAlertsAreSame -Expected $Alert -Found $retrieved
21063
}
21164
}
65+
}
21266

213-
it "TestGetAllAlerts" -Skip:$('TestGetAllAlerts' -in $global:SkippedTests) {
67+
it "TestGetAllAlerts" -Skip:$('TestGetAllAlerts' -in $global:SkippedTests) {
21468

215-
$global:TestName = 'TestGetAllAlerts'
69+
$global:TestName = 'TestGetAllAlerts'
21670

217-
$Regions = Get-AzsRegionHealth -ResourceGroupName $global:ResourceGroupName -Location $global:Location
71+
$Regions = Get-AzsRegionHealth -ResourceGroupName $global:ResourceGroupName -Location $global:Location
21872

219-
foreach ($Region in $Regions) {
73+
foreach ($Region in $Regions) {
22074

221-
$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $Region.Name
75+
$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $Region.Name
22276

223-
foreach ($Alert in $Alerts) {
224-
$retrieved = $Alert | Get-AzsAlert
225-
AssertAlertsAreSame -Expected $Alert -Found $retrieved
77+
foreach ($Alert in $Alerts) {
78+
$retrieved = $Alert | Get-AzsAlert
79+
AssertAlertsAreSame -Expected $Alert -Found $retrieved
22680

227-
}
22881
}
22982
}
23083
}
231-
}
84+
}

0 commit comments

Comments
 (0)