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 } } }