Skip to content

Commit fc9cfd5

Browse files
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.
1 parent fddf416 commit fc9cfd5

File tree

78 files changed

+3432
-1549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3432
-1549
lines changed

.ruby-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

E2ETests/.rspec

Lines changed: 0 additions & 1 deletion
This file was deleted.

E2ETests/Gemfile

Lines changed: 0 additions & 7 deletions
This file was deleted.

E2ETests/Gemfile.lock

Lines changed: 0 additions & 64 deletions
This file was deleted.

E2ETests/Rakefile

Lines changed: 0 additions & 6 deletions
This file was deleted.

E2ETests/Scenarios/Server_Scenario_01_Install.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ Configuration Server_Scenario_01_Install
118118
$user = $repository.Users.GetCurrent()
119119
$createApiKeyResult = $repository.Users.CreateApiKey($user, "Octopus DSC Testing")
120120

121-
#save it to enviornment variables for tests to use
122-
[environment]::SetEnvironmentVariable("OctopusServerUrl", "http://localhost:81", "User")
123-
[environment]::SetEnvironmentVariable("OctopusServerUrl", "http://localhost:81", "Machine")
124-
[environment]::SetEnvironmentVariable("OctopusApiKey", $createApiKeyResult.ApiKey, "User")
125-
[environment]::SetEnvironmentVariable("OctopusApiKey", $createApiKeyResult.ApiKey, "Machine")
121+
#save it to file for tests to use
122+
$content = @{
123+
"OctopusServerUrl" = "http://localhost:81";
124+
"OctopusApiKey" = $createApiKeyResult.ApiKey;
125+
}
126+
set-content "c:\temp\octopus-configured.marker" ($content | ConvertTo-Json)
126127
}
127128
TestScript = {
128129
Add-Type -Path "${env:ProgramFiles}\Octopus Deploy\Octopus\Newtonsoft.Json.dll"

E2ETests/Scenarios/Server_Scenario_07_Reinstall.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ Configuration Server_Scenario_07_Reinstall
9797

9898
write-verbose "setting OctopusApiKey to $($createApiKeyResult.ApiKey)"
9999

100-
#save it to enviornment variables for tests to use
101-
[environment]::SetEnvironmentVariable("OctopusServerUrl", "http://localhost:81", "User")
102-
[environment]::SetEnvironmentVariable("OctopusServerUrl", "http://localhost:81", "Machine")
103-
[environment]::SetEnvironmentVariable("OctopusApiKey", $createApiKeyResult.ApiKey, "User")
104-
[environment]::SetEnvironmentVariable("OctopusApiKey", $createApiKeyResult.ApiKey, "Machine")
100+
#save it to file for tests to use
101+
$content = @{
102+
"OctopusServerUrl" = "http://localhost:81";
103+
"OctopusApiKey" = $createApiKeyResult.ApiKey;
104+
}
105+
set-content "c:\temp\octopus-configured.marker" ($content | ConvertTo-Json)
105106
}
106107
TestScript = {
107108
Add-Type -Path "${env:ProgramFiles}\Octopus Deploy\Octopus\Newtonsoft.Json.dll"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function Get-EnvironmentDetails {
2+
[CmdletBinding()]
3+
[OutputType([HashTable])]
4+
param (
5+
[Parameter(Mandatory=$true)]
6+
[string]
7+
$OctopusServerUrl,
8+
[Parameter(Mandatory=$true)]
9+
[string]
10+
$OctopusApiKey,
11+
[Parameter(Mandatory=$true)]
12+
[string]
13+
$EnvironmentName,
14+
[Parameter(Mandatory=$false)]
15+
[string]
16+
$SpaceId
17+
)
18+
19+
$serverSupportsSpaces = Test-ServerSupportsSpaces $OctopusServerUrl
20+
if ($serverSupportsSpaces -and (-not [string]::IsNullOrEmpty($SpaceId))) {
21+
$spaceFragment = "$SpaceId/"
22+
}
23+
24+
[PSCustomObject]$environment = Get-EnvironmentViaApi -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -EnvironmentName $EnvironmentName -SpaceFragment $spaceFragment
25+
26+
return @{
27+
Exists = $null -ne $environment;
28+
}
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function Get-SpaceDetails {
2+
[CmdletBinding()]
3+
[OutputType([HashTable])]
4+
param (
5+
[Parameter(Mandatory=$true)]
6+
[string]
7+
$OctopusServerUrl,
8+
[Parameter(Mandatory=$true)]
9+
[string]
10+
$OctopusApiKey,
11+
[Parameter(Mandatory=$true)]
12+
[string]
13+
$SpaceName
14+
)
15+
16+
[PSCustomObject]$space = Get-SpaceViaApi -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -SpaceName $SpaceName
17+
$exists = $null -ne $space
18+
$description = ""
19+
if ($exists) {
20+
$description = $space.Description
21+
}
22+
return @{
23+
Exists = $exists;
24+
Description = $description;
25+
}
26+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
function Get-TentacleDetails {
2+
[CmdletBinding()]
3+
[OutputType([HashTable])]
4+
param (
5+
[Parameter(Mandatory=$true)]
6+
[string]
7+
$OctopusServerUrl,
8+
[Parameter(Mandatory=$true)]
9+
[string]
10+
$OctopusApiKey,
11+
[Parameter(Mandatory=$true)]
12+
[string]
13+
$InstanceName,
14+
[Parameter(Mandatory=$false)]
15+
[string]
16+
$SpaceId
17+
)
18+
19+
[bool]$exists = Test-Path "c:\program files\Octopus Deploy\Tentacle\Tentacle.exe"
20+
[PSCustomObject]$machine = @{}
21+
[string[]]$environments = @()
22+
[string[]]$tenants = @()
23+
[string]$machinePolicy = $null
24+
[bool]$isOnline = $false
25+
[string]$communicationStyle = $Null
26+
27+
if ($exists) {
28+
$thumbprint = Get-Thumbprint $InstanceName
29+
$serverSupportsSpaces = Test-ServerSupportsSpaces $OctopusServerUrl
30+
if ($serverSupportsSpaces -and (-not [string]::IsNullOrEmpty($SpaceId))) {
31+
$spaceFragment = "$SpaceId/"
32+
}
33+
$machine = Get-MachineViaApi -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -Thumbprint $thumbprint -SpaceFragment $spaceFragment
34+
$communicationStyle = $machine.Endpoint.CommunicationStyle
35+
$environments = (Get-Environments -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -SpaceFragment $spaceFragment) | Where-Object { $machine.EnvironmentIds -contains $_.Id } | Select-Object -ExpandProperty Name
36+
$tenants = (Get-Tenants -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -SpaceFragment $spaceFragment) | Where-Object { $machine.TenantIds -contains $_.Id } | Select-Object -ExpandProperty Name
37+
$machinePolicy = (Get-MachinePolicies -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -SpaceFragment $spaceFragment) | Where-Object { $machine.MachinePolicyId -contains $_.Id } | Select-Object -ExpandProperty Name
38+
$isOnline = Test-IsTentacleOnline -OctopusServerUrl $OctopusServerUrl -OctopusApiKey $OctopusApiKey -thumbprint $thumbprint -SpaceFragment $spaceFragment
39+
}
40+
41+
return @{
42+
Exists = $exists;
43+
IsRegisteredWithTheServer = $null -ne $machine;
44+
IsOnline = $isOnline
45+
IsListening = $communicationStyle -eq "TentaclePassive"
46+
IsPolling = $communicationStyle -eq "TentacleActive"
47+
Environments = $environments
48+
Roles = $machine.Roles
49+
DisplayName = $machine.Name
50+
Tenants = $tenants
51+
TenantTags = $machine.TenantTags
52+
Policy = $machinePolicy
53+
TenantedDeploymentParticipation = $machine.TenantedDeploymentParticipation
54+
Endpoint = $machine.Uri
55+
}
56+
}

0 commit comments

Comments
 (0)