From 9a6b91f3ed01d456ba09df96a0e4f469848adf22 Mon Sep 17 00:00:00 2001 From: Corbin Date: Fri, 23 Jan 2026 10:32:31 -0500 Subject: [PATCH] Add tests for iPerf3 install --- windows/Install-iPerf3.Tests.ps1 | 67 ++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 windows/Install-iPerf3.Tests.ps1 diff --git a/windows/Install-iPerf3.Tests.ps1 b/windows/Install-iPerf3.Tests.ps1 new file mode 100644 index 0000000..d42f8a6 --- /dev/null +++ b/windows/Install-iPerf3.Tests.ps1 @@ -0,0 +1,67 @@ +Describe 'Install-IPerf3' { + BeforeAll { + Set-Item function:Install-IPerf3 ([ScriptBlock]::Create((Get-Content -Raw 'windows\Install-iPerf3.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 + } + + AfterAll { + # Clean up any existing iPerf3 installation + if (Get-Service -Name iperf3server -ErrorAction SilentlyContinue) { + Stop-Service -Name iperf3server -Force + Remove-Service -Name iperf3server + } + Remove-Item -Path 'C:\Program Files\iPerf3' -Recurse -Force -ErrorAction SilentlyContinue + Remove-NetFirewallRule -DisplayName 'Allow iPerf3' -ErrorAction SilentlyContinue + } + } + + 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 { + # Clean up any existing iPerf3 installation + if (Get-Service -Name iperf3server -ErrorAction SilentlyContinue) { + Stop-Service -Name iperf3server -Force + Remove-Service -Name iperf3server + } + Remove-Item -Path 'C:\Program Files\iPerf3' -Recurse -Force -ErrorAction SilentlyContinue + Remove-NetFirewallRule -DisplayName 'Allow iPerf3' -ErrorAction SilentlyContinue + } + } +} \ No newline at end of file