Files
PSProxmoxVE/.github/workflows/unit-tests.yml
T
Clint Branham 68dadbfdc0 fix: remediate findings F045, F047, F048, F064, F070, F071, F076-F079
Phase 1 — Trivial fixes:
- F071: Add Uri.EscapeDataString to GetPveTemplateCmdlet node path
- F077: Add ValidateRange(100, 999999999) to GetPveTaskListCmdlet.VmId
- F076: Create .github/dependabot.yml (nuget + github-actions, weekly)
- F079: Fix unit-tests.yml dotnet SDK from 9.0.x to 10.0.x
- F048: Mark wont_fix — sync-over-async accepted for PS 5.1 compat

Phase 2 — Framework targeting (D009 compliance):
- F047: Reduce publishable csproj to netstandard2.0 only, remove all
  #if NET48/NETSTANDARD2_0 conditionals from PveHttpClient.cs,
  restructure build.yml for netstandard2.0 publish + net10.0/net48 tests
- F064: Resolved by F047 — SMA 7.5.0 ItemGroup removed with net10.0 TFM
- F070: Add PS 5.1 smoke-test job to publish.yml (windows-latest)

Phase 3 — IPveHttpClient interface extraction (F045):
- Extract IPveHttpClient interface from PveHttpClient
- Add constructor injection to all 14 service classes
- Services use injected client when available, create+dispose when not

Phase 4 — Service unit tests (F078):
- 196 new xUnit tests across 10 service test files
- All services tested via Moq-mocked IPveHttpClient
- Total test count: 382 (was 186)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 13:51:37 -05:00

158 lines
5.5 KiB
YAML

name: Unit Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
# ── Build module artifacts (only job that needs .NET SDK) ──────────
build:
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
framework: net48
- os: windows-latest
framework: netstandard2.0
- os: ubuntu-latest
framework: netstandard2.0
steps:
- uses: actions/checkout@v5
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- name: Build module
run: dotnet publish src/PSProxmoxVE/PSProxmoxVE.csproj --configuration Release --framework ${{ matrix.framework }} --output ./publish/${{ matrix.framework }}
- name: Clean publish output for PS module loading
shell: bash
run: rm -f ./publish/${{ matrix.framework }}/*.deps.json ./publish/${{ matrix.framework }}/*.runtimeconfig.json
- name: Upload module artifact
uses: actions/upload-artifact@v7
with:
name: module-${{ matrix.framework }}-${{ matrix.os }}
path: ./publish/${{ matrix.framework }}/
# ── Pester tests (no .NET SDK — just PowerShell + Pester) ─────────
pester-tests:
needs: build
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
ps_version: '5.1'
framework: net48
artifact_os: windows-latest
shell: powershell
- os: windows-latest
ps_version: '7.5'
framework: netstandard2.0
artifact_os: windows-latest
shell: pwsh
- os: ubuntu-latest
ps_version: '7.5'
framework: netstandard2.0
artifact_os: ubuntu-latest
shell: pwsh
- os: macos-latest
ps_version: '7.5'
framework: netstandard2.0
artifact_os: ubuntu-latest
shell: pwsh
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- name: Download module artifact
uses: actions/download-artifact@v8
with:
name: module-${{ matrix.framework }}-${{ matrix.artifact_os }}
path: ./publish/${{ matrix.framework }}/
- name: Install Pester 5 (PS 5.1)
if: matrix.ps_version == '5.1'
shell: powershell
run: |
Install-Module -Name Pester -MinimumVersion 5.0 -Force -Scope CurrentUser -SkipPublisherCheck
- name: Install Pester 5 (PS 7.x)
if: matrix.ps_version != '5.1'
shell: pwsh
run: |
Install-Module -Name Pester -MinimumVersion 5.0 -Force -Scope CurrentUser
- name: Copy module to module path (PS 5.1)
if: matrix.ps_version == '5.1'
shell: powershell
run: |
$modulePath = "$env:USERPROFILE\Documents\WindowsPowerShell\Modules\PSProxmoxVE"
New-Item -ItemType Directory -Path $modulePath -Force | Out-Null
Copy-Item -Path .\publish\${{ matrix.framework }}\* -Destination $modulePath -Recurse -Force
- name: Copy module to module path (PS 7.x, Windows)
if: matrix.ps_version != '5.1' && matrix.os == 'windows-latest'
shell: pwsh
run: |
$modulePath = "$env:USERPROFILE\Documents\PowerShell\Modules\PSProxmoxVE"
New-Item -ItemType Directory -Path $modulePath -Force | Out-Null
Copy-Item -Path .\publish\${{ matrix.framework }}\* -Destination $modulePath -Recurse -Force
- name: Copy module to module path (PS 7.x, non-Windows)
if: matrix.ps_version != '5.1' && matrix.os != 'windows-latest'
shell: pwsh
run: |
$modulePath = "$HOME/.local/share/powershell/Modules/PSProxmoxVE"
New-Item -ItemType Directory -Path $modulePath -Force | Out-Null
Copy-Item -Path ./publish/${{ matrix.framework }}/* -Destination $modulePath -Recurse -Force
- name: Run Pester tests (PS 5.1)
if: matrix.ps_version == '5.1'
shell: powershell
run: |
Import-Module Pester -MinimumVersion 5.0
$config = New-PesterConfiguration
$config.Run.Path = "tests/PSProxmoxVE.Tests"
$config.Run.Exit = $true
$config.Filter.ExcludeTag = @("Integration")
$config.Output.Verbosity = "Detailed"
$config.TestResult.Enabled = $true
$config.TestResult.OutputFormat = "NUnitXml"
$config.TestResult.OutputPath = "TestResults/pester-results.xml"
Invoke-Pester -Configuration $config
- name: Run Pester tests (PS 7.x)
if: matrix.ps_version != '5.1'
shell: pwsh
run: |
Import-Module Pester -MinimumVersion 5.0
$config = New-PesterConfiguration
$config.Run.Path = "tests/PSProxmoxVE.Tests"
$config.Run.Exit = $true
$config.Filter.ExcludeTag = @("Integration")
$config.Output.Verbosity = "Detailed"
$config.TestResult.Enabled = $true
$config.TestResult.OutputFormat = "NUnitXml"
$config.TestResult.OutputPath = "TestResults/pester-results.xml"
Invoke-Pester -Configuration $config
- name: Upload test results
if: always()
uses: actions/upload-artifact@v7
with:
name: pester-results-${{ matrix.os }}-ps${{ matrix.ps_version }}
path: TestResults/