tests/PortProxy.tests.ps1
Describe 'PortProxy' { BeforeAll { Get-PortProxy -ListenAddress 127.0.0.1 -ListenPort 99 -ErrorAction "SilentlyContinue" | Remove-PortProxy Add-PortProxy -ListenAddress 127.0.0.1 -ListenPort 99 -ConnectAddress 127.0.0.1 -ConnectPort 100 } AfterAll { Get-PortProxy -ListenPort 99 -ListenAddress 127.0.0.1 -ErrorAction SilentlyContinue | Remove-PortProxy -Confirm:$false } It 'can get portproxy entries' { $proxies = @(Get-PortProxy) $proxies.Count | Should -BeGreaterThan 0 } It 'can get a single portproxy entry' { $proxies = @(Get-PortProxy -ListenAddress 127.0.0.1 -ListenPort 99 -ConnectAddress 127.0.0.1 -ConnectPort 100) $proxies.Count | Should -BeExactly 1 } It 'fails when an entry is not found' { { Get-PortProxy -ListenAddress 127.0.0.1 -ListenPort 100 -ErrorAction Stop } | Should -Throw } It 'fails when removing a non-existing portproxy' { { Remove-PortProxy -ListenPort 101 -ListenAddress 127.0.0.1 -ErrorAction Stop -Confirm:$false } | Should -Throw } It 'succeeds at removing an existing portproxy' { Remove-PortProxy -ListenPort 99 -ListenAddress 127.0.0.1 -Confirm:$false (Get-PortProxy -ListenPort 99 -ListenAddress 127.0.0.1 -ErrorAction SilentlyContinue) | Should -BeNullOrEmpty } } |