From 1a5ff2c7b2c73b348c7be017b6fe52d3a02ebb24 Mon Sep 17 00:00:00 2001 From: Scott McKendry <39483124+scottmckendry@users.noreply.github.com> Date: Mon, 20 May 2024 08:01:56 +1200 Subject: [PATCH] feat(tests):add Get-ReleaseAsset tests --- ps-arch-wsl/ps-arch-wsl.Tests.ps1 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ps-arch-wsl/ps-arch-wsl.Tests.ps1 diff --git a/ps-arch-wsl/ps-arch-wsl.Tests.ps1 b/ps-arch-wsl/ps-arch-wsl.Tests.ps1 new file mode 100644 index 0000000..b181b1b --- /dev/null +++ b/ps-arch-wsl/ps-arch-wsl.Tests.ps1 @@ -0,0 +1,29 @@ +BeforeAll { + Import-Module $PSScriptRoot/ps-arch-wsl.psm1 -Force +} + +Describe "Get-ReleaseAsset" { + It "Finds the release asset" { + InModuleScope ps-arch-wsl { + $foundAsset = Get-ReleaseAsset -Repository "yuk7/ArchWSL" -AssetFilter "cer" + $latestCertificateInTemp = Get-ChildItem $env:Temp | Where-Object { $_.FullName -like "*.cer" } | Sort-Object -Property CreationTime -Descending + $foundAsset | Should -Be $latestCertificateInTemp[0].FullName + } + } + + It "Can't find the release asset" { + InModuleScope ps-arch-wsl { + $repository = "yuk7/ArchWSL" + $filter = "someNonExistentExt" + { Get-ReleaseAsset -Repository $repository -AssetFilter $filter } | Should -Throw -ExpectedMessage "Failed to find an asset matching the filter '$filter' from the latest release of $repository." + } + } + + It "Can't find the repository" { + InModuleScope ps-arch-wsl { + $repository = "scottmckendry/norepositoryhere" + $filter = "doesntmatter" + { Get-ReleaseAsset -Repository $repository -AssetFilter $filter } | Should -Throw -ExpectedMessage "$repository doesn't exist or has no releases." + } + } +}