4
4
<#
5
5
. Synopsis
6
6
Tests for GitHubRepositories.ps1 module
7
- . Description
8
- Many cmdlets are indirectly tested in the course of other tests (New-GitHubRepository, Remove-GitHubRepository), and may not have explicit tests here
9
7
#>
10
8
11
9
# This is common test code setup logic for all Pester test files
@@ -14,6 +12,15 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent
14
12
15
13
try
16
14
{
15
+ # Define Script-scoped, readonly, hidden variables.
16
+ @ {
17
+ defaultRepoDesc = " This is a description."
18
+ defaultRepoHomePage = " https://www.microsoft.com/"
19
+ defaultRepoTopic = " microsoft"
20
+ }.GetEnumerator() | ForEach-Object {
21
+ Set-Variable - Force - Scope Script - Option ReadOnly - Visibility Private - Name $_.Key - Value $_.Value
22
+ }
23
+
17
24
Describe ' Getting repositories' {
18
25
Context ' For authenticated user' {
19
26
BeforeAll - Scriptblock {
25
32
$privateRepo = $privateRepo
26
33
}
27
34
28
- $publicRepos = @ (Get-GitHubRepository - Visibility Public)
29
- $privateRepos = @ (Get-GitHubRepository - Visibility Private)
30
-
31
35
It " Should have the public repo" {
32
- $publicRepo.Name | Should BeIn $publicRepos.Name
33
- $publicRepo.Name | Should Not BeIn $privateRepos.Name
36
+ $publicRepos = @ (Get-GitHubRepository - Visibility Public)
37
+ $privateRepos = @ (Get-GitHubRepository - Visibility Private)
38
+ $publicRepo.name | Should - BeIn $publicRepos.name
39
+ $publicRepo.name | Should -Not - BeIn $privateRepos.name
34
40
}
35
41
36
42
It " Should have the private repo" {
37
- $privateRepo.Name | Should BeIn $privateRepos.Name
38
- $privateRepo.Name | Should Not BeIn $publicRepos.Name
43
+ $publicRepos = @ (Get-GitHubRepository - Visibility Public)
44
+ $privateRepos = @ (Get-GitHubRepository - Visibility Private)
45
+ $privateRepo.name | Should - BeIn $privateRepos.name
46
+ $privateRepo.name | Should -Not - BeIn $publicRepos.name
39
47
}
40
48
41
49
It ' Should not permit bad combination of parameters' {
42
- { Get-GitHubRepository - Type All - Visibility All } | Should Throw
43
- { Get-GitHubRepository - Type All - Affiliation Owner } | Should Throw
50
+ { Get-GitHubRepository - Type All - Visibility All } | Should - Throw
51
+ { Get-GitHubRepository - Type All - Affiliation Owner } | Should - Throw
44
52
}
45
53
46
54
AfterAll - ScriptBlock {
50
58
}
51
59
52
60
Context ' For any user' {
53
- $repos = @ (Get-GitHubRepository - OwnerName ' octocat' - Type Public)
54
-
55
61
It " Should have results for The Octocat" {
62
+ $repos = @ (Get-GitHubRepository - OwnerName ' octocat' - Type Public)
56
63
$repos.Count | Should - BeGreaterThan 0
57
- $repos [0 ].owner.login | Should Be ' octocat'
64
+ $repos [0 ].owner.login | Should - Be ' octocat'
58
65
}
59
66
}
60
67
66
73
$repo = $repo
67
74
}
68
75
69
- $repos = @ (Get-GitHubRepository - OrganizationName $script :organizationName - Type All)
70
76
It " Should have results for the organization" {
71
- $repo.name | Should BeIn $repos.name
77
+ $repos = @ (Get-GitHubRepository - OrganizationName $script :organizationName - Type All)
78
+ $repo.name | Should - BeIn $repos.name
72
79
}
73
80
74
81
AfterAll - ScriptBlock {
82
89
}
83
90
84
91
Context ' For a specific repo' {
85
- BeforeAll - Scriptblock {
92
+ BeforeAll - ScriptBlock {
86
93
$repo = New-GitHubRepository - RepositoryName ([Guid ]::NewGuid().Guid) - AutoInit
87
94
88
95
# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
89
96
$repo = $repo
90
97
}
91
98
92
- $result = Get-GitHubRepository - Uri $repo.svn_url
93
99
It " Should be a single result using Uri ParameterSet" {
100
+ $result = Get-GitHubRepository - Uri $repo.svn_url
94
101
$result | Should - BeOfType PSCustomObject
95
102
}
96
103
97
- $result = Get-GitHubRepository - OwnerName $repo.owner.login - RepositoryName $repo.Name
98
104
It " Should be a single result using Elements ParameterSet" {
105
+ $result = Get-GitHubRepository - OwnerName $repo.owner.login - RepositoryName $repo.name
99
106
$result | Should - BeOfType PSCustomObject
100
107
}
101
108
102
109
It ' Should not permit additional parameters' {
103
- { Get-GitHubRepository - OwnerName $repo.owner.login - RepositoryName $repo.Name - Type All } | Should Throw
110
+ { Get-GitHubRepository - OwnerName $repo.owner.login - RepositoryName $repo.name - Type All } | Should - Throw
104
111
}
105
112
106
113
It ' Should require both OwnerName and RepositoryName' {
107
- { Get-GitHubRepository - RepositoryName $repo.Name } | Should Throw
108
- { Get-GitHubRepository - Uri " https://github.com./$script :ownerName " } | Should Throw
114
+ { Get-GitHubRepository - RepositoryName $repo.name } | Should - Throw
115
+ { Get-GitHubRepository - Uri " https://github.com./$script :ownerName " } | Should - Throw
116
+ }
117
+
118
+ AfterAll - ScriptBlock {
119
+ Remove-GitHubRepository - Uri $repo.svn_url - Confirm:$false
120
+ }
121
+ }
122
+ }
123
+
124
+ Describe ' Creating repositories' {
125
+
126
+ Context - Name ' For creating a repository' - Fixture {
127
+ BeforeAll - ScriptBlock {
128
+ $repoName = ([Guid ]::NewGuid().Guid)
129
+ $repo = New-GitHubRepository - RepositoryName $repoName - Description $defaultRepoDesc - AutoInit
130
+
131
+ # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
132
+ $repoName = $repoName
133
+ $repo = $repo
134
+ }
135
+
136
+ It ' Should get repository' {
137
+ $repo | Should -Not - BeNullOrEmpty
138
+ }
139
+
140
+ It ' Name is correct' {
141
+ $repo.name | Should - Be $repoName
142
+ }
143
+
144
+ It ' Description is correct' {
145
+ $repo.description | Should - Be $defaultRepoDesc
109
146
}
110
147
111
148
AfterAll - ScriptBlock {
@@ -114,30 +151,152 @@ try
114
151
}
115
152
}
116
153
117
- Describe ' Modifying repositories' {
154
+ Describe ' Deleting repositories' {
155
+
156
+ Context - Name ' For deleting a repository' - Fixture {
157
+ BeforeAll - ScriptBlock {
158
+ $repo = New-GitHubRepository - RepositoryName ([Guid ]::NewGuid().Guid) - Description $defaultRepoDesc - AutoInit
159
+
160
+ # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
161
+ $repo = $repo
162
+ }
163
+
164
+ It ' Should get no content' {
165
+ Remove-GitHubRepository - OwnerName $repo.owner.login - RepositoryName $repo.name - Confirm:$false
166
+ { Get-GitHubRepository - OwnerName $repo.owner.login - RepositoryName $repo.name } | Should - Throw
167
+ }
168
+ }
169
+ }
170
+
171
+ Describe ' Renaming repositories' {
172
+
118
173
Context - Name ' For renaming a repository' - Fixture {
119
174
BeforeEach - Scriptblock {
120
175
$repo = New-GitHubRepository - RepositoryName ([Guid ]::NewGuid().Guid) - AutoInit
121
176
$suffixToAddToRepo = " _renamed"
122
- $newRepoName = " $ ( $repo.Name ) $suffixToAddToRepo "
123
- Write-Verbose " New repo name shall be: '$newRepoName '"
177
+ $newRepoName = " $ ( $repo.name ) $suffixToAddToRepo "
178
+
179
+ # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
180
+ $newRepoName = $newRepoName
124
181
}
182
+
125
183
It " Should have the expected new repository name - by URI" {
126
184
$renamedRepo = $repo | Rename-GitHubRepository - NewName $newRepoName - Confirm:$false
127
- $renamedRepo.Name | Should be $newRepoName
185
+ $renamedRepo.name | Should - Be $newRepoName
128
186
}
129
187
130
188
It " Should have the expected new repository name - by Elements" {
131
189
$renamedRepo = Rename-GitHubRepository - OwnerName $repo.owner.login - RepositoryName $repo.name - NewName $newRepoName - Confirm:$false
132
- $renamedRepo.Name | Should be $newRepoName
190
+ $renamedRepo.name | Should - Be $newRepoName
133
191
}
134
- # # cleanup temp testing repository
192
+
135
193
AfterEach - Scriptblock {
136
- # # variables from BeforeEach scriptblock are accessible here, but not variables from It scriptblocks, so need to make URI (instead of being able to use $renamedRepo variable from It scriptblock)
137
194
Remove-GitHubRepository - Uri " $ ( $repo.svn_url ) $suffixToAddToRepo " - Confirm:$false
138
195
}
139
196
}
140
197
}
198
+
199
+ Describe ' Updating repositories' {
200
+
201
+ Context - Name ' For creating a repository' - Fixture {
202
+ BeforeAll - ScriptBlock {
203
+ $repo = New-GitHubRepository - RepositoryName ([Guid ]::NewGuid().Guid) - Description $defaultRepoDesc - AutoInit
204
+
205
+ # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
206
+ $repo = $repo
207
+ }
208
+
209
+ It ' Should have the new updated description' {
210
+ $modifiedRepoDesc = $defaultRepoDesc + " _modified"
211
+ $updatedRepo = Update-GitHubRepository - OwnerName $repo.owner.login - RepositoryName $repo.name - Description $modifiedRepoDesc
212
+ $updatedRepo.description | Should - Be $modifiedRepoDesc
213
+ }
214
+
215
+ It ' Should have the new updated homepage url' {
216
+ $updatedRepo = Update-GitHubRepository - OwnerName $repo.owner.login - RepositoryName $repo.name - Homepage $defaultRepoHomePage
217
+ $updatedRepo.homepage | Should - Be $defaultRepoHomePage
218
+ }
219
+
220
+ AfterAll - ScriptBlock {
221
+ Remove-GitHubRepository - Uri $repo.svn_url - Confirm:$false
222
+ }
223
+ }
224
+ }
225
+
226
+ Describe ' Get/set repository topic' {
227
+
228
+ Context - Name ' For creating and getting a repository topic' - Fixture {
229
+ BeforeAll - ScriptBlock {
230
+ $repo = New-GitHubRepository - RepositoryName ([Guid ]::NewGuid().Guid) - AutoInit
231
+
232
+ # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
233
+ $repo = $repo
234
+ }
235
+
236
+ It ' Should have the expected topic' {
237
+ Set-GitHubRepositoryTopic - OwnerName $repo.owner.login - RepositoryName $repo.name - Name $defaultRepoTopic
238
+ $topic = Get-GitHubRepositoryTopic - OwnerName $repo.owner.login - RepositoryName $repo.name
239
+ $topic.names | Should - Be $defaultRepoTopic
240
+ }
241
+
242
+ It ' Should have no topics' {
243
+ Set-GitHubRepositoryTopic - OwnerName $repo.owner.login - RepositoryName $repo.name - Clear
244
+ $topic = Get-GitHubRepositoryTopic - OwnerName $repo.owner.login - RepositoryName $repo.name
245
+ $topic.names | Should - BeNullOrEmpty
246
+ }
247
+
248
+ AfterAll - ScriptBlock {
249
+ Remove-GitHubRepository - Uri $repo.svn_url - Confirm:$false
250
+ }
251
+ }
252
+ }
253
+
254
+ Describe ' Get repository languages' {
255
+
256
+ Context - Name ' For getting repository languages' - Fixture {
257
+ BeforeAll - ScriptBlock {
258
+ $repo = New-GitHubRepository - RepositoryName ([Guid ]::NewGuid().Guid) - AutoInit
259
+
260
+ # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
261
+ $repo = $repo
262
+ }
263
+
264
+ It ' Should be empty' {
265
+ $languages = Get-GitHubRepositoryLanguage - OwnerName $repo.owner.login - RepositoryName $repo.name
266
+ $languages | Should - BeNullOrEmpty
267
+ }
268
+
269
+ It ' Should contain PowerShell' {
270
+ $languages = Get-GitHubRepositoryLanguage - OwnerName " microsoft" - RepositoryName " PowerShellForGitHub"
271
+ $languages.PowerShell | Should -Not - BeNullOrEmpty
272
+ }
273
+
274
+ AfterAll - ScriptBlock {
275
+ Remove-GitHubRepository - Uri $repo.svn_url - Confirm:$false
276
+ }
277
+ }
278
+ }
279
+
280
+ Describe ' Get repository tags' {
281
+
282
+ Context - Name ' For getting repository tags' - Fixture {
283
+ BeforeAll - ScriptBlock {
284
+ $repo = New-GitHubRepository - RepositoryName ([Guid ]::NewGuid().Guid) - AutoInit
285
+
286
+ # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
287
+ $repo = $repo
288
+ }
289
+
290
+ It ' Should be empty' {
291
+ $tags = Get-GitHubRepositoryTag - OwnerName $repo.owner.login - RepositoryName $repo.name
292
+ $tags | Should - BeNullOrEmpty
293
+ }
294
+
295
+ AfterAll - ScriptBlock {
296
+ Remove-GitHubRepository - Uri $repo.svn_url - Confirm:$false
297
+ }
298
+ }
299
+ }
141
300
}
142
301
finally
143
302
{
0 commit comments