-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEnvironments.Tests.ps1
More file actions
136 lines (129 loc) · 6.69 KB
/
Environments.Tests.ps1
File metadata and controls
136 lines (129 loc) · 6.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' }
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseDeclaredVarsMoreThanAssignments', '',
Justification = 'Pester grouping syntax: known issue.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingConvertToSecureStringWithPlainText', '',
Justification = 'Used to create a secure string for testing.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingWriteHost', '',
Justification = 'Log outputs to GitHub Actions logs.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidLongLines', '',
Justification = 'Long test descriptions and skip switches'
)]
[CmdletBinding()]
param()
BeforeAll {
$testName = 'Environments'
$os = $env:RUNNER_OS
$id = $env:GITHUB_RUN_ID
}
Describe 'Environments' {
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"
Context 'As <Type> using <Case> on <Target>' -ForEach $authCases {
BeforeAll {
$context = Connect-GitHubAccount @connectParams -PassThru -Silent
LogGroup 'Context' {
Write-Host ($context | Format-List | Out-String)
}
if ($AuthType -eq 'APP') {
LogGroup 'Context - Installation' {
$context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent
Write-Host ($context | Format-List | Out-String)
}
}
$repoPrefix = "Test-$os-$TokenType"
$repoName = "$repoPrefix-$id"
$environmentName = "$testName-$os-$TokenType-$id"
LogGroup "Using Repository - [$repoName]" {
$repo = Get-GitHubRepository -Owner $Owner -Name $repoName
Write-Host ($repo | Select-Object * | Out-String)
}
}
AfterAll {
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent
Write-Host ('-' * 60)
}
It 'Get-GitHubEnvironment - should return an empty list when no environments exist' -Skip:($OwnerType -in ('repository', 'enterprise')) {
$result = Get-GitHubEnvironment -Owner $owner -Repository $repoName
LogGroup 'Environment' {
Write-Host ($result | Format-Table | Out-String)
}
$result | Should -BeNullOrEmpty
}
It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' -Skip:($OwnerType -in ('repository', 'enterprise')) {
$result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName
LogGroup 'Environment' {
Write-Host ($result | Format-Table | Out-String)
}
$result | Should -BeNullOrEmpty
}
It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' -Skip:($OwnerType -in ('repository', 'enterprise')) {
$result = Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName -WaitTimer 10
LogGroup 'Environment' {
Write-Host ($result | Format-List | Out-String)
}
$result | Should -Not -BeNullOrEmpty
$result | Should -BeOfType [GitHubEnvironment]
$result.Name | Should -Be $environmentName
$result.ProtectionRules.wait_timer | Should -Be 10
}
It 'Get-GitHubEnvironment - should retrieve the environment that was created' -Skip:($OwnerType -in ('repository', 'enterprise')) {
$result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName
LogGroup 'Environment' {
Write-Host ($result | Format-List | Out-String)
}
$result | Should -Not -BeNullOrEmpty
$result.Name | Should -Be $environmentName
}
It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' -Skip:($OwnerType -in ('repository', 'enterprise')) {
$result = Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os"
LogGroup 'Environment' {
Write-Host ($result | Format-List | Out-String)
}
$result | Should -Not -BeNullOrEmpty
$result.Name | Should -Be "$environmentName/$os"
}
It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' -Skip:($OwnerType -in ('repository', 'enterprise')) {
$result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os"
LogGroup 'Environment' {
Write-Host ($result | Format-Table | Out-String)
}
$result | Should -Not -BeNullOrEmpty
$result.Name | Should -Be "$environmentName/$os"
}
It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' -Skip:($OwnerType -in ('repository', 'enterprise')) {
{
Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false
} | Should -Not -Throw
}
It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' -Skip:($OwnerType -in ('repository', 'enterprise')) {
$result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os"
LogGroup 'Environment' {
Write-Host ($result | Format-Table | Out-String)
}
$result | Should -BeNullOrEmpty
}
It 'Get-GitHubEnvironment - should list one remaining environment' -Skip:($OwnerType -in ('repository', 'enterprise')) {
$result = Get-GitHubEnvironment -Owner $owner -Repository $repoName
LogGroup 'Environment' {
Write-Host ($result | Format-Table | Out-String)
}
$result.Count | Should -Be 1
}
It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' -Skip:($OwnerType -in ('repository', 'enterprise')) {
{ Remove-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName -Confirm:$false } | Should -Not -Throw
}
It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' -Skip:($OwnerType -in ('repository', 'enterprise')) {
$result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName
LogGroup 'Environment' {
Write-Host ($result | Format-Table | Out-String)
}
$result | Should -BeNullOrEmpty
}
}
}