From 7c6ef53ca09ba6269c684a5b7c3525477e4c1519 Mon Sep 17 00:00:00 2001 From: CorpoC Date: Tue, 24 May 2022 14:43:14 +0100 Subject: [PATCH 1/7] test: tests for terraform dependency type --- .gitignore | 3 +- Tests/DependFiles/terraform.depend.psd1 | 6 + .../terraform_bad_version.depend.psd1 | 6 + .../terraform_no_version.depend.psd1 | 6 + Tests/PSModuleGallery.Type.Tests.ps1 | 126 ++++++++++++++++++ 5 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 Tests/DependFiles/terraform.depend.psd1 create mode 100644 Tests/DependFiles/terraform_bad_version.depend.psd1 create mode 100644 Tests/DependFiles/terraform_no_version.depend.psd1 diff --git a/.gitignore b/.gitignore index 6f437ab..9efbc27 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -nuget.exe \ No newline at end of file +nuget.exe +terraform.exe \ No newline at end of file diff --git a/Tests/DependFiles/terraform.depend.psd1 b/Tests/DependFiles/terraform.depend.psd1 new file mode 100644 index 0000000..1795958 --- /dev/null +++ b/Tests/DependFiles/terraform.depend.psd1 @@ -0,0 +1,6 @@ +@{ + 'terraform' = @{ + DependencyType = "Terraform" + Version = "1.1.1" + } +} \ No newline at end of file diff --git a/Tests/DependFiles/terraform_bad_version.depend.psd1 b/Tests/DependFiles/terraform_bad_version.depend.psd1 new file mode 100644 index 0000000..efb724c --- /dev/null +++ b/Tests/DependFiles/terraform_bad_version.depend.psd1 @@ -0,0 +1,6 @@ +@{ + 'terraform' = @{ + DependencyType = "Terraform" + Version = "a.1.1" + } +} \ No newline at end of file diff --git a/Tests/DependFiles/terraform_no_version.depend.psd1 b/Tests/DependFiles/terraform_no_version.depend.psd1 new file mode 100644 index 0000000..6d74f20 --- /dev/null +++ b/Tests/DependFiles/terraform_no_version.depend.psd1 @@ -0,0 +1,6 @@ +@{ + 'terraform' = @{ + DependencyType = "Terraform" + Version = "0.0.0" + } +} \ No newline at end of file diff --git a/Tests/PSModuleGallery.Type.Tests.ps1 b/Tests/PSModuleGallery.Type.Tests.ps1 index 34d78a1..0cd9ab2 100644 --- a/Tests/PSModuleGallery.Type.Tests.ps1 +++ b/Tests/PSModuleGallery.Type.Tests.ps1 @@ -1252,4 +1252,130 @@ InModuleScope ('{0}' -f $ENV:BHProjectName) { } } } + + Describe "Terraform Type PS$PSVersion" { + Context 'Installs dependency' { + Mock Get-WebFile { + [pscustomobject]@{ + PSB = $PSBoundParameters + Arg = $Args + } + } + Mock Get-InstalledTerraformVersion {} + + $Dependencies = @(Get-Dependency @Verbose -Path "$TestDepends\terraform.depend.psd1") + + It 'Parses the Terraform dependency type' { + $Dependencies.count | Should be 1 + $Dependencies[0].DependencyType | Should be 'Terraform' + } + + $Results = Invoke-PSDepend @Verbose -Path "$TestDepends\terraform.depend.psd1" -Force + + It 'Invokes the Terraform dependency type' { + Assert-MockCalled Get-WebFile -Times 0 -Exactly + Assert-MockCalled Get-InstalledTerraformVersion -Times 1 -Exactly + } + } + + Context 'Installs dependency' { + Mock Get-WebFile { + [pscustomobject]@{ + PSB = $PSBoundParameters + Arg = $Args + } + } + Mock Get-InstalledTerraformVersion {} + + $Dependencies = @(Get-Dependency @Verbose -Path "$TestDepends\terraform.depend.psd1") + + It 'Parses the Terraform dependency type' { + $Dependencies.count | Should be 1 + $Dependencies[0].DependencyType | Should be 'Terraform' + } + + $Results = Invoke-PSDepend @Verbose -Path "$TestDepends\terraform.depend.psd1" -Force + + It 'Invokes the Terraform dependency type' { + Assert-MockCalled Get-WebFile -Times 0 -Exactly + Assert-MockCalled Get-InstalledTerraformVersion -Times 1 -Exactly + } + } + + Context "Bad version input" { + Mock Get-WebFile {} + Mock Get-InstalledTerraformVersion {} + + It "Throws because required version doesn't exist" { + $Results = { Invoke-PSDepend @Verbose -Path "$TestDepends\terraform_no_version.depend.psd1" -Force } + Assert-MockCalled Get-InstalledTerraformVersion -Times 0 -Exactly + $Results | Should Throw + } + + It "Throws because requested version couldn't be found" { + $Results = { Invoke-PSDepend @Verbose -Path "$TestDepends\terraform_bad_version.depend.psd1" -Force } + Assert-MockCalled Get-InstalledTerraformVersion -Times 1 -Exactly + $Results | Should Throw + } + } + + Context 'Tests dependency - not installed' { + Mock Get-WebFile {} + Mock Get-InstalledTerraformVersion { + return [PSCustomObject]@{ + IsInstalled = $false + IsPreRelease = $false + } + } + It 'Returns $false if it is not installed' { + $Results = @( Get-Dependency @Verbose -Path "$TestDepends\terraform.depend.psd1" | Test-Dependency @Verbose -Quiet) + $Results.count | Should be 1 + $Results[0] | Should be $False + Assert-MockCalled -CommandName Get-WebFile -Times 0 -Exactly + Assert-MockCalled Get-InstalledTerraformVersion -Times 1 -Exactly + } + } + + Context "Tests dependency - installed with wrong version" { + Mock Get-WebFile {} + Mock Get-InstalledTerraformVersion { + return [PSCustomObject]@{ + IsInstalled = $true + Version = "1.0.0" + VersionCore = "1.0.0" + PreRelease = $null + IsPreRelease = $null + } + } + + It 'Returns $false if it is installed and is the wrong version' { + $Results = @( Get-Dependency @Verbose -Path "$TestDepends\terraform.depend.psd1" | Test-Dependency @Verbose -Quiet) + $Results.count | Should be 1 + $Results[0] | Should be $false + Assert-MockCalled -CommandName Get-WebFile -Times 0 -Exactly + Assert-MockCalled Get-InstalledTerraformVersion -Times 1 -Exactly + } + } + + Context "Tests dependency - installed with correct version" { + Mock Get-WebFile {} + Mock Get-InstalledTerraformVersion { + return [PSCustomObject]@{ + IsInstalled = $true + Version = "1.1.1" + VersionCore = "1.1.1" + PreRelease = $null + IsPreRelease = $null + } + } + + It 'Returns $true if it is installed' { + $Results = @( Get-Dependency @Verbose -Path "$TestDepends\terraform.depend.psd1" | Test-Dependency @Verbose -Quiet) + $Results.count | Should be 1 + $Results[0] | Should be $true + Assert-MockCalled -CommandName Get-WebFile -Times 0 -Exactly + Assert-MockCalled Get-InstalledTerraformVersion -Times 1 -Exactly + } + } + } } From 8741b53ffb29b28d66b2cddfee25a266afae62eb Mon Sep 17 00:00:00 2001 From: CorpoC Date: Tue, 24 May 2022 15:05:36 +0100 Subject: [PATCH 2/7] feat: terraform dependency support --- PSDepend2/PSDependMap.psd1 | 8 +- PSDepend2/PSDependScripts/Terraform.ps1 | 153 ++++++++++++++++++ .../Private/Get-InstalledTerraformVersion.ps1 | 37 +++++ 3 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 PSDepend2/PSDependScripts/Terraform.ps1 create mode 100644 PSDepend2/Private/Get-InstalledTerraformVersion.ps1 diff --git a/PSDepend2/PSDependMap.psd1 b/PSDepend2/PSDependMap.psd1 index 1103b6f..cd421a3 100644 --- a/PSDepend2/PSDependMap.psd1 +++ b/PSDepend2/PSDependMap.psd1 @@ -11,7 +11,7 @@ Description = 'Install a Chocolatey package from a Chocolatey feed' Supports = 'windows' } - + Command = @{ Script = 'Command.ps1' Description = 'Invoke a command in PowerShell' @@ -89,4 +89,10 @@ Description = 'Support dependencies by handling simple tasks' Supports = 'core', 'windows', 'macos', 'linux' } + + Terraform = @{ + Script = 'Terraform.ps1' + Description = 'Installs Terraform' + Supports = 'core', 'windows', 'macos', 'linux' + } } diff --git a/PSDepend2/PSDependScripts/Terraform.ps1 b/PSDepend2/PSDependScripts/Terraform.ps1 new file mode 100644 index 0000000..94aea71 --- /dev/null +++ b/PSDepend2/PSDependScripts/Terraform.ps1 @@ -0,0 +1,153 @@ +<# + .SYNOPSIS + Installs Terraform + + .DESCRIPTION + Downloads and places the desired version of terraform on the PATH + + Relevant Dependency metadata: + DependencyName (Key): This should be terraform + Target: The folder to download this file to. If a full path to a new file is used, this overrides any other file name. + AddToPath: If specified, prepend the target's parent container to PATH + + .NOTES + + .PARAMETER Architecture + The architecture of the binary to install. Defaults to amd64 + + .PARAMETER PSDependAction + Test or Install the module. Defaults to Install + + Test: Return true or false on whether the dependency is in place + Install: Install the dependency + + .EXAMPLE + @{ + 'terraform' = @{ + DependencyType = "Terraform" + Version = "1.1.1" + } + + Downloads terraform v1.1.1 to the current working directory + + .EXAMPLE + @{ + 'terraform' = @{ + DependencyType = "Terraform" + Target = "./Tools" + Version = "1.2.0" + } + + Downloads terraform v1.2.0 to the target path relative from the current working directory. It will create the Tools folder if it doesn't already exist. + + This is the recommended setup in conjunction with a local folder within your repo that is untracked by VCS where your dependencies are local to your code and + you can specify a path that is not impacted by platform you are running PSDepend on + + .EXAMPLE + @{ + 'terraform' = @{ + DependencyType = "Terraform" + Target = "/usr/bin/local" + Version = "1.2.0" + } + + Downloads terraform v1.2.0 to the absolute path + + .EXAMPLE + @{ + 'terraform' = @{ + DependencyType = "Terraform" + Parameters = @{ + Architecture = "arm" + } + Version = "1.2.0" + } + + Downloads terraform v1.2.0 for ARM architecture +} +#> +[cmdletbinding()] +param( + [PSTypeName('PSDepend.Dependency')] + [psobject[]] + $Dependency, + + $Architecture = "amd64", + + [ValidateSet('Test', 'Install')] + [string[]]$PSDependAction = @('Install') +) + +$VersionRegex = "(?\d+\.\d+.\d+)(-(?.+)){0,1}$" +$Source = $Dependency.Source +$tf = Get-InstalledTerraformVersion +$Version = Select-String -Pattern $VersionRegex -InputObject $Dependency.Version + +if (-not $Version) { + throw "Input version does not match regex" +} + +$Platform = ((Get-OSEnvironment) -eq "MacOS" ? "darwin" : (Get-OSEnvironment)).ToLower() +$FileName = "terraform_{0}_{1}_{2}.zip" -f $Version, $Platform, $Architecture +$DownloadPath = Join-Path $env:TEMP $FileName +if (-not $Dependency.target) { + $Path = Get-Location +} +else { + $Path = $Dependency.Target +} + +if ($tf.IsInstalled) { + if ($tf.Version -ne $Version) { + Write-Verbose "Installed Terraform v$($tf.Version) does not match version v$($Version) required" + $ToInstall = $true + } + else { + Write-Verbose "Terraform v$($tf.Version) installed" + $ToInstall = $false + } +} +else { + Write-Verbose "Terraform not found on path" + $ToInstall = $true +} + +if ($PSDependAction -eq "Install" -and $ToInstall -eq $true) { + if ($Source) { + $URL = $Source + } + else { + $URL = "https://releases.hashicorp.com/terraform/{0}/{1}" -f $Version, $FileName + } + Write-Verbose "Downloading [$URL] to [$DownloadPath]" + + if (-not (Test-Path $DownloadPath)) { + Write-Verbose "Version of zip not found at $DownloadPath" + try { + Get-WebFile -URL $URL -Path $DownloadPath + } + catch { + $_ + throw "Unable to retrieve package from $URL" + } + } + else { + Write-Verbose "Version of zip found at $DownloadPath" + } + + $Out = Expand-Archive -Path $DownloadPath -DestinationPath $Path -Force -PassThru + Write-Verbose "Terraform installed to $Out" + + if ($Dependency.AddToPath) { + Write-Verbose "Setting PATH to`n$($Path, $env:PATH -join ';' | Out-String)" + Add-ToItemCollection -Reference Env:\Path -Item $Path + } + + return $true +} +elseif ($PSDependAction -eq "Install" -and $ToInstall -eq $false) { + return $true +} +elseif ($PSDependAction -eq "Test") { + return $ToInstall -eq $true ? $false : $true +} \ No newline at end of file diff --git a/PSDepend2/Private/Get-InstalledTerraformVersion.ps1 b/PSDepend2/Private/Get-InstalledTerraformVersion.ps1 new file mode 100644 index 0000000..4b82759 --- /dev/null +++ b/PSDepend2/Private/Get-InstalledTerraformVersion.ps1 @@ -0,0 +1,37 @@ +function Get-InstalledTerraformVersion { + param( + [string] $VersionRegex = "(?\d+\.\d+.\d+)(-(?.+)){0,1}$" + ) + end { + # We don't check the whole fs for TF, either its on the path at the version we want already + # or we put the version we want where the build wants it + + # We add current location to the path as the first entry to search for the terraform command. To not do this would + # result in an output message that can't be avoided which we don't want or care about + # We assume that if the client installs tf into the current directory (i.e. doesn't specify a target dir) + # then they are happy to cater for the ./ requirement for pwsh to run the binary properly + $PATH_BACKUP = $env:PATH + Add-ToItemCollection -Reference Env:\Path -Item (Get-Location) + $IsInstalled = (Get-Command terraform -ErrorAction SilentlyContinue) + if ($IsInstalled) { + $g = ((terraform --version)[0] | Select-String -Pattern $VersionRegex).Matches.Groups + $env:PATH = $PATH_BACKUP + $VersionCore = ($g | Where-Object Name -EQ "Version").Value + $PreRelease = ($g | Where-Object Name -EQ "PreReleaseTag").Value + return ([psobject]@{ + IsInstalled = $true + Version = "{0}{1}" -f $VersionCore, $PreReleaseTag + VersionCore = $VersionCore + PreRelease = $PreRelease + IsPreRelease = ($null -ne $PreRelease ? $true : $false) + }) + } + else { + $env:PATH = $PATH_BACKUP + return ([psobject]@{ + IsInstalled = $false + IsPreRelease = $false + }) + } + } +} \ No newline at end of file From a27fd9e348404ec894544f30e231cf71a56ea34f Mon Sep 17 00:00:00 2001 From: CorpoC Date: Tue, 24 May 2022 15:15:14 +0100 Subject: [PATCH 3/7] refac: ternary for if --- PSDepend2/Private/Get-InstalledTerraformVersion.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSDepend2/Private/Get-InstalledTerraformVersion.ps1 b/PSDepend2/Private/Get-InstalledTerraformVersion.ps1 index 4b82759..06f4c8d 100644 --- a/PSDepend2/Private/Get-InstalledTerraformVersion.ps1 +++ b/PSDepend2/Private/Get-InstalledTerraformVersion.ps1 @@ -23,7 +23,7 @@ function Get-InstalledTerraformVersion { Version = "{0}{1}" -f $VersionCore, $PreReleaseTag VersionCore = $VersionCore PreRelease = $PreRelease - IsPreRelease = ($null -ne $PreRelease ? $true : $false) + IsPreRelease = if ($null -ne $PreRelease) { $true } else { $false } }) } else { From bdd908c335562c2d77d7129479113536d8f1ff48 Mon Sep 17 00:00:00 2001 From: CorpoC Date: Wed, 25 May 2022 08:59:02 +0100 Subject: [PATCH 4/7] refac: syntax for ps5.1 incl rename of ToInstall --- PSDepend2/PSDependScripts/Terraform.ps1 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/PSDepend2/PSDependScripts/Terraform.ps1 b/PSDepend2/PSDependScripts/Terraform.ps1 index 94aea71..e87e9f0 100644 --- a/PSDepend2/PSDependScripts/Terraform.ps1 +++ b/PSDepend2/PSDependScripts/Terraform.ps1 @@ -16,7 +16,7 @@ The architecture of the binary to install. Defaults to amd64 .PARAMETER PSDependAction - Test or Install the module. Defaults to Install + Test or Install the module. Defaults to Install Test: Return true or false on whether the dependency is in place Install: Install the dependency @@ -87,8 +87,8 @@ if (-not $Version) { throw "Input version does not match regex" } -$Platform = ((Get-OSEnvironment) -eq "MacOS" ? "darwin" : (Get-OSEnvironment)).ToLower() -$FileName = "terraform_{0}_{1}_{2}.zip" -f $Version, $Platform, $Architecture +$Platform = if ((Get-OSEnvironment) -eq "MacOS") { "darwin" } else { Get-OSEnvironment } +$FileName = "terraform_{0}_{1}_{2}.zip" -f $Version, $Platform.ToLower(), $Architecture $DownloadPath = Join-Path $env:TEMP $FileName if (-not $Dependency.target) { $Path = Get-Location @@ -100,19 +100,19 @@ else { if ($tf.IsInstalled) { if ($tf.Version -ne $Version) { Write-Verbose "Installed Terraform v$($tf.Version) does not match version v$($Version) required" - $ToInstall = $true + $InstallNeeded = $true } else { Write-Verbose "Terraform v$($tf.Version) installed" - $ToInstall = $false + $InstallNeeded = $false } } else { Write-Verbose "Terraform not found on path" - $ToInstall = $true + $InstallNeeded = $true } -if ($PSDependAction -eq "Install" -and $ToInstall -eq $true) { +if ($PSDependAction -eq "Install" -and $InstallNeeded) { if ($Source) { $URL = $Source } @@ -145,9 +145,9 @@ if ($PSDependAction -eq "Install" -and $ToInstall -eq $true) { return $true } -elseif ($PSDependAction -eq "Install" -and $ToInstall -eq $false) { +elseif ($PSDependAction -eq "Install" -and $InstallNeeded -eq $false) { return $true } elseif ($PSDependAction -eq "Test") { - return $ToInstall -eq $true ? $false : $true + return -not $InstallNeeded } \ No newline at end of file From c91aa1f8887948b8235b7f45653544c20b9823a1 Mon Sep 17 00:00:00 2001 From: CorpoC Date: Wed, 25 May 2022 14:05:41 +0100 Subject: [PATCH 5/7] refac: Expand-PSDependArchive internal function to cater for legacy and new ps versions --- PSDepend2/PSDependScripts/GitHub.ps1 | 14 ++-------- PSDepend2/PSDependScripts/Terraform.ps1 | 4 +-- PSDepend2/Private/Expand-PSDependArchive.ps1 | 27 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 PSDepend2/Private/Expand-PSDependArchive.ps1 diff --git a/PSDepend2/PSDependScripts/GitHub.ps1 b/PSDepend2/PSDependScripts/GitHub.ps1 index a19043a..cf4fb3c 100644 --- a/PSDepend2/PSDependScripts/GitHub.ps1 +++ b/PSDepend2/PSDependScripts/GitHub.ps1 @@ -456,18 +456,8 @@ if(($PSDependAction -contains 'Install') -and $ShouldInstall) return } - # Extract the zip file - if (($script:IsWindows) -and ($psEdition -eq 'Desktop') -and ($null -eq $(Get-Command -Name Expand-Archive))) - { - $ZipFile = (New-Object -com shell.application).NameSpace($OutFile) - $ZipDestination = (New-Object -com shell.application).NameSpace($OutPath) - $ZipDestination.CopyHere($ZipFile.Items()) - } - else - { - # If not on Windows "Expand-Archive" should be available as PS version 6 is considered minimum. - Expand-Archive $OutFile -DestinationPath $OutPath - } + # Use our internal implementation to cater for Windows PS 5.1 and below + pwsh 6+ + Expand-PSDependArchive -Path $OutFile -DestinationPath $OutPath # Remove the zip file Remove-Item $OutFile -Force -Confirm:$false diff --git a/PSDepend2/PSDependScripts/Terraform.ps1 b/PSDepend2/PSDependScripts/Terraform.ps1 index e87e9f0..27a8f3c 100644 --- a/PSDepend2/PSDependScripts/Terraform.ps1 +++ b/PSDepend2/PSDependScripts/Terraform.ps1 @@ -135,8 +135,8 @@ if ($PSDependAction -eq "Install" -and $InstallNeeded) { Write-Verbose "Version of zip found at $DownloadPath" } - $Out = Expand-Archive -Path $DownloadPath -DestinationPath $Path -Force -PassThru - Write-Verbose "Terraform installed to $Out" + Expand-PSDependArchive -Path $DownloadPath -DestinationPath $Path -Force + Write-Verbose "Terraform installed to $Path" if ($Dependency.AddToPath) { Write-Verbose "Setting PATH to`n$($Path, $env:PATH -join ';' | Out-String)" diff --git a/PSDepend2/Private/Expand-PSDependArchive.ps1 b/PSDepend2/Private/Expand-PSDependArchive.ps1 new file mode 100644 index 0000000..1753112 --- /dev/null +++ b/PSDepend2/Private/Expand-PSDependArchive.ps1 @@ -0,0 +1,27 @@ +function Expand-PSDependArchive { + [CmdletBinding()] + param ( + [String] + $Path, + + [String] + $DestinationPath, + + [Switch] + $Force + ) + + end { + # Use Windows unzip method as otherwise Expand-Archive exists and that runs on all platforms + if ($null -eq $(Get-Command -Name Expand-Archive -ErrorAction SilentlyContinue)) { + Write-Verbose "Extracting using legacy unzip method" + $ZipFile = (New-Object -com shell.application).NameSpace($Path) + $ZipDestination = (New-Object -com shell.application).NameSpace($DestinationPath) + $ZipDestination.CopyHere($ZipFile.Items()) + } + else { + Write-Verbose "Extracting using current Expand-Archive function" + Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force:$Force + } + } +} \ No newline at end of file From 60ccddbc197c466d00b2e75e8aed26c58fefe43b Mon Sep 17 00:00:00 2001 From: CorpoC Date: Fri, 27 May 2022 18:52:34 +0100 Subject: [PATCH 6/7] chore: logging --- PSDepend2/PSDependScripts/Terraform.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/PSDepend2/PSDependScripts/Terraform.ps1 b/PSDepend2/PSDependScripts/Terraform.ps1 index 27a8f3c..8ee9c5f 100644 --- a/PSDepend2/PSDependScripts/Terraform.ps1 +++ b/PSDepend2/PSDependScripts/Terraform.ps1 @@ -135,6 +135,7 @@ if ($PSDependAction -eq "Install" -and $InstallNeeded) { Write-Verbose "Version of zip found at $DownloadPath" } + Write-Verbose "Extracting [$DownloadPath] to [$Path]" Expand-PSDependArchive -Path $DownloadPath -DestinationPath $Path -Force Write-Verbose "Terraform installed to $Path" From c13be640c532151f6563c2243e23cc03a435dc98 Mon Sep 17 00:00:00 2001 From: CorpoC Date: Fri, 27 May 2022 18:56:18 +0100 Subject: [PATCH 7/7] fix: mock calls to Expand-PSDependArchive --- Tests/PSModuleGallery.Type.Tests.ps1 | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/Tests/PSModuleGallery.Type.Tests.ps1 b/Tests/PSModuleGallery.Type.Tests.ps1 index 0cd9ab2..f7fb185 100644 --- a/Tests/PSModuleGallery.Type.Tests.ps1 +++ b/Tests/PSModuleGallery.Type.Tests.ps1 @@ -1262,6 +1262,7 @@ InModuleScope ('{0}' -f $ENV:BHProjectName) { } } Mock Get-InstalledTerraformVersion {} + Mock Expand-PSDependArchive {} $Dependencies = @(Get-Dependency @Verbose -Path "$TestDepends\terraform.depend.psd1") @@ -1273,32 +1274,9 @@ InModuleScope ('{0}' -f $ENV:BHProjectName) { $Results = Invoke-PSDepend @Verbose -Path "$TestDepends\terraform.depend.psd1" -Force It 'Invokes the Terraform dependency type' { - Assert-MockCalled Get-WebFile -Times 0 -Exactly - Assert-MockCalled Get-InstalledTerraformVersion -Times 1 -Exactly - } - } - - Context 'Installs dependency' { - Mock Get-WebFile { - [pscustomobject]@{ - PSB = $PSBoundParameters - Arg = $Args - } - } - Mock Get-InstalledTerraformVersion {} - - $Dependencies = @(Get-Dependency @Verbose -Path "$TestDepends\terraform.depend.psd1") - - It 'Parses the Terraform dependency type' { - $Dependencies.count | Should be 1 - $Dependencies[0].DependencyType | Should be 'Terraform' - } - - $Results = Invoke-PSDepend @Verbose -Path "$TestDepends\terraform.depend.psd1" -Force - - It 'Invokes the Terraform dependency type' { - Assert-MockCalled Get-WebFile -Times 0 -Exactly + Assert-MockCalled Get-WebFile -Times 1 -Exactly Assert-MockCalled Get-InstalledTerraformVersion -Times 1 -Exactly + Assert-MockCalled Expand-PSDependArchive -Times 1 -Exactly } }