Skip to content

Commit

Permalink
Merge pull request Azure#7 from bganapa/infra-pr
Browse files Browse the repository at this point in the history
add pester tests for InfrastructureInsights.admin
  • Loading branch information
bganapa authored Feb 10, 2020
2 parents f00593a + 6e22ce1 commit 3fa8c50
Show file tree
Hide file tree
Showing 15 changed files with 6,758 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Azs.InfrastructureInsights.Admin/test/Close-AzsAlert.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
if (-Not (Test-Path -Path $loadEnvPath)) {
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
}
. ($loadEnvPath)
$TestRecordingFile = Join-Path $PSScriptRoot 'Close-AzsAlert.Recording.json'
$currentPath = $PSScriptRoot
while(-not $mockingPath) {
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
$currentPath = Split-Path -Path $currentPath -Parent
}
. ($mockingPath | Select-Object -First 1).FullName


Describe "Alerts" -Tags @('Alert', 'InfrastructureInsightsAdmin') {

. $PSScriptRoot\Common.ps1

it "TestCloseAlert" -Skip:$('TestCloseAlert' -in $global:SkippedTests) {

$global:TestName = 'TestCloseAlert'

$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $global:location

$Alerts | Should Not Be $null

foreach ($Alert in $Alerts) {

$Alert | Should not be $null
$Alert.State | Should not be $null

if ($Alert.State -eq "Active") {

$Alert | Close-AzsAlert -Location $global:location -User "foobar"

return
}
}
}
}
2,322 changes: 2,322 additions & 0 deletions src/Azs.InfrastructureInsights.Admin/test/Get-AzsAlert.Recording.json

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions src/Azs.InfrastructureInsights.Admin/test/Get-AzsAlert.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
if (-Not (Test-Path -Path $loadEnvPath)) {
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
}
. ($loadEnvPath)
$TestRecordingFile = Join-Path $PSScriptRoot 'Get-AzsAlert.Recording.json'
$currentPath = $PSScriptRoot

while(-not $mockingPath) {
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
$currentPath = Split-Path -Path $currentPath -Parent
}
. ($mockingPath | Select-Object -First 1).FullName

