microsoft/hve-core
Publicmirrored from https://github.com/microsoft/hve-coreAvailable
.github/skills/installer/hve-core-installer/tests/validate-extension.Tests.ps1
76lines · modecode
| 1 | #Requires -Modules Pester |
| 2 | # Copyright (c) Microsoft Corporation. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | |
| 5 | Describe 'validate-extension' -Tag 'Unit' { |
| 6 | BeforeAll { |
| 7 | $script:scriptPath = Join-Path $PSScriptRoot '../scripts/validate-extension.ps1' |
| 8 | $script:testRoot = Join-Path ([System.IO.Path]::GetTempPath()) "hve-test-valext-$([guid]::NewGuid().ToString('N'))" |
| 9 | New-Item -ItemType Directory -Path $script:testRoot -Force | Out-Null |
| 10 | } |
| 11 | |
| 12 | AfterAll { |
| 13 | if (Test-Path $script:testRoot) { |
| 14 | Remove-Item $script:testRoot -Recurse -Force -ErrorAction SilentlyContinue |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | Context 'Extension installed' { |
| 19 | It 'Reports EXTENSION_INSTALLED=True when extension is listed' { |
| 20 | # Create a mock script that simulates the code CLI |
| 21 | $mockPath = Join-Path $script:testRoot 'mock-code-found.ps1' |
| 22 | @' |
| 23 | if ($args -contains '--show-versions') { |
| 24 | 'ms-vscode.powershell@2024.1.0' |
| 25 | 'ise-hve-essentials.hve-core@3.0.2' |
| 26 | 'github.copilot@1.0.0' |
| 27 | } else { |
| 28 | 'ms-vscode.powershell' |
| 29 | 'ise-hve-essentials.hve-core' |
| 30 | 'github.copilot' |
| 31 | } |
| 32 | '@ | Set-Content $mockPath |
| 33 | |
| 34 | $output = & $script:scriptPath -CodeCli $mockPath 6>&1 | Out-String |
| 35 | |
| 36 | $output | Should -Match 'EXTENSION_INSTALLED=True' |
| 37 | } |
| 38 | |
| 39 | It 'Reports extension version when available' { |
| 40 | $mockPath = Join-Path $script:testRoot 'mock-code-version.ps1' |
| 41 | @' |
| 42 | if ($args -contains '--show-versions') { |
| 43 | 'ise-hve-essentials.hve-core@3.0.2' |
| 44 | } else { |
| 45 | 'ise-hve-essentials.hve-core' |
| 46 | } |
| 47 | '@ | Set-Content $mockPath |
| 48 | |
| 49 | $output = & $script:scriptPath -CodeCli $mockPath 6>&1 | Out-String |
| 50 | |
| 51 | $output | Should -Match '3\.0\.2' |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | Context 'Extension not installed' { |
| 56 | It 'Reports EXTENSION_INSTALLED=False when extension is not listed' { |
| 57 | $mockPath = Join-Path $script:testRoot 'mock-code-notfound.ps1' |
| 58 | @' |
| 59 | 'ms-vscode.powershell' |
| 60 | 'github.copilot' |
| 61 | '@ | Set-Content $mockPath |
| 62 | |
| 63 | $output = & $script:scriptPath -CodeCli $mockPath 6>&1 | Out-String |
| 64 | |
| 65 | $output | Should -Match 'EXTENSION_INSTALLED=False' |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | Context 'Default codeCli' { |
| 70 | It 'Has a default value for CodeCli parameter' { |
| 71 | $param = (Get-Command $script:scriptPath).Parameters['CodeCli'] |
| 72 | $param | Should -Not -BeNullOrEmpty |
| 73 | $param.Attributes | Where-Object { $_ -is [System.Management.Automation.ParameterAttribute] } | Should -Not -BeNullOrEmpty |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |