mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-10 14:26:52 +00:00
12874d168d
Split the 1544-line Integration.Tests.ps1 into 18 focused test files with numeric prefixes for execution ordering. New shared helper (_IntegrationHelper.ps1): - Credential-based auth (root@pam) instead of API tokens - Skip helpers for env var checks - Resource discovery (Find-TestVm) for cross-file dependencies - Register-TestResource for env-var state passing between files Files created: 00_Connection, 01_Nodes, 02_Users, 03_Storage, 03a_SharedStorage, 04_Network, 05_SDN, 06_VMs, 07_Snapshots, 08_Templates, 09_CloudInit, 10_Containers, 11_LinuxVM, 12_OVA, 13_Firewall, 14_Backup, 15_Tasks, 99_Cleanup Key changes: - All tests use root@pam credentials (not API tokens) - Each file self-contained with own BeforeAll/AfterAll cleanup - Token CRUD tests now idempotent (remove-before-create) - 99_Cleanup is safety-net for any leftover pester-* resources - SharedStorage renamed to 03a_SharedStorage Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
156 lines
5.1 KiB
PowerShell
156 lines
5.1 KiB
PowerShell
#Requires -Module Pester
|
|
|
|
BeforeAll {
|
|
. $PSScriptRoot/_IntegrationHelper.ps1
|
|
Connect-TestPve
|
|
}
|
|
|
|
AfterAll {
|
|
if (-not $script:SkipReason) {
|
|
# Clean up users created during this file
|
|
foreach ($userId in @('pester-user@pam', 'pester-tokenuser@pam', 'pester-permuser@pam')) {
|
|
try { Remove-PveUser -UserId $userId -Confirm:$false -ErrorAction SilentlyContinue } catch { }
|
|
}
|
|
# Clean up roles
|
|
try { Remove-PveRole -RoleId 'PesterTestRole' -Confirm:$false -ErrorAction SilentlyContinue } catch { }
|
|
}
|
|
Disconnect-TestPve
|
|
}
|
|
|
|
Describe 'Users — Integration' -Tag 'Integration' {
|
|
Context 'User CRUD' {
|
|
It 'Should create a new user' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
{ New-PveUser -UserId 'pester-user@pam' -ErrorAction Stop } |
|
|
Should -Not -Throw
|
|
}
|
|
|
|
It 'Should list users and find the new user' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
$users = Get-PveUser
|
|
$users | Should -Not -BeNullOrEmpty
|
|
$users | Where-Object { $_.UserId -eq 'pester-user@pam' } |
|
|
Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Should update user properties' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
{ Set-PveUser -UserId 'pester-user@pam' `
|
|
-Comment 'Updated by Pester integration test' `
|
|
-ErrorAction Stop } | Should -Not -Throw
|
|
|
|
$user = Get-PveUser | Where-Object { $_.UserId -eq 'pester-user@pam' }
|
|
$user.Comment | Should -Be 'Updated by Pester integration test'
|
|
}
|
|
|
|
It 'Should remove the user' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
{ Remove-PveUser -UserId 'pester-user@pam' -Confirm:$false -ErrorAction Stop } |
|
|
Should -Not -Throw
|
|
|
|
$users = Get-PveUser
|
|
$users | Where-Object { $_.UserId -eq 'pester-user@pam' } |
|
|
Should -BeNullOrEmpty
|
|
}
|
|
}
|
|
|
|
Context 'Role CRUD' {
|
|
It 'Should create a new role' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
{ New-PveRole -RoleId 'PesterTestRole' `
|
|
-Privileges 'VM.Audit,VM.Console' `
|
|
-ErrorAction Stop } | Should -Not -Throw
|
|
}
|
|
|
|
It 'Should list roles and find the new role' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
$roles = Get-PveRole
|
|
$roles | Should -Not -BeNullOrEmpty
|
|
$roles | Where-Object { $_.RoleId -eq 'PesterTestRole' } |
|
|
Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Should remove the role' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
{ Remove-PveRole -RoleId 'PesterTestRole' -Confirm:$false -ErrorAction Stop } |
|
|
Should -Not -Throw
|
|
}
|
|
}
|
|
|
|
Context 'API Token CRUD' {
|
|
BeforeAll {
|
|
if ($null -eq $script:SkipReason) {
|
|
# Idempotent setup: remove existing token/user first if they exist
|
|
try { Remove-PveApiToken -UserId 'pester-tokenuser@pam' -TokenId 'pester-token' -Confirm:$false -ErrorAction SilentlyContinue } catch { }
|
|
try { Remove-PveUser -UserId 'pester-tokenuser@pam' -Confirm:$false -ErrorAction SilentlyContinue } catch { }
|
|
|
|
New-PveUser -UserId 'pester-tokenuser@pam' -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
|
|
It 'Should create an API token' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
$result = New-PveApiToken `
|
|
-UserId 'pester-tokenuser@pam' `
|
|
-TokenId 'pester-token' `
|
|
-ErrorAction Stop
|
|
|
|
$result | Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Should list API tokens for the user' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
$tokens = Get-PveApiToken -UserId 'pester-tokenuser@pam'
|
|
$tokens | Should -Not -BeNullOrEmpty
|
|
$tokens | Where-Object { $_.TokenId -eq 'pester-token' } |
|
|
Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Should remove the API token' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
{ Remove-PveApiToken `
|
|
-UserId 'pester-tokenuser@pam' `
|
|
-TokenId 'pester-token' `
|
|
-Confirm:$false `
|
|
-ErrorAction Stop } | Should -Not -Throw
|
|
}
|
|
}
|
|
|
|
Context 'Permissions' {
|
|
BeforeAll {
|
|
if ($null -eq $script:SkipReason) {
|
|
# Idempotent setup
|
|
try { Remove-PveUser -UserId 'pester-permuser@pam' -Confirm:$false -ErrorAction SilentlyContinue } catch { }
|
|
New-PveUser -UserId 'pester-permuser@pam' -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
|
|
It 'Should list permissions' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
{ Get-PvePermission -ErrorAction Stop } | Should -Not -Throw
|
|
}
|
|
|
|
It 'Should set a permission' {
|
|
if (Skip-IfNoTarget) { return }
|
|
|
|
{ Set-PvePermission `
|
|
-Path '/' `
|
|
-Role 'PVEAuditor' `
|
|
-UgId 'pester-permuser@pam' `
|
|
-Type 'user' `
|
|
-ErrorAction Stop } | Should -Not -Throw
|
|
}
|
|
}
|
|
}
|