Describe "Alerts" -Tags @('Alert', 'InfrastructureInsightsAdmin') {

. $PSScriptRoot\Common.ps1

it "TestListAlerts" -Skip:$('TestListAlerts' -in $global:SkippedTests) {

$global:TestName = 'TestListAlerts'

$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $global:Location

foreach ($Alert in $Alerts) {
ValidateAlert -Alert $Alert
}
}

it "TestGetAlert" -Skip:$('TestGetAlert' -in $global:SkippedTests) {

$global:TestName = 'TestGetAlert'

$Regions = Get-AzsRegionHealth -ResourceGroupName $global:ResourceGroupName -Location $global:Location

foreach ($Region in $Regions) {

$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $Region.Name

foreach ($Alert in $Alerts) {

$retrieved = Get-AzsAlert -Location $Region.Name -Name $Alert.AlertId
AssertAlertsAreSame -Expected $Alert -Found $retrieved
return
}
}
}

it "TestGetAllAlerts" -Skip:$('TestGetAllAlerts' -in $global:SkippedTests) {

$global:TestName = 'TestGetAllAlerts'

$Regions = Get-AzsRegionHealth -ResourceGroupName $global:ResourceGroupName -Location $global:Location

foreach ($Region in $Regions) {

$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $Region.Name

foreach ($Alert in $Alerts) {
$retrieved = Get-AzsAlert -Location $Region.Name -Name $Alert.AlertId

AssertAlertsAreSame -Expected $Alert -Found $retrieved
}
}
}

it "TestGetAllAlerts" -Skip:$('TestGetAllAlerts' -in $global:SkippedTests) {

$global:TestName = 'TestGetAllAlerts'

$Regions = Get-AzsRegionHealth -ResourceGroupName $global:ResourceGroupName -Location $global:Location

foreach ($Region in $Regions) {

$Alerts = Get-AzsAlert -ResourceGroupName $global:ResourceGroupName -Location $Region.Name

foreach ($Alert in $Alerts) {
$retrieved = $Alert | Get-AzsAlert
AssertAlertsAreSame -Expected $Alert -Found $retrieved

}
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
if (-Not (Test-Path -Path $loadEnvPath)) {
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
}
. ($loadEnvPath)
$TestRecordingFile = Join-Path $PSScriptRoot 'Get-AzsRPHealth.Recording.json'
$currentPath = $PSScriptRoot
while(-not $mockingPath) {
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
$currentPath = Split-Path -Path $currentPath -Parent
}
. ($mockingPath | Select-Object -First 1).FullName

Describe "AzsServiceHealths" -Tags @('AzsServiceHealth', 'InfrastructureInsightsAdmin') {

. $PSScriptRoot\Common.ps1

it "TestListServiceHealths" -Skip:$('TestListServiceHealths' -in $global:SkippedTests) {
$global:TestName = 'TestListServiceHealths'


$RegionHealths = Get-AzsRegionHealth -Location $global:Location -ResourceGroupName $global:ResourceGroupName
foreach ($RegionHealth in $RegionHealths) {
$ServiceHealths = Get-AzsRPHealth -ResourceGroupName $global:ResourceGroupName -Location $RegionHealth.Name
foreach ($serviceHealth in $ServiceHealths) {
ValidateAzsServiceHealth -ServiceHealth $serviceHealth
}
}
}

it "TestGetServiceHealth" -Skip:$('TestGetServiceHealth' -in $global:SkippedTests) {
$global:TestName = 'TestGetServiceHealth'

$RegionHealths = Get-AzsRegionHealth -Location $global:Location -ResourceGroupName $global:ResourceGroupName
foreach ($RegionHealth in $RegionHealths) {
$ServiceHealths = Get-AzsRPHealth -ResourceGroupName $global:ResourceGroupName -Location $RegionHealth.Name
foreach ($serviceHealth in $ServiceHealths) {
$retrieved = Get-AzsRPHealth -ResourceGroupName $global:ResourceGroupName -Location $RegionHealth.Name -ServiceHealth $serviceHealth.RegistrationId
AssertAzsServiceHealthsAreSame -Expected $serviceHealth -Found $retrieved
break
}
break
}
}

it "TestGetAllServiceHealths" -Skip:$('TestGetAllServiceHealths' -in $global:SkippedTests) {
$global:TestName = 'TestGetAllServiceHealths'

$RegionHealths = Get-AzsRegionHealth -Location $global:Location -ResourceGroupName $global:ResourceGroupName
foreach ($RegionHealth in $RegionHealths) {
$ServiceHealths = Get-AzsRPHealth -ResourceGroupName $global:ResourceGroupName -Location $RegionHealth.Name
foreach ($serviceHealth in $ServiceHealths) {
$retrieved = Get-AzsRPHealth -ResourceGroupName $global:ResourceGroupName -Location $RegionHealth.Name -ServiceHealth $serviceHealth.RegistrationId
AssertAzsServiceHealthsAreSame -Expected $serviceHealth -Found $retrieved
}
}
}



it "TestGetAllServiceHealths" -Skip:$('TestGetAllServiceHealths' -in $global:SkippedTests) {
$global:TestName = 'TestGetAllServiceHealths'

$RegionHealths = Get-AzsRegionHealth -Location $global:Location -ResourceGroupName $global:ResourceGroupName
foreach ($RegionHealth in $RegionHealths) {
$ServiceHealths = Get-AzsRPHealth -ResourceGroupName $global:ResourceGroupName -Location $RegionHealth.Name
foreach ($serviceHealth in $ServiceHealths) {
$retrieved = $serviceHealth | Get-AzsRPHealth
AssertAzsServiceHealthsAreSame -Expected $serviceHealth -Found $retrieved
}
}
}
}
Loading

0 comments on commit 3fa8c50

Please sign in to comment.