-
Notifications
You must be signed in to change notification settings - Fork 187
/
GitHubRepositories.tests.ps1
1024 lines (864 loc) · 42.2 KB
/
GitHubRepositories.tests.ps1
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
<#
.Synopsis
Tests for GitHubRepositories.ps1 module
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '',
Justification='Suppress false positives in Pester code blocks')]
param()
# This is common test code setup logic for all Pester test files
$moduleRootPath = Split-Path -Path $PSScriptRoot -Parent
. (Join-Path -Path $moduleRootPath -ChildPath 'Tests\Common.ps1')
try
{
# Define Script-scoped, readonly, hidden variables.
@{
defaultRepoDesc = "This is a description."
defaultRepoHomePage = "https://www.microsoft.com/"
defaultRepoTopic = "microsoft"
}.GetEnumerator() | ForEach-Object {
Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value
}
Describe 'GitHubRepositories\New-GitHubRepository' {
Context -Name 'When creating a repository for the authenticated user' -Fixture {
Context -Name 'When creating a public repository with default settings' -Fixture {
BeforeAll -ScriptBlock {
$repoName = ([Guid]::NewGuid().Guid)
$newGitHubRepositoryParms = @{
RepositoryName = $repoName
}
$repo = New-GitHubRepository @newGitHubRepositoryParms
}
It 'Should return an object of the correct type' {
$repo | Should -BeOfType PSCustomObject
}
It 'Should return the correct properties' {
$repo.name | Should -Be $repoName
$repo.private | Should -BeFalse
$repo.description | Should -BeNullOrEmpty
$repo.homepage | Should -BeNullOrEmpty
$repo.has_issues | Should -BeTrue
$repo.has_projects | Should -BeTrue
$repo.has_Wiki | Should -BeTrue
$repo.allow_squash_merge | Should -BeTrue
$repo.allow_merge_commit | Should -BeTrue
$repo.allow_rebase_merge | Should -BeTrue
$repo.delete_branch_on_merge | Should -BeFalse
$repo.is_template | Should -BeFalse
}
AfterAll -ScriptBlock {
if ($repo)
{
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}
Context -Name 'When creating a private repository with default settings' -Fixture {
BeforeAll -ScriptBlock {
$repoName = ([Guid]::NewGuid().Guid)
$newGitHubRepositoryParms = @{
RepositoryName = $repoName
Private = $true
}
$repo = New-GitHubRepository @newGitHubRepositoryParms
}
It 'Should return an object of the correct type' {
$repo | Should -BeOfType PSCustomObject
}
It 'Should return the correct properties' {
$repo.name | Should -Be $repoName
$repo.private | Should -BeTrue
$repo.description | Should -BeNullOrEmpty
$repo.homepage | Should -BeNullOrEmpty
$repo.has_issues | Should -BeTrue
$repo.has_projects | Should -BeTrue
$repo.has_Wiki | Should -BeTrue
$repo.allow_squash_merge | Should -BeTrue
$repo.allow_merge_commit | Should -BeTrue
$repo.allow_rebase_merge | Should -BeTrue
$repo.delete_branch_on_merge | Should -BeFalse
$repo.is_template | Should -BeFalse
}
AfterAll -ScriptBlock {
if ($repo)
{
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}
Context -Name 'When creating a repository with all possible settings' -Fixture {
BeforeAll -ScriptBlock {
$repoName = ([Guid]::NewGuid().Guid)
$testGitIgnoreTemplate=(Get-GitHubGitIgnore)[0]
$testLicenseTemplate=(Get-GitHubLicense)[0].key
$newGitHubRepositoryParms = @{
RepositoryName = $repoName
Description = $defaultRepoDesc
HomePage = $defaultRepoHomePage
NoIssues = $true
NoProjects = $true
NoWiki = $true
DisallowSquashMerge = $true
DisallowMergeCommit = $true
DisallowRebaseMerge = $false
DeleteBranchOnMerge = $true
GitIgnoreTemplate = $testGitIgnoreTemplate
LicenseTemplate = $testLicenseTemplate
IsTemplate = $true
}
$repo = New-GitHubRepository @newGitHubRepositoryParms
}
It 'Should return an object of the correct type' {
$repo | Should -BeOfType PSCustomObject
}
It 'Should return the correct properties' {
$repo.name | Should -Be $repoName
$repo.description | Should -Be $defaultRepoDesc
$repo.homepage | Should -Be $defaultRepoHomePage
$repo.has_issues | Should -BeFalse
$repo.has_projects | Should -BeFalse
$repo.has_Wiki | Should -BeFalse
$repo.allow_squash_merge | Should -BeFalse
$repo.allow_merge_commit | Should -BeFalse
$repo.allow_rebase_merge | Should -BeTrue
$repo.delete_branch_on_merge | Should -BeTrue
$repo.is_template | Should -BeTrue
}
It 'Should have created a .gitignore file' {
{ Get-GitHubContent -Uri $repo.svn_url -Path '.gitignore' } | Should -Not -Throw
}
It 'Should have created a LICENSE file' {
{ Get-GitHubContent -Uri $repo.svn_url -Path 'LICENSE' } | Should -Not -Throw
}
AfterAll -ScriptBlock {
if ($repo)
{
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}
Context -Name 'When creating a repository with alternative Merge settings' -Fixture {
BeforeAll -ScriptBlock {
$repoName = ([Guid]::NewGuid().Guid)
$newGitHubRepositoryParms = @{
RepositoryName = $repoName
DisallowSquashMerge = $true
DisallowMergeCommit = $false
DisallowRebaseMerge = $true
}
$repo = New-GitHubRepository @newGitHubRepositoryParms
}
It 'Should return an object of the correct type' {
$repo | Should -BeOfType PSCustomObject
}
It 'Should return the correct properties' {
$repo.name | Should -Be $repoName
$repo.allow_squash_merge | Should -BeFalse
$repo.allow_merge_commit | Should -BeTrue
$repo.allow_rebase_merge | Should -BeFalse
}
AfterAll -ScriptBlock {
if ($repo)
{
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}
Context -Name 'When a TeamID is specified' -Fixture {
BeforeAll -ScriptBlock {
$repoName = ([Guid]::NewGuid().Guid)
$mockTeamID=1
$newGitHubRepositoryParms = @{
RepositoryName = $repoName
TeamID = $mockTeamID
}
}
It 'Should throw the correct exception' {
$errorMessage = 'TeamId may only be specified when creating a repository under an organization.'
{ New-GitHubRepository @newGitHubRepositoryParms } | Should -Throw $errorMessage
}
}
}
Context -Name 'When creating an organization repository' -Fixture {
Context -Name 'When creating a public repository with default settings' -Fixture {
BeforeAll -ScriptBlock {
$repoName = ([Guid]::NewGuid().Guid)
$newGitHubRepositoryParms = @{
RepositoryName = $repoName
OrganizationName = $script:organizationName
}
$repo = New-GitHubRepository @newGitHubRepositoryParms
}
It 'Should return an object of the correct type' {
$repo | Should -BeOfType PSCustomObject
}
It 'Should return the correct properties' {
$repo.name | Should -Be $repoName
$repo.private | Should -BeFalse
$repo.organization.login | Should -Be $script:organizationName
$repo.description | Should -BeNullOrEmpty
$repo.homepage | Should -BeNullOrEmpty
$repo.has_issues | Should -BeTrue
$repo.has_projects | Should -BeTrue
$repo.has_Wiki | Should -BeTrue
$repo.allow_squash_merge | Should -BeTrue
$repo.allow_merge_commit | Should -BeTrue
$repo.allow_rebase_merge | Should -BeTrue
$repo.delete_branch_on_merge | Should -BeFalse
$repo.is_template | Should -BeFalse
}
AfterAll -ScriptBlock {
if ($repo)
{
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}
Context -Name 'When creating a private repository with default settings' -Fixture {
BeforeAll -ScriptBlock {
$repoName = ([Guid]::NewGuid().Guid)
$newGitHubRepositoryParms = @{
RepositoryName = $repoName
Private = $true
OrganizationName = $script:organizationName
}
$repo = New-GitHubRepository @newGitHubRepositoryParms
}
It 'Should return an object of the correct type' {
$repo | Should -BeOfType PSCustomObject
}
It 'Should return the correct properties' {
$repo.name | Should -Be $repoName
$repo.private | Should -BeTrue
$repo.organization.login | Should -Be $script:organizationName
$repo.description | Should -BeNullOrEmpty
$repo.homepage | Should -BeNullOrEmpty
$repo.has_issues | Should -BeTrue
$repo.has_projects | Should -BeTrue
$repo.has_Wiki | Should -BeTrue
$repo.allow_squash_merge | Should -BeTrue
$repo.allow_merge_commit | Should -BeTrue
$repo.allow_rebase_merge | Should -BeTrue
$repo.delete_branch_on_merge | Should -BeFalse
$repo.is_template | Should -BeFalse
}
AfterAll -ScriptBlock {
if ($repo)
{
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}
}
}
Describe 'GitHubRepositories\New-GitHubRepositoryFromTemplate' {
BeforeAll {
$templateRepoName = ([Guid]::NewGuid().Guid)
$ownerName = $script:ownerName
$testGitIgnoreTemplate = (Get-GitHubGitIgnore)[0]
$testLicenseTemplate = (Get-GitHubLicense)[0].key
$newGitHubRepositoryParms = @{
RepositoryName = $templateRepoName
Description = $defaultRepoDesc
GitIgnoreTemplate = $testGitIgnoreTemplate
LicenseTemplate = $testLicenseTemplate
IsTemplate = $true
}
$templateRepo = New-GitHubRepository @newGitHubRepositoryParms
}
Context 'When creating a public repository from a template' {
BeforeAll {
$repoName = ([Guid]::NewGuid().Guid)
$newRepoDesc = 'New Repo Description'
$newGitHubRepositoryFromTemplateParms = @{
RepositoryName = $templateRepoName
OwnerName = $templateRepo.owner.login
TargetOwnerName = $ownerName
TargetRepositoryName = $repoName
Description = $newRepoDesc
}
$repo = New-GitHubRepositoryFromTemplate @newGitHubRepositoryFromTemplateParms
}
It 'Should support pipeline input for the uri parameter' {
$newGitHubRepositoryFromTemplateParms = @{
TargetOwnerName = $ownerName
TargetRepositoryName = $repoName
}
{ $templateRepo | New-GitHubRepositoryFromTemplate @newGitHubRepositoryFromTemplateParms -WhatIf } |
Should -Not -Throw
}
It 'Should have the expected type and addititional properties' {
$repo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository'
$repo.name | Should -Be $repoName
$repo.private | Should -BeFalse
$repo.owner.login | Should -Be $script:ownerName
$repo.description | Should -Be $newRepoDesc
$repo.is_template | Should -BeFalse
$repo.RepositoryId | Should -Be $repo.id
$repo.RepositoryUrl | Should -Be $repo.html_url
}
It 'Should have created a .gitignore file' {
{ Get-GitHubContent -Uri $repo.svn_url -Path '.gitignore' } | Should -Not -Throw
}
It 'Should have created a LICENSE file' {
{ Get-GitHubContent -Uri $repo.svn_url -Path 'LICENSE' } | Should -Not -Throw
}
AfterAll {
if (Get-Variable -Name repo -ErrorAction SilentlyContinue)
{
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}
AfterAll {
if (Get-Variable -Name templateRepo -ErrorAction SilentlyContinue)
{
Remove-GitHubRepository -Uri $templateRepo.svn_url -Confirm:$false
}
}
}
Describe 'Getting repositories' {
Context 'For authenticated user' {
BeforeAll -Scriptblock {
$publicRepo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
$privateRepo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit -Private
}
It "Should have the public repo" {
$publicRepos = @(Get-GitHubRepository -Visibility Public)
$privateRepos = @(Get-GitHubRepository -Visibility Private)
$publicRepo.name | Should -BeIn $publicRepos.name
$publicRepo.name | Should -Not -BeIn $privateRepos.name
}
It "Should have the private repo" {
$publicRepos = @(Get-GitHubRepository -Visibility Public)
$privateRepos = @(Get-GitHubRepository -Visibility Private)
$privateRepo.name | Should -BeIn $privateRepos.name
$privateRepo.name | Should -Not -BeIn $publicRepos.name
}
It 'Should not permit bad combination of parameters' {
{ Get-GitHubRepository -Type All -Visibility All } | Should -Throw
{ Get-GitHubRepository -Type All -Affiliation Owner } | Should -Throw
}
AfterAll -ScriptBlock {
Remove-GitHubRepository -Uri $publicRepo.svn_url -Confirm:$false
Remove-GitHubRepository -Uri $privateRepo.svn_url -Confirm:$false
}
}
Context 'For any user' {
It "Should have results for The Octocat" {
$repos = @(Get-GitHubRepository -OwnerName 'octocat' -Type Public)
$repos.Count | Should -BeGreaterThan 0
$repos[0].owner.login | Should -Be 'octocat'
}
}
Context 'For organizations' {
BeforeAll -Scriptblock {
$repo = New-GitHubRepository -OrganizationName $script:organizationName -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
}
It "Should have results for the organization" {
$repos = @(Get-GitHubRepository -OrganizationName $script:organizationName -Type All)
$repo.name | Should -BeIn $repos.name
}
AfterAll -ScriptBlock {
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
Context 'For public repos' {
# Skipping these tests for now, as it would run for a _very_ long time.
# No obviously good way to verify this.
}
Context 'For a specific repo' {
BeforeAll -ScriptBlock {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
}
It "Should be a single result using Uri ParameterSet" {
$result = Get-GitHubRepository -Uri $repo.svn_url
$result | Should -BeOfType PSCustomObject
}
It "Should be a single result using Elements ParameterSet" {
$result = Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name
$result | Should -BeOfType PSCustomObject
}
It 'Should not permit additional parameters' {
{ Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Type All } | Should -Throw
}
It 'Should require both OwnerName and RepositoryName' {
{ Get-GitHubRepository -RepositoryName $repo.name } | Should -Throw
{ Get-GitHubRepository -Uri "https://github.com/$script:ownerName" } | Should -Throw
}
AfterAll -ScriptBlock {
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}
Describe 'Deleting repositories' {
Context -Name 'For deleting a repository' -Fixture {
BeforeEach -ScriptBlock {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -Description $defaultRepoDesc -AutoInit
}
It 'Should get no content using -Confirm:$false' {
Remove-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Confirm:$false
{ Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name } | Should -Throw
}
It 'Should get no content using -Force' {
Remove-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Force
{ Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name } | Should -Throw
}
}
}
Describe 'Renaming repositories' {
Context -Name 'For renaming a repository' -Fixture {
BeforeEach -Scriptblock {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
$suffixToAddToRepo = "_renamed"
$newRepoName = "$($repo.name)$suffixToAddToRepo"
}
It "Should have the expected new repository name - by URI" {
$renamedRepo = Rename-GitHubRepository -Uri ($repo.RepositoryUrl) -NewName $newRepoName -Force
$renamedRepo.name | Should -Be $newRepoName
}
It "Should have the expected new repository name - by Elements" {
$renamedRepo = Rename-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -NewName $newRepoName -Confirm:$false
$renamedRepo.name | Should -Be $newRepoName
}
It "Should work via the pipeline" {
$renamedRepo = $repo | Rename-GitHubRepository -NewName $newRepoName -Confirm:$false
$renamedRepo.name | Should -Be $newRepoName
$renamedRepo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository'
}
It "Should be possible to rename with Update-GitHubRepository too" {
$renamedRepo = $repo | Update-GitHubRepository -NewName $newRepoName -Confirm:$false
$renamedRepo.name | Should -Be $newRepoName
$renamedRepo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository'
}
AfterEach -Scriptblock {
Remove-GitHubRepository -Uri "$($repo.svn_url)$suffixToAddToRepo" -Confirm:$false
}
}
}
Describe 'GitHubRepositories\Update-GitHubRepository' {
Context -Name 'When updating a public repository' -Fixture {
BeforeAll -ScriptBlock {
$repoName = ([Guid]::NewGuid().Guid)
$repo = New-GitHubRepository -RepositoryName $repoName
}
Context -Name 'When updating a repository with all possible settings' {
BeforeAll -ScriptBlock {
$updateGithubRepositoryParms = @{
OwnerName = $repo.owner.login
RepositoryName = $repoName
Private = $true
Description = $defaultRepoDesc
HomePage = $defaultRepoHomePage
NoIssues = $true
NoProjects = $true
NoWiki = $true
DisallowSquashMerge = $true
DisallowMergeCommit = $true
DisallowRebaseMerge = $false
DeleteBranchOnMerge = $true
IsTemplate = $true
}
$updatedRepo = Update-GitHubRepository @updateGithubRepositoryParms
}
It 'Should return an object of the correct type' {
$updatedRepo | Should -BeOfType PSCustomObject
}
It 'Should return the correct properties' {
$updatedRepo.name | Should -Be $repoName
$updatedRepo.private | Should -BeTrue
$updatedRepo.description | Should -Be $defaultRepoDesc
$updatedRepo.homepage | Should -Be $defaultRepoHomePage
$updatedRepo.has_issues | Should -BeFalse
$updatedRepo.has_projects | Should -BeFalse
$updatedRepo.has_Wiki | Should -BeFalse
$updatedRepo.allow_squash_merge | Should -BeFalse
$updatedRepo.allow_merge_commit | Should -BeFalse
$updatedRepo.allow_rebase_merge | Should -BeTrue
$updatedRepo.delete_branch_on_merge | Should -BeTrue
$updatedRepo.is_template | Should -BeTrue
}
}
Context -Name 'When updating a repository with alternative Merge settings' {
BeforeAll -ScriptBlock {
$updateGithubRepositoryParms = @{
OwnerName = $repo.owner.login
RepositoryName = $repoName
DisallowSquashMerge = $true
DisallowMergeCommit = $false
DisallowRebaseMerge = $true
}
$updatedRepo = Update-GitHubRepository @updateGithubRepositoryParms
}
It 'Should return an object of the correct type' {
$updatedRepo | Should -BeOfType PSCustomObject
}
It 'Should return the correct properties' {
$updatedRepo.name | Should -Be $repoName
$updatedRepo.allow_squash_merge | Should -BeFalse
$updatedRepo.allow_merge_commit | Should -BeTrue
$updatedRepo.allow_rebase_merge | Should -BeFalse
}
}
Context -Name 'When updating a repository with the Archive setting' {
BeforeAll -ScriptBlock {
$updateGithubRepositoryParms = @{
OwnerName = $repo.owner.login
RepositoryName = $repoName
Archived = $true
}
$updatedRepo = Update-GitHubRepository @updateGithubRepositoryParms
}
It 'Should return an object of the correct type' {
$updatedRepo | Should -BeOfType PSCustomObject
}
It 'Should return the correct properties' {
$updatedRepo.name | Should -Be $repoName
$updatedRepo.archived | Should -BeTrue
}
}
AfterAll -ScriptBlock {
if ($repo)
{
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}
Context -Name 'When updating a private repository' -Fixture {
BeforeAll -ScriptBlock {
$repoName = ([Guid]::NewGuid().Guid)
$repo = New-GitHubRepository -RepositoryName $repoName -Private
$updateGithubRepositoryParms = @{
OwnerName = $repo.owner.login
RepositoryName = $repoName
Private = $false
}
$updatedRepo = Update-GitHubRepository @updateGithubRepositoryParms
}
It 'Should return an object of the correct type' {
$updatedRepo | Should -BeOfType PSCustomObject
}
It 'Should return the correct properties' {
$updatedRepo.name | Should -Be $repoName
$updatedRepo.private | Should -BeFalse
}
AfterAll -ScriptBlock {
if ($repo)
{
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}
}
Describe 'Common user repository pipeline scenarios' {
Context 'For authenticated user' {
BeforeAll -Scriptblock {
$repo = ([Guid]::NewGuid().Guid) | New-GitHubRepository -AutoInit
}
It "Should have expected additional properties and type after creation" {
$repo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository'
$repo.RepositoryUrl | Should -Be (Join-GitHubUri -OwnerName $script:ownerName -RepositoryName $repo.name)
$repo.RepositoryId | Should -Be $repo.id
$repo.owner.PSObject.TypeNames[0] | Should -Be 'GitHub.User'
}
It "Should have expected additional properties and type after creation" {
$returned = ($repo | Get-GitHubRepository)
$returned.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository'
$returned.RepositoryUrl | Should -Be (Join-GitHubUri -OwnerName $script:ownerName -RepositoryName $returned.name)
$returned.RepositoryId | Should -Be $returned.id
$returned.owner.PSObject.TypeNames[0] | Should -Be 'GitHub.User'
}
It "Should get the repository by user" {
$repos = @($script:ownerName | Get-GitHubUser | Get-GitHubRepository)
$repos.name | Should -Contain $repo.name
}
It 'Should be removable by the pipeline' {
($repo | Remove-GitHubRepository -Confirm:$false) | Should -BeNullOrEmpty
{ $repo | Get-GitHubRepository } | Should -Throw
}
}
}
Describe 'Common organization repository pipeline scenarios' {
Context 'For organization' {
BeforeAll -Scriptblock {
$org = [PSCustomObject]@{'OrganizationName' = $script:organizationName}
$repo = $org | New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
}
It "Should have expected additional properties and type after creation" {
$repo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository'
$repo.RepositoryUrl | Should -Be (Join-GitHubUri -OwnerName $script:organizationName -RepositoryName $repo.name)
$repo.RepositoryId | Should -Be $repo.id
$repo.owner.PSObject.TypeNames[0] | Should -Be 'GitHub.User'
$repo.organization.PSObject.TypeNames[0] | Should -Be 'GitHub.Organization'
$repo.organization.OrganizationName | Should -Be $repo.organization.login
$repo.organization.OrganizationId | Should -Be $repo.organization.id
}
It "Should have expected additional properties and type after creation" {
$returned = ($repo | Get-GitHubRepository)
$returned.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository'
$returned.RepositoryUrl | Should -Be (Join-GitHubUri -OwnerName $script:organizationName -RepositoryName $returned.name)
$returned.RepositoryId | Should -Be $returned.id
$returned.owner.PSObject.TypeNames[0] | Should -Be 'GitHub.User'
$returned.organization.PSObject.TypeNames[0] | Should -Be 'GitHub.Organization'
$returned.organization.OrganizationName | Should -Be $returned.organization.login
$returned.organization.OrganizationId | Should -Be $returned.organization.id
}
It 'Should be removable by the pipeline' {
($repo | Remove-GitHubRepository -Confirm:$false) | Should -BeNullOrEmpty
{ $repo | Get-GitHubRepository } | Should -Throw
}
}
}
Describe 'Get/set repository topic' {
Context -Name 'For creating and getting a repository topic' -Fixture {
BeforeAll -ScriptBlock {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
}
It 'Should have the expected topic' {
$null = Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name -Topic $defaultRepoTopic
$topic = Get-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name
$topic.names | Should -Be $defaultRepoTopic
}
It 'Should have no topics' {
$null = Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name -Clear
$topic = Get-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name
$topic.names | Should -BeNullOrEmpty
}
It 'Should have the expected topic (using repo via pipeline)' {
$null = $repo | Set-GitHubRepositoryTopic -Topic $defaultRepoTopic
$topic = $repo | Get-GitHubRepositoryTopic
$topic.names | Should -Be $defaultRepoTopic
$topic.PSObject.TypeNames[0] | Should -Be 'GitHub.RepositoryTopic'
$topic.RepositoryUrl | Should -Be $repo.RepositoryUrl
}
It 'Should have the expected topic (using topic via pipeline)' {
$null = $defaultRepoTopic | Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name
$topic = $repo | Get-GitHubRepositoryTopic
$topic.names | Should -Be $defaultRepoTopic
$topic.PSObject.TypeNames[0] | Should -Be 'GitHub.RepositoryTopic'
$topic.RepositoryUrl | Should -Be $repo.RepositoryUrl
}
It 'Should have the expected multi-topic (using topic via pipeline)' {
$topics = @('one', 'two')
$null = $topics | Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name
$result = $repo | Get-GitHubRepositoryTopic
$result.PSObject.TypeNames[0] | Should -Be 'GitHub.RepositoryTopic'
$result.RepositoryUrl | Should -Be $repo.RepositoryUrl
$result.names.count | Should -Be $topics.Count
foreach ($topic in $topics)
{
$result.names | Should -Contain $topic
}
}
AfterAll -ScriptBlock {
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}
Describe 'Get repository languages' {
Context -Name 'For getting repository languages' -Fixture {
BeforeAll -ScriptBlock {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
}
It 'Should be empty' {
$languages = Get-GitHubRepositoryLanguage -OwnerName $repo.owner.login -RepositoryName $repo.name
$languages | Should -BeNullOrEmpty
}
It 'Should contain PowerShell' {
$languages = Get-GitHubRepositoryLanguage -OwnerName "microsoft" -RepositoryName "PowerShellForGitHub"
$languages.PowerShell | Should -Not -BeNullOrEmpty
$languages.PSObject.TypeNames[0] | Should -Be 'GitHub.RepositoryLanguage'
}
It 'Should contain PowerShell (via pipeline)' {
$psfg = Get-GitHubRepository -OwnerName "microsoft" -RepositoryName "PowerShellForGitHub"
$languages = $psfg | Get-GitHubRepositoryLanguage
$languages.PowerShell | Should -Not -BeNullOrEmpty
$languages.PSObject.TypeNames[0] | Should -Be 'GitHub.RepositoryLanguage'
}
AfterAll -ScriptBlock {
Remove-GitHubRepository -Uri $repo.svn_url -Force
}
}
}
Describe 'Get repository tags' {
Context -Name 'For getting repository tags' -Fixture {
BeforeAll -ScriptBlock {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
}
It 'Should be empty' {
$tags = Get-GitHubRepositoryTag -OwnerName $repo.owner.login -RepositoryName $repo.name
$tags | Should -BeNullOrEmpty
}
It 'Should be empty (via pipeline)' {
$tags = $repo | Get-GitHubRepositoryTag
$tags | Should -BeNullOrEmpty
}
AfterAll -ScriptBlock {
Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}
}
}
Describe 'Contributors for a repository' {
BeforeAll {
$repo = New-GitHubRepository -RepositoryName ([guid]::NewGuid().Guid) -AutoInit
}
AfterAll {
$null = Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false
}
Context -Name 'Obtaining contributors for repository' -Fixture {
$contributors = @(Get-GitHubRepositoryContributor -Uri $repo.RepositoryUrl)
It 'Should return expected number of contributors' {
$contributors.Count | Should -Be 1
$contributors[0].PSObject.TypeNames[0] = 'GitHub.User'
}
}
Context -Name 'Obtaining contributors for repository (via pipeline)' -Fixture {
$contributors = @($repo | Get-GitHubRepositoryContributor -IncludeStatistics)
It 'Should return expected number of contributors' {
$contributors.Count | Should -Be 1
$contributors[0].PSObject.TypeNames[0] = 'GitHub.User'
}
}
Context -Name 'Obtaining contributor statistics for repository' -Fixture {
$stats = @(Get-GitHubRepositoryContributor -Uri $repo.RepositoryUrl -IncludeStatistics)
It 'Should return expected number of contributors' {
$stats.Count | Should -Be 1
$stats[0].PSObject.TypeNames[0] = 'GitHub.RepositoryContributorStatistics'
$stats[0].author.PSObject.TypeNames[0] = 'GitHub.User'
}
}
}
Describe 'Collaborators for a repository' {
BeforeAll {
$repo = New-GitHubRepository -RepositoryName ([guid]::NewGuid().Guid) -AutoInit
}
AfterAll {
$null = Remove-GitHubRepository -Uri $repo.RepositoryUrl -Confirm:$false
}
Context -Name 'Obtaining collaborators for repository' -Fixture {
$collaborators = @(Get-GitHubRepositoryCollaborator -Uri $repo.RepositoryUrl)
It 'Should return expected number of collaborators' {
$collaborators.Count | Should -Be 1
$collaborators[0].PSObject.TypeNames[0] = 'GitHub.User'
}
}
Context -Name 'Obtaining collaborators for repository (via pipeline)' -Fixture {
$collaborators = @($repo | Get-GitHubRepositoryCollaborator)
It 'Should return expected number of collaborators' {
$collaborators.Count | Should -Be 1
$collaborators[0].PSObject.TypeNames[0] = 'GitHub.User'
}
}
}
Describe 'GitHubRepositories\Test-GitHubRepositoryVulnerabilityAlert' {
BeforeAll -ScriptBlock {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid)
}
Context 'When the Git Hub Repository Vulnerability Alert Status is Enabled' {
BeforeAll -ScriptBlock {
Enable-GitHubRepositoryVulnerabilityAlert -Uri $repo.svn_url
$result = Test-GitHubRepositoryVulnerabilityAlert -Uri $repo.svn_url
}
It 'Should return an object of the correct type' {
$result | Should -BeOfType System.Boolean
}
It 'Should return the correct value' {
$result | Should -Be $true
}
}
Context 'When the Git Hub Repository Vulnerability Alert Status is Disabled' {
BeforeAll -ScriptBlock {
Disable-GitHubRepositoryVulnerabilityAlert -Uri $repo.svn_url
$status = Test-GitHubRepositoryVulnerabilityAlert -Uri $repo.svn_url
}
It 'Should return an object of the correct type' {
$status | Should -BeOfType System.Boolean
}
It 'Should return the correct value' {
$status | Should -BeFalse
}
}
Context 'When Invoke-GHRestMethod returns an unexpected error' {
It 'Should throw' {
$getGitHubRepositoryVulnerabilityAlertParms = @{
OwnerName = 'octocat'
RepositoryName = 'IncorrectRepostioryName'
}
{ Test-GitHubRepositoryVulnerabilityAlert @getGitHubRepositoryVulnerabilityAlertParms } |
Should -Throw
}
}
AfterAll -ScriptBlock {
Remove-GitHubRepository -Uri $repo.svn_url -Force
}
}
Describe 'GitHubRepositories\Enable-GitHubRepositoryVulnerabilityAlert' {
BeforeAll {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid)
}
Context 'When Enabling GitHub Repository Vulnerability Alerts' {
It 'Should not throw' {
{ Enable-GitHubRepositoryVulnerabilityAlert -Uri $repo.svn_url } |
Should -Not -Throw
}
}
AfterAll -ScriptBlock {
Remove-GitHubRepository -Uri $repo.svn_url -Force
}
}
Describe 'GitHubRepositories\Disable-GitHubRepositoryVulnerabilityAlert' {
BeforeAll {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid)
Enable-GitHubRepositoryVulnerabilityAlert -Uri $repo.svn_url
}
Context 'When Disabling GitHub Repository Vulnerability Alerts' {
It 'Should not throw' {
{ Disable-GitHubRepositoryVulnerabilityAlert -Uri $repo.svn_url } |
Should -Not -Throw
}
}
AfterAll -ScriptBlock {
Remove-GitHubRepository -Uri $repo.svn_url -Force
}
}
Describe 'GitHubRepositories\Enable-GitHubRepositorySecurityFix' {
BeforeAll {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid)
}
Context 'When Enabling GitHub Repository Security Fixes' {
It 'Should not throw' {
{ Enable-GitHubRepositorySecurityFix -Uri $repo.svn_url } |
Should -Not -Throw
}
}
AfterAll -ScriptBlock {
Remove-GitHubRepository -Uri $repo.svn_url -Force
}
}
Describe 'GitHubRepositories\Disable-GitHubRepositorySecurityFix' {
BeforeAll {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid)