Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Thilas committed Oct 28, 2023
1 parent 3826cfc commit 86bc67e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 37 deletions.
69 changes: 36 additions & 33 deletions .github/workflows/.common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ on:
type: string
default: ${{ github.workflow }}
test:
description: Test
description: Test update
type: boolean
force:
description: Force update
type: boolean
test_scripts:
description: JSON serialized list of Powershell scripts to test a package
test_cases:
description: |
List of test cases
- {title}
{script}
type: string

jobs:
Expand Down Expand Up @@ -117,30 +120,30 @@ jobs:
name: Packages

- name: Tests before install
if: inputs.test_scripts
if: inputs.test_cases
run: |
$results = $env:scripts -split "`r?`n" | Where-Object { $_ } | ForEach-Object {
if ($env:debug) {
$VerbosePreference = $DebugPreference = $InformationPreference = "Continue"
}
$script = $_
if ($env:debug) {
$VerbosePreference = $DebugPreference = $InformationPreference = "Continue"
}
$test_cases = $env:test_cases -split "^-\s+(.+)\s*$", 0, "Multiline"
for ($i = 1; $i -lt $test_cases.length - 1; $i += 2) {
try {
$out = @()
Invoke-Expression $script *>&1 | ForEach-Object { $out += $_ }
Invoke-Expression $test_cases[$i + 1] *>&1 | ForEach-Object { $out += $_ }
if ($LASTEXITCODE) { throw "Test failed." }
Write-Host "❌ $script"
"❌ {0}" -f $test_cases[$i] | Write-Host
$out | Out-Host
return $true
} catch {
Write-Host "✅ $script"
"✅ {0}" -f $test_cases[$i] | Write-Host
}
}
if ($results -contains $true) {
throw "Tests failed."
}
env:
debug: ${{ runner.debug }}
scripts: ${{ inputs.test_scripts }}
test_cases: ${{ inputs.test_cases }}

- name: Install package
run: |
Expand All @@ -166,20 +169,20 @@ jobs:
path: ${{ steps.information.outputs.path }}

- name: Tests after install
if: inputs.test_scripts
if: inputs.test_cases
run: |
$results = $env:scripts -split "`r?`n" | Where-Object { $_ } | ForEach-Object {
if ($env:debug) {
$VerbosePreference = $DebugPreference = $InformationPreference = "Continue"
}
$script = $_
if ($env:debug) {
$VerbosePreference = $DebugPreference = $InformationPreference = "Continue"
}
$test_cases = $env:test_cases -split "^-\s+(.+)\s*$", 0, "Multiline"
for ($i = 1; $i -lt $test_cases.length - 1; $i += 2) {
try {
$out = @()
Invoke-Expression $script *>&1 | ForEach-Object { $out += $_ }
Invoke-Expression $test_cases[$i + 1] *>&1 | ForEach-Object { $out += $_ }
if ($LASTEXITCODE) { throw "Test failed." }
Write-Host "✅ $script"
"✅ {0}" -f $test_cases[$i] | Write-Host
} catch {
Write-Host "❌ $script"
"❌ {0}" -f $test_cases[$i] | Write-Host
$out, $_ | Out-Host
return $true
}
Expand All @@ -189,7 +192,7 @@ jobs:
}
env:
debug: ${{ runner.debug }}
scripts: ${{ inputs.test_scripts }}
scripts: ${{ inputs.test_cases }}

- name: Uninstall package
# AirServer requires Wireless-Networking while uninstalling, feature not installed on GitHub agents
Expand All @@ -203,30 +206,30 @@ jobs:
timeout-minutes: 10

- name: Tests after uninstall
if: inputs.test_scripts
if: inputs.test_cases
run: |
$results = $env:scripts -split "`r?`n" | Where-Object { $_ } | ForEach-Object {
if ($env:debug) {
$VerbosePreference = $DebugPreference = $InformationPreference = "Continue"
}
$script = $_
if ($env:debug) {
$VerbosePreference = $DebugPreference = $InformationPreference = "Continue"
}
$test_cases = $env:test_cases -split "^-\s+(.+)\s*$", 0, "Multiline"
for ($i = 1; $i -lt $test_cases.length - 1; $i += 2) {
try {
$out = @()
Invoke-Expression $script *>&1 | ForEach-Object { $out += $_ }
Invoke-Expression $test_cases[$i + 1] *>&1 | ForEach-Object { $out += $_ }
if ($LASTEXITCODE) { throw "Test failed." }
Write-Host "❌ $script"
"❌ {0}" -f $test_cases[$i] | Write-Host
$out | Out-Host
return $true
} catch {
Write-Host "✅ $script"
"✅ {0}" -f $test_cases[$i] | Write-Host
}
}
if ($results -contains $true) {
throw "Tests failed."
}
env:
debug: ${{ runner.debug }}
scripts: ${{ inputs.test_scripts }}
scripts: ${{ inputs.test_cases }}

- name: Take failure screenshot
if: failure()
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/procexp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@ jobs:
with:
test: ${{ github.event_name == 'pull_request' || github.event.schedule == '0 4 * * *' || inputs.type == 'Test' }}
force: ${{ inputs.type == 'Force update' }}
test_cases: |
- Start procexp
procexp
$sw = [System.Diagnostics.Stopwatch]::StartNew()
while ($sw.ElapsedMilliseconds -lt 60000) {
if (Get-Process procexp* -ErrorAction SilentlyContinue | Where-Object MainWindowHandle -NE 0) {
return
}
Start-Sleep -Milliseconds 500
}
throw "Process start timed out."
- Close procexp
Get-Process procexp* | Should -Not -BeNullOrEmpty; Stop-Process -Name procexp*
secrets: inherit
4 changes: 3 additions & 1 deletion .github/workflows/psinfo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ jobs:
with:
test: ${{ github.event_name == 'pull_request' || github.event.schedule == '0 4 * * *' || inputs.type == 'Test' }}
force: ${{ inputs.type == 'Force update' }}
test_scripts: psinfo
test_cases: |
- Run psinfo
psinfo
secrets: inherit
8 changes: 5 additions & 3 deletions .github/workflows/sabnzbd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ jobs:
with:
test: ${{ github.event_name == 'pull_request' || github.event.schedule == '0 4 * * *' || inputs.type == 'Test' }}
force: ${{ inputs.type == 'Force update' }}
test_scripts: |
Get-Service SABnzbd | ForEach-Object Status | Should -Be "Running"
Invoke-WebRequest "http://127.0.0.1:8080/" -UseBasicParsing
test_cases: |
- Check SABnzbd service
Get-Service SABnzbd | ForEach-Object Status | Should -Be "Running"
- Test web interface
Invoke-WebRequest "http://127.0.0.1:8080/" -UseBasicParsing
secrets: inherit

0 comments on commit 86bc67e

Please sign in to comment.