Tests/Wait-OriAzBopModuleComplete.tests.ps1
. $PSScriptRoot\..\Public\Wait-OriAzBopModuleComplete.ps1 . $PSScriptRoot\..\Public\Test-OriAzBopModuleComplete.ps1 . $PSScriptRoot\..\Public\Get-OriAzBopModuleMd5FromTag.ps1 Describe 'OriAzBopBoostrapOriPsgallery\Wait-OriAzBopModuleComplete' { Context 'Succesfull excution while no check is requied' { $testPath = "TestDrive:\myPsModule.psd1" Set-Content $testPath -value "my test text." Mock -CommandName Get-OriAzBopModuleMd5FromTag -Verifiable -MockWith { return "" } Mock -CommandName Test-OriAzBopModuleComplete Mock -CommandName Write-Verbose -Verifiable Mock -CommandName Write-Debug -Verifiable it 'Should be succesfully processed' { { Wait-OriAzBopModuleComplete ` -Path "TestDrive:\myPsModule.psd1" } | Should -Not -Throw } Assert-MockCalled Get-OriAzBopModuleMd5FromTag -Times 1 -Exactly Assert-MockCalled Test-OriAzBopModuleComplete -Times 0 -Exactly Assert-MockCalled Write-Debug -Times 1 -Exactly -ParameterFilter { $Message -eq "No MD5 found in module." } Assert-MockCalled Write-Verbose -Times 1 -Exactly -ParameterFilter { $Message -eq "-- End of Wait-OriAzBopModuleComplete --" } Assert-VerifiableMock } Context 'Succesfull excution while check is requied' { $testPath = "TestDrive:\myPsModule.psd1" Set-Content $testPath -value "my test text." Mock -CommandName Get-OriAzBopModuleMd5FromTag -Verifiable -MockWith { return "3a2525173780253134a12527003ae151" } [int] $Global:i = 0 Mock -CommandName Test-OriAzBopModuleComplete -Verifiable -MockWith { if($Global:i -lt 3) { $Global:i++ return $false } else { return $true } } Mock -CommandName Start-Sleep -Verifiable Mock -CommandName Write-Verbose -Verifiable Mock -CommandName Write-Debug -Verifiable it 'Should be succesfully processed' { { Wait-OriAzBopModuleComplete ` -Path "TestDrive:\myPsModule.psd1" ` -SleepInSec 0 ` -MaxRetry 5 } | Should -Not -Throw } Assert-MockCalled Get-OriAzBopModuleMd5FromTag -Times 1 -Exactly Assert-MockCalled Start-Sleep -Times 3 -Exactly Assert-MockCalled Test-OriAzBopModuleComplete -Times 4 -Exactly Assert-MockCalled Write-Debug -Times 0 -Exactly -ParameterFilter { $Message -eq "No MD5 found in module." } Assert-MockCalled Write-Verbose -Times 1 -Exactly -ParameterFilter { $Message -eq "-- End of Wait-OriAzBopModuleComplete --" } Assert-VerifiableMock } Context 'Succesfull excution while check is requied' { $testPath = "TestDrive:\myPsModule.psd1" Set-Content $testPath -value "my test text." Mock -CommandName Get-OriAzBopModuleMd5FromTag -Verifiable -MockWith { return "3a2525173780253134a12527003ae151" } [int] $Global:i = 0 Mock -CommandName Test-OriAzBopModuleComplete -Verifiable -MockWith { if($Global:i -lt 10) { $Global:i++ return $false } else { return $true } } Mock -CommandName Start-Sleep -Verifiable Mock -CommandName Write-Verbose -Verifiable Mock -CommandName Write-Debug -Verifiable it 'Should be succesfully processed' { { Wait-OriAzBopModuleComplete ` -Path "TestDrive:\myPsModule.psd1" ` -SleepInSec 0 ` -MaxRetry 5 } | Should -Throw "The module [TestDrive:\myPsModule.psd1] is not complete based on MD5 in the module tag is expected [3a2525173780253134a12527003ae151]. Max retry [5] reached." } Assert-MockCalled Get-OriAzBopModuleMd5FromTag -Times 1 -Exactly Assert-MockCalled Start-Sleep -Times 4 -Exactly Assert-MockCalled Test-OriAzBopModuleComplete -Times 5 -Exactly Assert-MockCalled Write-Debug -Times 0 -Exactly -ParameterFilter { $Message -eq "No MD5 found in module." } Assert-MockCalled Write-Verbose -Times 0 -Exactly -ParameterFilter { $Message -eq "-- End of Wait-OriAzBopModuleComplete --" } Assert-VerifiableMock } } |