81 lines
3.1 KiB
PowerShell
81 lines
3.1 KiB
PowerShell
Describe 'Install-IPerf3' {
|
|
BeforeAll {
|
|
function Uninstall-IPerf3 {
|
|
param (
|
|
[string]$DestinationPath = 'C:\Program Files\iPerf3'
|
|
)
|
|
|
|
# Stop and remove the service if it exists
|
|
if (Get-Service -Name iperf3server -ErrorAction SilentlyContinue) {
|
|
Stop-Service -Name iperf3server -Force
|
|
Remove-Service -Name iperf3server
|
|
}
|
|
|
|
# Remove the installation directory
|
|
if (Test-Path -Path $DestinationPath) {
|
|
Remove-Item -Path $DestinationPath -Recurse -Force
|
|
}
|
|
|
|
# Remove firewall rule
|
|
if ('Allow iPerf3' -in (Get-NetFirewallRule).DisplayName) {
|
|
Remove-NetFirewallRule -DisplayName 'Allow iPerf3'
|
|
}
|
|
|
|
# Remove from PATH
|
|
$env:PATH = $env:PATH -replace [regex]::Escape("$DestinationPath\"), ''
|
|
[Environment]::SetEnvironmentVariable("Path", $env:PATH, [System.EnvironmentVariableTarget]::Machine)
|
|
}
|
|
|
|
# Clean up any existing iPerf3 installation
|
|
Uninstall-IPerf3 -DestinationPath 'C:\Program Files\iPerf3'
|
|
|
|
# Load the Install-iPerf3 function
|
|
Set-Item function:Install-IPerf3 ([ScriptBlock]::Create((Get-Content -Raw $PSCommandPath.Replace('.Tests.ps1', '.ps1'))))
|
|
}
|
|
|
|
It 'Has the correct parameters' {
|
|
$params = (Get-Command Install-iPerf3).Parameters
|
|
|
|
$params.ContainsKey('DestinationPath') | Should -Be $true
|
|
$params['DestinationPath'].ParameterType.Name | Should -Be 'String'
|
|
|
|
$params.ContainsKey('ServerService') | Should -Be $true
|
|
$params['ServerService'].ParameterType.Name | Should -Be 'SwitchParameter'
|
|
}
|
|
|
|
Context 'Without ServerService parameter' {
|
|
It 'Should download and install iPerf3 without errors' {
|
|
{ Install-iPerf3 -DestinationPath 'C:\Program Files\iPerf3' } | Should -Not -Throw
|
|
}
|
|
|
|
It 'Should add iPerf3 to the system PATH' {
|
|
$env:PATH | Should -Match 'C:\\Program Files\\iPerf3\\'
|
|
}
|
|
|
|
It 'Should create the iPerf3 installation directory' {
|
|
Test-Path -Path 'C:\Program Files\iPerf3' | Should -Be $true
|
|
}
|
|
|
|
It 'Should create the iPerf3 executable in the installation directory' {
|
|
Test-Path -Path 'C:\Program Files\iPerf3\iperf3.exe' | Should -Be $true
|
|
}
|
|
|
|
It 'Should add a firewall rule for iPerf3' {
|
|
$firewallRule = Get-NetFirewallRule -DisplayName 'Allow iPerf3' -ErrorAction SilentlyContinue
|
|
$firewallRule | Should -Not -Be $null
|
|
}
|
|
}
|
|
|
|
Context 'With ServerService parameter' {
|
|
It 'Should install iPerf3 as a Windows service when ServerService is specified' {
|
|
{ Install-iPerf3 -DestinationPath 'C:\Program Files\iPerf3' -ServerService } | Should -Not -Throw
|
|
$service = Get-Service -Name iperf3server -ErrorAction SilentlyContinue
|
|
$service | Should -Not -Be $null
|
|
$service.Status | Should -Be 'Running'
|
|
}
|
|
}
|
|
|
|
AfterAll {
|
|
Uninstall-IPerf3 -DestinationPath 'C:\Program Files\iPerf3'
|
|
}
|
|
} |