Skip to content

Commit

Permalink
#235 Add Confirm-AzBPResource call to each example (ST-W directories) (
Browse files Browse the repository at this point in the history
…#240)

* Added Confirm-* examples for St*-Z* resources

* Minor typo fixes.

* Updates based on the Design Session.

* Code review upates.

* Code review upates.

* Removing whiitespace added by the editor.

* Code review upates.

* Adding clarification on unloading the BenchPress module to the getting started docs.

* Rephrasing to make megalinter happy.
  • Loading branch information
marclerwick authored Mar 22, 2023
1 parent 1087856 commit 86fb7e8
Show file tree
Hide file tree
Showing 11 changed files with 652 additions and 288 deletions.
5 changes: 5 additions & 0 deletions Modules/BenchPress.Azure/Classes/ResourceType.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ enum ResourceType{
StorageAccount
StorageContainer
StreamAnalyticsCluster
StreamAnalyticsFunction
StreamAnalyticsInput
StreamAnalyticsJob
StreamAnalyticsOutput
StreamAnalyticsTransformation
SynapseSparkPool
SynapseSqlPool
SynapseWorkspace
Expand Down
143 changes: 104 additions & 39 deletions examples/Storage/Storage.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,78 +1,138 @@
BeforeAll {
Import-Module Az.InfrastructureTesting

$Script:rgName = 'rg-test'
$Script:accountName = 'azbenchpressstorage'
$Script:location = 'westus3'
}

Describe 'Verify Storage Account' {
it 'Should contain a Storage Account with the given name' {
BeforeAll {
$Script:noAccountName = 'noazbenchpressstorage'
}

It 'Should contain a Storage Account with the given name - Confirm-AzBPResource' {
#arrange
$rgName = 'rg-test'
$name = 'azbenchpressstorage'
$params = @{
ResourceType = "StorageAccount"
ResourceGroupName = $rgName
ResourceName = $accountName
}

#act
$result = Confirm-AzBPStorageAccount -ResourceGroupName $rgName -Name $name
$result = Confirm-AzBPResource @params

#assert
$result.Success | Should -Be $true
}

it 'Should not contain a Storage Account with the given name' {
It "Should contain a Storage Account named $accountName - ConfirmAzBPResource" {
#arrange
$rgName = 'rg-test'
$serverName = 'noazbenchpressstorage'
$params = @{
ResourceType = "StorageAccount"
ResourceGroupName = $rgName
ResourceName = $accountName
PropertyKey = 'StorageAccountName'
PropertyValue = $accountName
}

#act
$result = Confirm-AzBPResource @params

#assert
$result.Success | Should -Be $true
}

It 'Should contain a Storage Account with the given name' {
#act
$result = Confirm-AzBPStorageAccount -ResourceGroupName $rgName -Name $accountName

#assert
$result.Success | Should -Be $true
}

It 'Should not contain a Storage Account with the given name' {

#act
# The '-ErrorAction SilentlyContinue' command suppresses all errors.
# In this test, it will suppress the error message when a resource cannot be found.
# Remove this field to see all errors.
$result = Confirm-AzBPStorageAccount -ResourceGroupName $rgName -Name $serverName -ErrorAction SilentlyContinue
$result = Confirm-AzBPStorageAccount -ResourceGroupName $rgName -Name $noAccountName -ErrorAction SilentlyContinue

#assert
$result.Success | Should -Be $false
}

it 'Should contain a Storage Account named azbenchpressstorage' {
#arrange
$rgName = 'rg-test'
$name = 'azbenchpressstorage'

It "Should contain a Storage Account named $accountName" {
#act
$result = Confirm-AzBPStorageAccount -ResourceGroupName $rgName -Name $name
$result = Confirm-AzBPStorageAccount -ResourceGroupName $rgName -Name $accountName

#assert
$result | Should -BeDeployed
}

it 'Should contain a Storage Account named azbenchpressstorage in westus3' {
It "Should contain a Storage Account named $accountName in $location" {
#act
$result = Confirm-AzBPStorageAccount -ResourceGroupName $rgName -Name $accountName
#assert
$result | Should -BeInLocation $location
}

It "Should be a Storage Account in a resource group named $rgName" {
#act
$result = Confirm-AzBPStorageAccount -ResourceGroupName $rgName -Name $accountName

#assert
$result | Should -BeInResourceGroup $rgName
}
}

Describe 'Verify Storage Container' {
BeforeAll {
$Script:containerName = 'azbenchpresscontainer'
$Script:noContainerName = 'noazbenchpresscontainer'
}

It 'Should contain a Storage Container with the given name - Confirm-AzBPResource' {
#arrange
$rgName = 'rg-test'
$name = 'azbenchpressstorage'
$params = @{
ResourceType = "StorageContainer"
ResourceGroupName = $rgName
AccountName = $accountName
ResourceName = $containerName
}

#act
$result = Confirm-AzBPStorageAccount -ResourceGroupName $rgName -Name $name
$result = Confirm-AzBPResource @params

#assert
$result | Should -BeInLocation 'westus3'
$result.Success | Should -Be $true
}

it 'Should be a Storage Account in a resource group named rg-test' {
It "Should contain a Storage Container named $containerName - ConfirmAzBPResource" {
#arrange
$rgName = 'rg-test'
$name = 'azbenchpressstorage'
$params = @{
ResourceType = "StorageContainer"
ResourceGroupName = $rgName
AccountName = $accountName
ResourceName = $containerName
PropertyKey = 'Name'
PropertyValue = $containerName
}

#act
$result = Confirm-AzBPStorageAccount -ResourceGroupName $rgName -Name $name
$result = Confirm-AzBPResource @params

#assert
$result | Should -BeInResourceGroup 'rg-test'
$result.Success | Should -Be $true
}
}

Describe 'Verify Storage Container' {
it 'Should contain a Storage Container with the given name' {
It 'Should contain a Storage Container with the given name' {
#arrange
$params = @{
ResourceGroupName = 'rg-test'
AccountName = 'azbenchpressstorage'
Name = 'azbenchpresscontainer'
ResourceGroupName = $rgName
AccountName = $accountName
Name = $containerName
}

#act
Expand All @@ -82,13 +142,13 @@ Describe 'Verify Storage Container' {
$result.Success | Should -Be $true
}

it 'Should not contain a Storage Container with the given name' {
It "Should not contain a Storage Container with the given name" {
#arrange
$params = @{
ResourceGroupName = 'rg-test'
AccountName = 'azbenchpressstorage'
Name = 'noazbenchpresscontainer'
ErrorAction = 'SilentlyContinue'
ResourceGroupName = $rgName
AccountName = $accountName
Name = $noContainerName
ErrorAction = "SilentlyContinue"
}

#act
Expand All @@ -101,12 +161,12 @@ Describe 'Verify Storage Container' {
$result.Success | Should -Be $false
}

it 'Should contain a Storage Container named azbenchpresscontainer' {
It "Should contain a Storage Container named $containerName" {
#arrange
$params = @{
ResourceGroupName = 'rg-test'
AccountName = 'azbenchpressstorage'
Name = 'azbenchpresscontainer'
ResourceGroupName = $rgName
AccountName = $accountName
Name = $containerName
}

#act
Expand All @@ -116,3 +176,8 @@ Describe 'Verify Storage Container' {
$result | Should -BeDeployed
}
}

AfterAll {
Get-Module Az-InfrastructureTesting | Remove-Module
Get-Module BenchPress.Azure | Remove-Module
}
6 changes: 4 additions & 2 deletions examples/Storage/Storage_Example.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@

1. Update `Storage.Tests.ps1` variables to point to your expected resources:

- `rg-test` -> `your-resource-group-name`
- `rg-test` -> `your-resource-group-name`
- `westus3` -> `your-resource-group-location`
- `azbenchpressstorage` -> `your-storage-account-name`

1. If using a local copy of `Az.InfrastructureTesting`, replace `Import-Module Az.InfrastructureTesting` with
`Import-Module "../../bin/BenchPress.Azure.psd1"`.
`Import-Module "../../bin/BenchPress.Azure.psd1"`. Note that the final `AfterAll` step will properly remove the module
regardless of which method is chosen to load the module.

1. Run `Storage.Tests.ps1`:

Expand Down
Loading

0 comments on commit 86fb7e8

Please sign in to comment.