53 lines
2.6 KiB
PowerShell
53 lines
2.6 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 "Test-PackageHasInfrastructureMigrations" {
|
|||
|
|
|||
|
# 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
|
|||
|
$validInfraMigrationPackage = "[{`"fullPath`":`"tools/Whatever.dll`",`"parentFullPath`":`"tools/`",`"name`":`"Whatever.dll`",`"isDirectory`":false},{`"fullPath`":`"Terraform/main.tf`",`"parentFullPath`":`"/`",`"name`":`"main.tf`",`"isDirectory`":false}]"
|
|||
|
$nonInfraMigrationPackage = "[{`"fullPath`":`"package/files/otherfile.xml`",`"parentFullPath`":`"package/files/`",`"name`":`"otherfile.xml`",`"isDirectory`":false}]"
|
|||
|
|
|||
|
|
|||
|
Context "Valid Infrastructure Migration Package" {
|
|||
|
Mock -CommandName Get-PackageFileListV2 -ModuleName $moduleForMock -MockWith {
|
|||
|
return (ConvertFrom-Json -InputObject $validInfraMigrationPackage)
|
|||
|
}
|
|||
|
|
|||
|
It "Correctly Identifies an Infrastructure Migration Microservice" {
|
|||
|
$result = Test-PackageHasInfrastructureMigrationsV2 -feedSource $source -name $name -version $version;
|
|||
|
$result | Should -be $true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Context "Not an Infrastructure Migration Package" {
|
|||
|
Mock -CommandName Get-PackageFileListV2 -ModuleName $moduleForMock -MockWith {
|
|||
|
return (ConvertFrom-Json -InputObject $nonInfraMigrationPackage)
|
|||
|
}
|
|||
|
It "Returns False Because it is not an Infrastructure Migration Package" {
|
|||
|
$result = Test-PackageHasInfrastructureMigrationsV2 -feedSource $source -name $name -version $version;
|
|||
|
$result | Should -be $false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
# 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-PackageHasInfrastructureMigrations -feedSource $source -name $name -version $version -ErrorAction Stop} | Should -Throw;
|
|||
|
}
|
|||
|
}#>
|
|||
|
}
|