. $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 "Test-PackageHasAlkamiManifest" { # Describe fake package info. $source = "https://www.fakepackagerepo.com/nuget/fake.feed"; $name = "fake.package"; $version = "1.2.3"; # Fake responses from Invoke-WebRequest for mocked Get-PackageFileList $validAlkamiManifestPackage = "[{`"fullPath`":`"tools/Whatever.dll`",`"parentFullPath`":`"tools/`",`"name`":`"Whatever.dll`",`"isDirectory`":false},{`"fullPath`":`"AlkamiManifest.xml`",`"parentFullPath`":`"/`",`"name`":`"AlkamiManifest.xml`",`"isDirectory`":false}]" $invalidAlkamiManifestPackage = "[{`"fullPath`":`"tools/Whatever.dll`",`"parentFullPath`":`"tools/`",`"name`":`"Whatever.dll`",`"isDirectory`":false},{`"fullPath`":`"src/AlkamiManifest.xml`",`"parentFullPath`":`"/src`",`"name`":`"AlkamiManifest.xml`",`"isDirectory`":false}]" $missingAlkamiManifest = "[{`"fullPath`":`"package/files/otherfile.xml`",`"parentFullPath`":`"package/files/`",`"name`":`"otherfile.xml`",`"isDirectory`":false}]" Context "Valid Alkami Manifest Package" { Mock -CommandName Get-PackageFileListV2 -ModuleName $moduleForMock -MockWith { return (ConvertFrom-Json -InputObject $validAlkamiManifestPackage) } It "Correctly Identifies an Alkami Manifest" { (Test-PackageHasAlkamiManifestV2 -feedSource $source -name $name -version $version) | Should -BeTrue } } Context "Invalid Alkami Manifest Package" { Mock -CommandName Get-PackageFileListV2 -ModuleName $moduleForMock -MockWith { return (ConvertFrom-Json -InputObject $invalidAlkamiManifestPackage) } It "Correctly Identifies an Alkami Manifest" { (Test-PackageHasAlkamiManifestV2 -feedSource $source -name $name -version $version) | Should -BeFalse } } Context "Not a Package With an Alkami Manifest" { Mock -CommandName Get-PackageFileListV2 -ModuleName $moduleForMock -MockWith { return @(ConvertFrom-Json -InputObject $missingAlkamiManifest) } It "Returns False Because it is not an Alkami Manifest Package" { (Test-PackageHasAlkamiManifestV2 -feedSource $source -name $name -version $version) | Should -BeFalse } } } # Ok, this next test block is very weird. Basically, I'm trying to say "if the other file doesn't do what it should then this one should still do what it should" # I'm probably doing this wrong and we should 100% revisit in 2022 and ask if we are doing the right thing # TODO: Revisit this test strategy to ensure we need it. This is an attempt at properly testing SRE-17072 - cbrand 2021-12-15 Describe "Test-PackageHasAlkamiManifest_with_Integration" -Tags @('Integration') { # Describe fake package info. $source = "https://www.fakepackagerepo.com/nuget/fake.feed"; $name = "fake.package"; $version = "1.2.3"; Context "Uses the pattern from Get-PackageFileListV2 test to do an integration test" { $additionalSut = "Get-PackageFileListV2.ps1" $functionPath = Join-Path -Path $here -ChildPath $additionalSut Write-Host "Overriding Additional-SUT: $functionPath" Import-Module $functionPath -Force $script:testString = @" [ { "fullPath": "src/VCU.MS.CardControl.Notifications/", "parentFullPath": "src/", "name": "VCU.MS.CardControl.Notifications", "isDirectory": true }, { "fullPath": "src/", "parentFullPath": "/", "name": "src", "isDirectory": true }, { "fullPath": "src/VCU.MS.CardControl.Notifications/VCU.Modules.CardControl/", "parentFullPath": "src/VCU.MS.CardControl.Notifications/", "name": "VCU.Modules.CardControl", "isDirectory": true }, { "fullPath": "package/services/metadata/core-properties/", "parentFullPath": "package/services/metadata/", "name": "core-properties", "isDirectory": true }, { "fullPath": "package/services/metadata/", "parentFullPath": "package/services/", "name": "metadata", "isDirectory": true }, { "fullPath": "package/services/", "parentFullPath": "package/", "name": "services", "isDirectory": true }, { "fullPath": "package/", "parentFullPath": "/", "name": "package", "isDirectory": true }, { "fullPath": "package/services/metadata/core-properties/5bb485eb5b744639ac99ff7821cf325a.psmdcp", "parentFullPath": "package/services/metadata/core-properties/", "name": "5bb485eb5b744639ac99ff7821cf325a.psmdcp", "isDirectory": false }, { "fullPath": "src/VCU.MS.CardControl.Notifications/VCU.Modules.CardControl/AlkamiManifest.xml", "parentFullPath": "src/VCU.MS.CardControl.Notifications/VCU.Modules.CardControl/", "name": "AlkamiManifest.xml", "isDirectory": false }, { "fullPath": "_rels/", "parentFullPath": "/", "name": "_rels", "isDirectory": true }, { "fullPath": "_rels/.rels", "parentFullPath": "_rels/", "name": ".rels", "isDirectory": false }, { "fullPath": "tools/", "parentFullPath": "/", "name": "tools", "isDirectory": true }, { "fullPath": "tools/VCU.MS.CardControl.Notifications.Host.exe", "parentFullPath": "tools/", "name": "VCU.MS.CardControl.Notifications.Host.exe", "isDirectory": false }, { "fullPath": "tools/ChocolateyUninstall.ps1", "parentFullPath": "tools/", "name": "ChocolateyUninstall.ps1", "isDirectory": false }, { "fullPath": "tools/ChocolateyInstall.ps1", "parentFullPath": "tools/", "name": "ChocolateyInstall.ps1", "isDirectory": false }, { "fullPath": "VCU.MS.CardControl.Notifications.Host.nuspec", "parentFullPath": "/", "name": "VCU.MS.CardControl.Notifications.Host.nuspec", "isDirectory": false }, { "fullPath": "[Content_Types].xml", "parentFullPath": "/", "name": "[Content_Types].xml", "isDirectory": false } ] "@ Mock -Module $moduleForMock -CommandName Invoke-ProgetRequest -MockWith { return $script:testString } Mock -Module $moduleForMock -CommandName Get-BasicAuthHeader -MockWith { return @{} } # just give an empty object for parameter It "Returns False Because it is not an Alkami Manifest Package" { (Test-PackageHasAlkamiManifestV2 -feedSource $source -name $name -version $version) | Should -BeFalse } } # This is an invalid test. "Get-PackageFileList" should be mocked # This test should validate how this SUT responds when the return value of Get-PackageFileList is $null # The _behavior_ of this original test should be moved to tests for "Get-PackageFileList" instead <#Context "Bad Nuget Source" { $source = "https://www.badpackagerepo.com/bad.feed"; It "Fails Because the Source Feed URL is Badly Formatted" { { Test-PackageHasAlkamiManifest -feedSource $source -name $name -version $version -ErrorAction Stop} | Should -Throw; } }#> }