Skip to content

Commit

Permalink
chore(ci): update tests (#234)
Browse files Browse the repository at this point in the history
- Updates the basic tests to be generic and discoverable for pull requests.
- Tests that the module can be imported and that the manifest is well formed.
- Updated to Pester 5 syntax with detailed output.

Signed-off-by: Ryan Johnson <[email protected]>
  • Loading branch information
Ryan Johnson authored Sep 23, 2023
1 parent ef497eb commit d54ef12
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 50 deletions.
10 changes: 3 additions & 7 deletions .ci/pester.tests.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
BeforeAll {
Import-Module -Name "$PSScriptRoot/../PowerVCF.psd1" -Force -ErrorAction Stop
}

Describe -Tag:('ModuleValidation') 'Module Baseline Validation' {
Describe -Tag:('ModuleValidation') 'Module Basic Tests' {

It 'is present' {
$module = Get-Module PowerVCF
$module = Get-Module -Name $moduleName
$module | Should -Be $true
}

It ('passes Test-ModuleManifest') {
Test-ModuleManifest -Path:("$PSScriptRoot/../PowerVCF.psd1") | Should -Not -BeNullOrEmpty
Test-ModuleManifest -Path $moduleManifest | Should -Not -BeNullOrEmpty
$? | Should -Be $true
}
}
74 changes: 31 additions & 43 deletions .github/workflows/ci-module.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,42 @@
---
name: Module CI
name: Tests

on:
pull_request:
branches: [main]
branches: [develop]
paths:
- '**.psm1'
- '**.psd1'
- "**.psm1"
- "**.psd1"

jobs:
test-pwshcore-linux:
basic_tests:
strategy:
matrix:
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v3.5.3v
- name: Run Pester Tests (pwsh)
run: |
Write-Output $PSVersionTable.PSVersion.Major $PSVersionTable.PSRemotingProtocolVersion.Minor
Set-PSRepository psgallery -InstallationPolicy trusted
Install-Module -Name VMware.PowerCLI -confirm:$false -Force
Install-Module -Name Pester -confirm:$false -Force
Invoke-Pester -Path "./.ci/pester.tests.ps1" -EnableExit
shell: pwsh

# test-pwshcore-windows:
# strategy:
# matrix:
# platform: [windows-latest]
# runs-on: ${{ matrix.platform }}
# steps:
# - uses: actions/checkout@v3
# - name: Run Pester Tests (pwsh)
# run: |
# Write-Output $PSVersionTable.PSVersion.Major $PSVersionTable.PSRemotingProtocolVersion.Minor
# Set-PSRepository psgallery -InstallationPolicy trusted
# Install-Module -Name Pester -confirm:$false -Force
# Invoke-Pester -Path "./.ci/pester.test.ps1" -EnableExit
# shell: pwsh

# test-powershell-windows:
# runs-on: windows-latest
# steps:
# - uses: actions/checkout@v3
# - name: Run Pester Tests (Windows PowerShell)
# run: |
# Write-Output $PSVersionTable.PSVersion.Major $PSVersionTable.PSRemotingProtocolVersion.Minor
# Set-PSRepository psgallery -InstallationPolicy trusted
# Install-Module -Name Pester -Confirm:$false -Force
# Invoke-Pester -Path "./.ci/pester.tests.ps1" -EnableExit
# if ($Error[0].Fullyqualifiederrorid -eq 'PesterAssertionFailed') {exit 1}
# shell: powershell
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Run Basic Tests
working-directory: ${{ github.workspace }}
run: |
$moduleManifest = (Get-ChildItem -Path $env:GITHUB_WORKSPACE -Filter *.psd1).Name
if ($moduleManifest) {
Write-Output "SUCCESS: Manifest '$moduleManifest' found in '$env:GITHUB_WORKSPACE'."
} else {
Write-Output "FAILURE: Manifest not found in '$env:GITHUB_WORKSPACE'."
}
if ($moduleManifest -match '^(.*)\.psd1$') {
$moduleName = $Matches[1]
Write-Output "SUCCESS: Determining module name from manifest'$moduleManifest'."
} else {
Write-Error "FAILED: Determining module name from manifest '$moduleManifest'."
}
Import-Module -Name (Resolve-Path $moduleManifest).Path -Force -ErrorAction Stop
if (Get-Module -Name $moduleName) {
Write-Output "SUCCESS: Module '$moduleName' was imported."
} else {
Write-Error "FAILED: Module '$moduleName' was not imported."
}
Set-PSRepository psgallery -InstallationPolicy trusted
Install-Module -Name Pester -confirm:$false -Force
Invoke-Pester -Path "./.ci/pester.tests.ps1" -Output Detailed -PassThru
shell: pwsh
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Tests

on:
pull_request:
branches: [develop]
paths:
- "**.psm1"
- "**.psd1"

jobs:
basic_tests:
strategy:
matrix:
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Run Basic Tests
working-directory: ${{ github.workspace }}
run: |
$moduleManifest = (Get-ChildItem -Path $env:GITHUB_WORKSPACE -Filter *.psd1).Name
if ($moduleManifest) {
Write-Output "SUCCESS: Manifest '$moduleManifest' found in '$env:GITHUB_WORKSPACE'."
} else {
Write-Output "FAILURE: Manifest not found in '$env:GITHUB_WORKSPACE'."
}
if ($moduleManifest -match '^(.*)\.psd1$') {
$moduleName = $Matches[1]
Write-Output "SUCCESS: Determining module name from manifest'$moduleManifest'."
} else {
Write-Error "FAILED: Determining module name from manifest '$moduleManifest'."
}
Import-Module -Name (Resolve-Path $moduleManifest).Path -Force -ErrorAction Stop
if (Get-Module -Name $moduleName) {
Write-Output "SUCCESS: Module '$moduleName' was imported."
} else {
Write-Error "FAILED: Module '$moduleName' was not imported."
}
Set-PSRepository psgallery -InstallationPolicy trusted
Install-Module -Name Pester -confirm:$false -Force
Invoke-Pester -Path "./.ci/pester.tests.ps1" -Output Detailed -PassThru
shell: pwsh

0 comments on commit d54ef12

Please sign in to comment.