ps/Modules/Alkami.DevOps.SqlReports/Public/Publish-SSRSReportsDirectory.Tests.ps1

117 lines
4.0 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
. $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 'Publish-SSRSReportsDirectory' {
$reportDirectory = $env:TEMP
$reportFolder = "foo report"
$reportHashLocation = "someHashLocation"
$webServiceUrl = "http:\\foo.com"
mock -ModuleName $moduleForMock Get-ChildItem -MockWith {
[PSCustomObject] `
@{ Name = '.\someReport.rdl' }
}
mock -ModuleName $moduleForMock Get-Content -MockWith {
[xml]
"<?xml version=`"1.0`" encoding=`"utf-8`"?>
<RptDataSource xmlns:xsi=`"http://www.w3.org/2001/XMLSchema-instance`" xmlns:xsd=`"http://www.w3.org/2001/XMLSchema`" Name=`"Alkami`">
<ConnectionProperties>
<Extension>SQL</Extension>
<ConnectString>Data Source=JunkSource;Initial Catalog=JunkCatalog</ConnectString>
<IntegratedSecurity>true</IntegratedSecurity>
</ConnectionProperties>
<DataSourceID>00000000-0000-0000-0000-000000000000</DataSourceID>
<Report>
<Description>Fizz-Buzz</Description>
</Report>
</RptDataSource>"
}
mock -ModuleName $moduleForMock Import-Csv -MockWith {
[PSCustomObject] `
@{
Algorithm = "SHA256"
Hash = "I'm a matching hash"
Path = ".\someReport.rdl"
}
}
mock -ModuleName $moduleForMock Publish-SSRSReport -MockWith {
123
}
mock -ModuleName $moduleForMock Start-Job -MockWith {
Invoke-Command -ScriptBlock {'Do Nothing'} -ComputerName localhost -AsJob
}
mock -ModuleName $moduleForMock Wait-Job -MockWith {$null}
it "should not throw when reportHashLocation is null" {
mock -ModuleName $moduleForMock Get-FileHash -MockWith {
[PSCustomObject] `
@{
Algorithm = "SHA256"
Hash = "I'm a matching hash"
Path = ".\someReport.rdl"
}
}
{ Publish-SSRSReportsDirectory $reportDirectory $webServiceUrl $reportFolder -avoidDoubleHop $true -Verbose } `
| should -Not -Throw
}
it "should call Start-Job when a provided reportHashLocation is null" {
mock -ModuleName $moduleForMock Get-FileHash -MockWith {
[PSCustomObject] `
@{
Algorithm = "SHA256"
Hash = "I'm a matching hash"
Path = ".\someReport.rdl"
}
}
Publish-SSRSReportsDirectory $reportDirectory $webServiceUrl $reportFolder -avoidDoubleHop $true -Verbose
Assert-MockCalled -ModuleName $moduleForMock Start-Job -Scope It
}
it "should call start-job when a provided hash doesn't match" {
mock -ModuleName $moduleForMock Get-FileHash -mockwith {
[PSCustomObject] `
@{
Algorithm = "SHA256"
Hash = "I'm a mismatched hash"
Path = ".\someReport.rdl"
}
}
Publish-SSRSReportsDirectory $reportdirectory $webserviceurl $reportfolder -avoiddoublehop $true -filehashlocation $reportHashLocation -verbose
Assert-MockCalled -ModuleName $moduleForMock Start-Job -scope it
}
it "should not call start-job when a provided hash matches" {
mock -ModuleName $moduleForMock Get-FileHash -mockwith {
[PSCustomObject] `
@{
Algorithm = "SHA256"
Hash = "I'm a matching hash"
Path = ".\someReport.rdl"
}
}
Publish-SSRSReportsDirectory $reportdirectory $webserviceurl $reportfolder -avoiddoublehop $true -filehashlocation $reportHashLocation -verbose
Assert-MockCalled -ModuleName $moduleForMock Start-Job -exactly 0 -scope it
}
}