Compare commits

..

2 Commits

4 changed files with 89 additions and 25 deletions

View File

@ -42,8 +42,7 @@ begin {
$ServerServiceInstalled = $true
Write-Host 'Server service already installed.'
} else {
if (-not (Test-Path 'C:\Program Files\nssm') ) {
# if ('nssm' -notin $env:PATH) {
if (-not (Get-Command 'nssm.exe') ) {
throw 'NSSM is not installed. Please install NSSM before attempting to install the server service.'
}
}
@ -75,7 +74,7 @@ process {
Expand-Archive -Path $ArchivePath -DestinationPath $DestinationPath -Force
# Add the DestinationPath to Path system environment variable
if ($DestinationPath -notin $env:PATH) { [Environment]::SetEnvironmentVariable("Path", $env:Path + ";$DestinationPath\", [System.EnvironmentVariableTarget]::Machine) }
if ($DestinationPath -notin $env:PATH) { $env:PATH = $env:PATH + ";$DestinationPath\"; [Environment]::SetEnvironmentVariable("Path", $env:PATH, [System.EnvironmentVariableTarget]::Machine) }
# Add firewall rule allowing application executable
if ('Allow iPerf3' -notin (Get-NetFirewallRule).DisplayName) { New-NetFirewallRule -DisplayName 'Allow iPerf3' -Direction Inbound -Program $ExecutablePath -RemoteAddress Any -Profile Any -Action Allow }

View File

@ -0,0 +1,51 @@
Describe 'Install-WinAcme' {
BeforeAll {
function Uninstall-WinAcme {
param (
[string]$DestinationPath
)
# Remove the installation directory
if (Test-Path -Path $DestinationPath) {
Remove-Item -Path $DestinationPath -Recurse -Force
}
# Remove from PATH
$env:PATH = $env:PATH -replace [regex]::Escape("$DestinationPath\"), ''
[Environment]::SetEnvironmentVariable("Path", $env:PATH, [System.EnvironmentVariableTarget]::Machine)
}
# Clean up any existing win-acme installation
Uninstall-WinAcme -DestinationPath 'C:\Program Files\win-acme'
# Load the Install-WinAcme function
Set-Item function:Install-WinAcme ([ScriptBlock]::Create((Get-Content -Raw $PSCommandPath.Replace('.Tests.ps1', '.ps1'))))
}
It 'Has the correct parameters' {
$params = (Get-Command Install-WinAcme).Parameters
$params.ContainsKey('DestinationPath') | Should -Be $true
$params['DestinationPath'].ParameterType.Name | Should -Be 'String'
}
It 'Should download and install win-acme without errors' {
{ Install-WinAcme -DestinationPath 'C:\Program Files\win-acme' } | Should -Not -Throw
}
It 'Should add win-acme to the system PATH' {
$env:PATH | Should -Match 'C:\\Program Files\\win-acme\\'
}
It 'Should create the win-acme installation directory' {
Test-Path -Path 'C:\Program Files\win-acme' | Should -Be $true
}
It 'Should create the wacs executable in the installation directory' {
Test-Path -Path 'C:\Program Files\win-acme\wacs.exe' | Should -Be $true
}
AfterAll {
Uninstall-WinAcme -DestinationPath 'C:\Program Files\win-acme'
}
}

View File

@ -18,7 +18,7 @@ param (
begin {
# Prep
$Releases = (Invoke-WebRequest 'https://api.github.com/repos/win-acme/win-acme/releases').Content | ConvertFrom-Json | Where-Object { $_.prerelease -eq $false -and $_.draft -eq $false }
$Releases = (Invoke-WebRequest 'https://api.github.com/repos/win-acme/win-acme/releases' -UseBasicParsing).Content | ConvertFrom-Json | Where-Object { $_.prerelease -eq $false -and $_.draft -eq $false }
$ReleaseTag = ($Releases | Select-Object -First 1).tag_name
# $InstallerUrl = 'https://github.com/win-acme/win-acme/releases/download/v2.2.9.1701/win-acme.v2.2.9.1701.x64.pluggable.zip'
@ -50,7 +50,7 @@ process {
Expand-Archive -Path $ArchivePath -DestinationPath $DestinationPath -Force
# Add the DestinationPath to Path system environment variable
if ($DestinationPath -notin $env:PATH) { [Environment]::SetEnvironmentVariable("Path", $env:Path + ";$DestinationPath\", [System.EnvironmentVariableTarget]::Machine) }
if ($DestinationPath -notin $env:PATH) { $env:PATH = $env:PATH + ";$DestinationPath\"; [Environment]::SetEnvironmentVariable("Path", $env:PATH, [System.EnvironmentVariableTarget]::Machine) }
} catch {
throw "Failed installing application. $_"
}

View File

@ -1,6 +1,36 @@
Describe 'Install-IPerf3' {
BeforeAll {
Set-Item function:Install-IPerf3 ([ScriptBlock]::Create((Get-Content -Raw 'windows\Install-iPerf3.ps1')))
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' {
@ -34,16 +64,6 @@ Describe 'Install-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' {
@ -53,15 +73,9 @@ Describe 'Install-IPerf3' {
$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
}
Uninstall-IPerf3 -DestinationPath 'C:\Program Files\iPerf3'
}
}