121 lines
7.0 KiB
PowerShell
121 lines
7.0 KiB
PowerShell
|
. $PSScriptRoot\..\..\Load-PesterModules.ps1
|
|||
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|||
|
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
|
|||
|
$functionPath = Join-Path -Path $here -ChildPath $sut
|
|||
|
Write-Host "Overriding SUT: $functionPath"
|
|||
|
Import-Module $functionPath -Force
|
|||
|
$moduleForMock = ""
|
|||
|
|
|||
|
Describe "New-AppTierApplicationPool" {
|
|||
|
$appPoolName = "FakeServiceApp"
|
|||
|
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Get-AppSetting -MockWith { return $null } #simulates not having a configured app setting
|
|||
|
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Get-LogLeadName -MockWith { "UUT" }
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Write-Verbose -MockWith { }
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Write-Host -MockWith { }
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Write-Warning -MockWith { }
|
|||
|
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Get-Item -MockWith { return @{ not = "null";} }
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Get-AlkamiCredential -MockWith { param($username,$ignored) return @{ Username = $username; } }
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Set-ItemProperty -MockWith { } # We care that this gets called if $Credential.UserName -ne REPLACEME
|
|||
|
Mock -ModuleName $moduleForMock -CommandName New-WebAppPool -MockWith { } # We care this gets called if Get-Item is not-null, and vice-versa
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Set-AlkamiWebAppPoolConfiguration -MockWith { } # We care this gets called if Get-Item is not-null, and vice-versa
|
|||
|
|
|||
|
$fakeCredentialReplaceMe = New-Object 'Management.Automation.PsCredential' "REPLACEME",(ConvertTo-SecureString -AsPlainText -Force -String "Absolutely garbage string")
|
|||
|
$fakeCredentialActualUser = New-Object 'Management.Automation.PsCredential' "ActualUser",(ConvertTo-SecureString -AsPlainText -Force -String "Absolutely garbage string")
|
|||
|
|
|||
|
Context "Get-Item is not null, Username is REPLACEME" {
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Get-Item -MockWith { return @{ not = "null";} }
|
|||
|
|
|||
|
It "Does not throw" {
|
|||
|
{ New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialReplaceMe -IsGMSAAccount } | Should -Not -Throw
|
|||
|
}
|
|||
|
|
|||
|
It "Did not call Set-ItemProperty (due to username being REPLACEME)" {
|
|||
|
New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialReplaceMe -IsGMSAAccount
|
|||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Set-ItemProperty -Scope It -Times 0
|
|||
|
}
|
|||
|
|
|||
|
It "Did not call New-WebAppPool (due to apppool being found)" {
|
|||
|
New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialReplaceMe -IsGMSAAccount
|
|||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName New-WebAppPool -Scope It -Times 0
|
|||
|
}
|
|||
|
|
|||
|
It "Did not call Set-AlkamiWebAppPoolConfiguration (due to apppool being found)" {
|
|||
|
New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialReplaceMe -IsGMSAAccount
|
|||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Set-AlkamiWebAppPoolConfiguration -Scope It -Times 0
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Context "Get-Item is not null, Username is not REPLACEME" {
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Get-Item -MockWith { return @{ not = "null"; } }
|
|||
|
|
|||
|
It "Did not throw" {
|
|||
|
{ New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialActualUser -IsGMSAAccount } | Should -Not -Throw
|
|||
|
}
|
|||
|
|
|||
|
It "Did call Set-ItemProperty (due to username not being REPLACEME)" {
|
|||
|
New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialActualUser -IsGMSAAccount
|
|||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Set-ItemProperty -Scope It -Times 1
|
|||
|
}
|
|||
|
|
|||
|
It "Did not call New-WebAppPool (due to apppool being found)" {
|
|||
|
New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialActualUser -IsGMSAAccount
|
|||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName New-WebAppPool -Scope It -Times 0
|
|||
|
}
|
|||
|
|
|||
|
It "Did not call Set-AlkamiWebAppPoolConfiguration (due to apppool being found)" {
|
|||
|
New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialActualUser -IsGMSAAccount
|
|||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Set-AlkamiWebAppPoolConfiguration -Scope It -Times 0
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Context "Get-Item is null, Username is REPLACEME" {
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Get-Item -MockWith { return $null }
|
|||
|
|
|||
|
|
|||
|
It "Does not throw" {
|
|||
|
{ New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialReplaceMe -IsGMSAAccount } | Should -Not -Throw
|
|||
|
}
|
|||
|
|
|||
|
It "Did not call Set-ItemProperty (due to username being REPLACEME)" {
|
|||
|
New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialReplaceMe -IsGMSAAccount
|
|||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Set-ItemProperty -Scope It -Times 0
|
|||
|
}
|
|||
|
|
|||
|
It "Did call New-WebAppPool (due to apppool not being found)" {
|
|||
|
New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialReplaceMe -IsGMSAAccount
|
|||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName New-WebAppPool -Scope It -Times 1
|
|||
|
}
|
|||
|
|
|||
|
It "Did call Set-AlkamiWebAppPoolConfiguration (due to apppool not being found)" {
|
|||
|
New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialReplaceMe -IsGMSAAccount
|
|||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Set-AlkamiWebAppPoolConfiguration -Scope It -Times 1
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Context "Get-Item is null, Username is not REPLACEME" {
|
|||
|
Mock -ModuleName $moduleForMock -CommandName Get-Item -MockWith { return $null }
|
|||
|
|
|||
|
|
|||
|
It "Does not throw" {
|
|||
|
{ New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialActualUser -IsGMSAAccount } | Should -Not -Throw
|
|||
|
}
|
|||
|
|
|||
|
It "Did call Set-ItemProperty (due to username not being REPLACEME)" {
|
|||
|
New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialActualUser -IsGMSAAccount
|
|||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Set-ItemProperty -Scope It -Times 1
|
|||
|
}
|
|||
|
|
|||
|
It "Did call New-WebAppPool (due to apppool not being found)" {
|
|||
|
New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialActualUser -IsGMSAAccount
|
|||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName New-WebAppPool -Scope It -Times 1
|
|||
|
}
|
|||
|
|
|||
|
It "Did call Set-AlkamiWebAppPoolConfiguration (due to apppool not being found)" {
|
|||
|
New-AppTierApplicationPool -AppPoolName $AppPoolName -Credential $fakeCredentialActualUser -IsGMSAAccount
|
|||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Set-AlkamiWebAppPoolConfiguration -Scope It -Times 1
|
|||
|
}
|
|||
|
}
|
|||
|
}
|