Skip to content

Commit

Permalink
try on pwsh (#61)
Browse files Browse the repository at this point in the history
* try on pwsh

* update pester version

* try without mac os

* try using my own random files

* use backslash

* debug env

* use .net method to get temp path

* debug folder creation

* need -Force for hidden folders

* do not fail fast

* print out env

* need a force delete

hidden folders need -force parameter on linux/mac

* change get-item().delete to remove-item

else the cmd.exe was used for deletion

* add a test around the link

* change handling of links on non windows platforms

* can not use $isWindows

* use $env:OS for determining windows

* use force for finding hidden path

* use new-item to create symlink

* revert old "if" change

* remove unused -force

* use new-item for linking
  • Loading branch information
ronnypolley authored Oct 9, 2024
1 parent d5f6a01 commit 5ecb36b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
60 changes: 31 additions & 29 deletions .github/workflows/pester.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
name: Pester
on: [push, pull_request, workflow_dispatch]
jobs:
# test-pwsh:
# strategy:
# matrix:
# platform: [ubuntu-latest, macos-latest, windows-latest]
# runs-on: ${{ matrix.platform }}
# steps:
# - uses: actions/checkout@v4
# - name: Run Pester tests (pwsh)
# run: |
# Write-host $PSVersionTable.PSVersion.Major $PSVersionTable.PSRemotingProtocolVersion.Minor
# Install-Module -Name Pester -RequiredVersion 5.2.2 -Confirm:$false -Force
# Set-Location -Path .\Tests\
# Invoke-Pester
# if ($Error[0].Fullyqualifiederrorid -eq 'PesterAssertionFailed') {exit 1}
# shell: pwsh
test-pwsh:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Run Pester tests (pwsh)
run: |
dir env:
Write-host $PSVersionTable.PSVersion.Major $PSVersionTable.PSRemotingProtocolVersion.Minor
Install-Module -Name Pester -RequiredVersion 5.6.1 -Confirm:$false -Force
Set-Location -Path .\Tests\
Invoke-Pester
if ($Error[0].Fullyqualifiederrorid -eq 'PesterAssertionFailed') {exit 1}
shell: pwsh

test-posh:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Run Pester tests (PowerShell)
run: |
Write-host $PSVersionTable.PSVersion.Major $PSVersionTable.PSRemotingProtocolVersion.Minor
Install-Module -Name Pester -RequiredVersion 5.6.1 -Confirm:$false -Force
$pesterConfig = New-PesterConfiguration
$pesterConfig.CodeCoverage.Enabled = $true
Set-Location -Path .\Tests\
Invoke-Pester -Configuration $pesterConfig
if ($Error[0].Fullyqualifiederrorid -eq 'PesterAssertionFailed') {exit 1}
shell: powershell
test-posh:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Run Pester tests (PowerShell)
run: |
Write-host $PSVersionTable.PSVersion.Major $PSVersionTable.PSRemotingProtocolVersion.Minor
Install-Module -Name Pester -RequiredVersion 5.6.1 -Confirm:$false -Force
$pesterConfig = New-PesterConfiguration
$pesterConfig.CodeCoverage.Enabled = $true
Set-Location -Path .\Tests\
Invoke-Pester -Configuration $pesterConfig
if ($Error[0].Fullyqualifiederrorid -eq 'PesterAssertionFailed') {exit 1}
shell: powershell
3 changes: 1 addition & 2 deletions PSSDKMan/Utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ function Set-Junction-Via-Mklink($Link, $Target) {
if ( Test-Path $Link ) {
(Get-Item $Link).Delete()
}

Invoke-Expression -Command "cmd.exe /c mklink /J '$Link' '$Target'" | Out-Null
New-Item -Path $Link -ItemType SymbolicLink -Value $Target | Out-Null
}

function Get-Online-Mode() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Commands.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Describe 'sdk' {
BeforeAll {
$Script:PSDK_FORCE_OFFLINE = $true
Mock-PSDK-Dir
Remove-Item $Global:PSDK_DIR -Recurse
Remove-Item $Global:PSDK_DIR -Recurse -Force
Mock Initialize-Posh-SDK -verifiable
Mock Initialize-Candidate-Cache -verifiable
Mock Show-Help
Expand Down
9 changes: 6 additions & 3 deletions Tests/TestUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ function Mock-Api-Call-Grails-1.1.1-Available($Available) {

function Mock-PSDK-Dir {
$Script:backup_PSDK_DIR = $Global:PSDK_DIR
New-Item -ItemType Directory "TestDrive:.posh-sdk" | Out-Null
$Global:PSDK_DIR = (Get-Item "TestDrive:.posh-sdk").FullName
$randomName = (-join ((65..90) + (97..122) | Get-Random -Count 5 | % {[char]$_}))
$tempDir = [System.IO.Path]::GetTempPath()
$testPath = "$tempDir\$randomName"
New-Item -ItemType Directory "$testPath\.posh-sdk"
$Global:PSDK_DIR = (Get-Item "$testPath\.posh-sdk" -Force).FullName
New-Item -ItemType Directory "$Global:PSDK_DIR\grails" | Out-Null
}

Expand Down Expand Up @@ -54,4 +57,4 @@ function Mock-Dispatcher-Test([switch]$Offline) {

function Reset-Dispatcher-Test {
Reset-PSDK-Dir
}
}

0 comments on commit 5ecb36b

Please sign in to comment.