-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert tests from rspec to pester (#290)
We've had a lot of trouble fighting with ruby - mainly around rubygems. It's just not fun. Combine that with unfamiliarity and a "why are we using ruby for tests when the rest of the code is in powershell" disconnect, it makes a lot of sense to use Pester as our test framework instead.
- Loading branch information
1 parent
fddf416
commit fc9cfd5
Showing
78 changed files
with
3,432 additions
and
1,549 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function Get-EnvironmentDetails { | ||
[CmdletBinding()] | ||
[OutputType([HashTable])] | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusServerUrl, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusApiKey, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$EnvironmentName, | ||
[Parameter(Mandatory=$false)] | ||
[string] | ||
$SpaceId | ||
) | ||
|
||
$serverSupportsSpaces = Test-ServerSupportsSpaces $OctopusServerUrl | ||
if ($serverSupportsSpaces -and (-not [string]::IsNullOrEmpty($SpaceId))) { | ||
$spaceFragment = "$SpaceId/" | ||
} | ||
|
||
[PSCustomObject]$environment = Get-EnvironmentViaApi -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -EnvironmentName $EnvironmentName -SpaceFragment $spaceFragment | ||
|
||
return @{ | ||
Exists = $null -ne $environment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function Get-SpaceDetails { | ||
[CmdletBinding()] | ||
[OutputType([HashTable])] | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusServerUrl, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusApiKey, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$SpaceName | ||
) | ||
|
||
[PSCustomObject]$space = Get-SpaceViaApi -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -SpaceName $SpaceName | ||
$exists = $null -ne $space | ||
$description = "" | ||
if ($exists) { | ||
$description = $space.Description | ||
} | ||
return @{ | ||
Exists = $exists; | ||
Description = $description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
function Get-TentacleDetails { | ||
[CmdletBinding()] | ||
[OutputType([HashTable])] | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusServerUrl, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusApiKey, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$InstanceName, | ||
[Parameter(Mandatory=$false)] | ||
[string] | ||
$SpaceId | ||
) | ||
|
||
[bool]$exists = Test-Path "c:\program files\Octopus Deploy\Tentacle\Tentacle.exe" | ||
[PSCustomObject]$machine = @{} | ||
[string[]]$environments = @() | ||
[string[]]$tenants = @() | ||
[string]$machinePolicy = $null | ||
[bool]$isOnline = $false | ||
[string]$communicationStyle = $Null | ||
|
||
if ($exists) { | ||
$thumbprint = Get-Thumbprint $InstanceName | ||
$serverSupportsSpaces = Test-ServerSupportsSpaces $OctopusServerUrl | ||
if ($serverSupportsSpaces -and (-not [string]::IsNullOrEmpty($SpaceId))) { | ||
$spaceFragment = "$SpaceId/" | ||
} | ||
$machine = Get-MachineViaApi -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -Thumbprint $thumbprint -SpaceFragment $spaceFragment | ||
$communicationStyle = $machine.Endpoint.CommunicationStyle | ||
$environments = (Get-Environments -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -SpaceFragment $spaceFragment) | Where-Object { $machine.EnvironmentIds -contains $_.Id } | Select-Object -ExpandProperty Name | ||
$tenants = (Get-Tenants -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -SpaceFragment $spaceFragment) | Where-Object { $machine.TenantIds -contains $_.Id } | Select-Object -ExpandProperty Name | ||
$machinePolicy = (Get-MachinePolicies -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -SpaceFragment $spaceFragment) | Where-Object { $machine.MachinePolicyId -contains $_.Id } | Select-Object -ExpandProperty Name | ||
$isOnline = Test-IsTentacleOnline -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -thumbprint $thumbprint -SpaceFragment $spaceFragment | ||
} | ||
|
||
return @{ | ||
Exists = $exists; | ||
IsRegisteredWithTheServer = $null -ne $machine; | ||
IsOnline = $isOnline | ||
IsListening = $communicationStyle -eq "TentaclePassive" | ||
IsPolling = $communicationStyle -eq "TentacleActive" | ||
Environments = $environments | ||
Roles = $machine.Roles | ||
DisplayName = $machine.Name | ||
Tenants = $tenants | ||
TenantTags = $machine.TenantTags | ||
Policy = $machinePolicy | ||
TenantedDeploymentParticipation = $machine.TenantedDeploymentParticipation | ||
Endpoint = $machine.Uri | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
function Get-WorkerDetails { | ||
[CmdletBinding()] | ||
[OutputType([HashTable])] | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusServerUrl, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusApiKey, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$InstanceName, | ||
[Parameter(Mandatory=$false)] | ||
[string] | ||
$SpaceId | ||
) | ||
|
||
[bool]$exists = Test-Path "c:\program files\Octopus Deploy\Tentacle\Tentacle.exe" | ||
[PSCustomObject]$worker = @{} | ||
[bool]$isOnline = $false | ||
[string]$communicationStyle = $Null | ||
|
||
if ($exists) { | ||
$thumbprint = Get-Thumbprint $InstanceName | ||
$serverSupportsSpaces = Test-ServerSupportsSpaces $OctopusServerUrl | ||
if ($serverSupportsSpaces -and (-not [string]::IsNullOrEmpty($SpaceId))) { | ||
$spaceFragment = "$SpaceId/" | ||
} | ||
$worker = Get-WorkerViaApi -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -Thumbprint $thumbprint -SpaceFragment $spaceFragment | ||
$communicationStyle = $worker.Endpoint.CommunicationStyle | ||
$isOnline = Test-IsWorkerOnline -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -thumbprint $thumbprint -SpaceFragment $spaceFragment | ||
} | ||
|
||
return @{ | ||
Exists = $exists; | ||
IsRegisteredWithTheServer = $null -ne $worker; | ||
IsOnline = $isOnline | ||
IsListening = $communicationStyle -eq "TentaclePassive" | ||
IsPolling = $communicationStyle -eq "TentacleActive" | ||
DisplayName = $worker.Name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function Get-WorkerPoolDetails { | ||
[CmdletBinding()] | ||
[OutputType([HashTable])] | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusServerUrl, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusApiKey, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$WorkerPoolName, | ||
[Parameter(Mandatory=$false)] | ||
[string] | ||
$SpaceId | ||
) | ||
|
||
$serverSupportsSpaces = Test-ServerSupportsSpaces $OctopusServerUrl | ||
if ($serverSupportsSpaces -and (-not [string]::IsNullOrEmpty($SpaceId))) { | ||
$spaceFragment = "$SpaceId/" | ||
} | ||
|
||
[PSCustomObject]$workerPool = Get-WorkerPoolViaApi -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -WorkerPoolName $WorkerPoolName -SpaceFragment $spaceFragment | ||
|
||
return @{ | ||
Exists = $null -ne $workerPool; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
E2ETests/Spec/TestHelpers/Private/Get-EnvironmentViaApi.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function Get-EnvironmentViaApi { | ||
[CmdletBinding()] | ||
[OutputType([PSCustomObject])] | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusServerUrl, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusApiKey, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$EnvironmentName, | ||
[Parameter(Mandatory=$true)] | ||
[AllowEmptyString()] | ||
[string] | ||
$spaceFragment | ||
) | ||
|
||
$url = "$OctopusServerUrl/api/$($spaceFragment)environments/all?api-key=$OctopusApiKey" | ||
$response = Invoke-RestMethod $url | ||
$environment = $response | Where-Object { $_.Name -eq $EnvironmentName } | ||
|
||
return $environment | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function Get-Environments { | ||
[CmdletBinding()] | ||
[OutputType([PSCustomObject])] | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusServerUrl, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusApiKey, | ||
[Parameter(Mandatory=$true)] | ||
[AllowEmptyString()] | ||
[string] | ||
$spaceFragment | ||
) | ||
|
||
$url = "$OctopusServerUrl/api/$($spaceFragment)environments/all?api-key=$OctopusApiKey" | ||
return Invoke-RestMethod $url | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function Get-MachinePolicies { | ||
[CmdletBinding()] | ||
[OutputType([PSCustomObject])] | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusServerUrl, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusApiKey, | ||
[Parameter(Mandatory=$true)] | ||
[AllowEmptyString()] | ||
[string] | ||
$spaceFragment | ||
) | ||
|
||
$url = "$OctopusServerUrl/api/$($spaceFragment)machinepolicies/all?api-key=$OctopusApiKey" | ||
return Invoke-RestMethod $url | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function Get-MachineViaApi { | ||
[CmdletBinding()] | ||
[OutputType([PSCustomObject])] | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusServerUrl, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$OctopusApiKey, | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$thumbprint, | ||
[Parameter(Mandatory=$true)] | ||
[AllowEmptyString()] | ||
[string] | ||
$spaceFragment | ||
) | ||
|
||
$url = "$OctopusServerUrl/api/$($spaceFragment)machines/all?api-key=$OctopusApiKey" | ||
$response = Invoke-RestMethod $url | ||
$machine = $response | Where-Object { $_.Thumbprint -eq $thumbprint } | ||
|
||
return $machine | ||
} |
Oops, something went wrong.