-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTeams.Tests.ps1
More file actions
144 lines (131 loc) · 5.67 KB
/
Teams.Tests.ps1
File metadata and controls
144 lines (131 loc) · 5.67 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
137
138
139
140
141
142
143
144
#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 = 'TeamsTests'
$os = $env:RUNNER_OS
$guid = [guid]::NewGuid().ToString() -replace '-', '_'
}
Describe 'Teams' {
$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)
}
}
$teamPrefix = "$testName`_$os`_$TokenType"
$teamName = "$teamPrefix`_$guid"
switch ($OwnerType) {
'organization' {
Get-GitHubTeam -Organization $owner | Where-Object { $_.Name -like "$teamPrefix*" } | Remove-GitHubTeam -Confirm:$false
}
}
}
AfterAll {
switch ($OwnerType) {
'organization' {
$teamsToRemove = Get-GitHubTeam -Organization $owner | Where-Object { $_.Name -like "$teamPrefix*" }
LogGroup 'Teams to remove' {
Write-Host "$($teamsToRemove | Format-List | Out-String)"
}
$teamsToRemove | Remove-GitHubTeam -Confirm:$false
}
}
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent
Write-Host ('-' * 60)
}
Context 'Organization' -Skip:($OwnerType -ne 'organization') {
BeforeAll {
$scope = @{
Organization = $owner
}
}
It 'New-GitHubTeam - Creates a new team' {
$teamName = "$teamPrefix`_NewTeam"
$teamDescription = 'This is a test team.'
$team = New-GitHubTeam @scope -Name $teamName -Description $teamDescription
LogGroup 'New Team' {
Write-Host ($team | Format-List | Out-String)
}
$team | Should -Not -BeNullOrEmpty
$team.Name | Should -Be $teamName
$team.Description | Should -Be $teamDescription
}
It 'Get-GitHubTeam - Gets a team' {
$teamName = "$teamPrefix`_NewTeam"
$team = Get-GitHubTeam -Organization $owner -Slug $teamName
LogGroup 'Get Team' {
Write-Host ($team | Format-List | Out-String)
}
$team | Should -Not -BeNullOrEmpty
$team.Name | Should -Be $teamName
}
It 'New-GitHubTeam - Creates 5 new teams' {
1..5 | ForEach-Object {
$teamName = "$teamPrefix`_NewTeam_$_"
$teamDescription = 'This is a test team.'
$team = New-GitHubTeam @scope -Name $teamName -Description $teamDescription
LogGroup 'New Team' {
Write-Host ($team | Format-List | Out-String)
}
$team | Should -Not -BeNullOrEmpty
$team.Name | Should -Be $teamName
$team.Description | Should -Be $teamDescription
}
}
It 'Get-GitHubTeam - Gets all teams' {
$teams = Get-GitHubTeam -Organization $owner
LogGroup 'Get All Teams' {
Write-Host ($teams | Format-List | Out-String)
}
$teams | Should -Not -BeNullOrEmpty
$teams.Count | Should -BeGreaterThan 0
}
It 'Update-GitHubTeam - Updates a team' {
$teamName = "$teamPrefix`_NewTeam"
$newTeamName = "$teamPrefix`_UpdatedTeam"
$teamDescription = 'This is an updated test team.'
$team = Update-GitHubTeam @scope -Slug $teamName -NewName $newTeamName -Description $teamDescription
LogGroup 'Update Team' {
Write-Host ($team | Format-List | Out-String)
}
$team | Should -Not -BeNullOrEmpty
$team.Name | Should -Be $newTeamName
$team.Description | Should -Be $teamDescription
}
It 'Remove-GitHubTeam - Removes a team' {
$teamName = "$teamPrefix`_UpdatedTeam"
$team = Get-GitHubTeam -Organization $owner -Slug $teamName
LogGroup 'Remove Team' {
Write-Host ($team | Format-List | Out-String)
}
$team | Should -Not -BeNullOrEmpty
$team.Name | Should -Be $teamName
Remove-GitHubTeam @scope -Slug $teamName -Confirm:$false
}
}
}
}