-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUpdate-GithubRelease.Tests.ps1
80 lines (74 loc) · 2.66 KB
/
Update-GithubRelease.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
. $(Resolve-Path "$PSScriptRoot/../../Tests/Shared.ps1")
Describe 'Update-GithubRelease' {
BeforeAll {
Write-Verbose 'Loading PowershellForGithub Module'
$UpdateGithubReleaseCommonParams = @{
Owner = 'Pester'
Repository = 'Pester'
Version = '2.1.5'
AccessToken = 'PesterToken'
Body = 'PesterBody'
ArtifactPath = [String](New-Item -ItemType File -Path TestDrive:/PesterArtifact)
WarningAction = 'SilentlyContinue'
}
}
It 'Should run <Action> for <MockFile> and remove <RemoveCount> releases' -Tag 'Test' {
$SCRIPT:MockFileName = $MockFile
[Int]$SCRIPT:RemoveReleaseInvokeCount = 0
Mock -ModuleName Press Get-GitHubReleaseAsset
Mock -ModuleName Press New-GitHubReleaseAsset
Mock -ModuleName Press Remove-GithubRelease
Mock -ModuleName Press Get-GithubRelease {
JsonMock Get-GithubRelease/$MockFileName.json
}
Mock -ModuleName Press -CommandName $Action -Verifiable -MockWith {
$SCRIPT:SetReleaseIdResult = $release
}
Update-GithubRelease @UpdateGithubReleaseCommonParams
if ($Action -eq 'Set-GithubRelease') {
$SCRIPT:SetReleaseIdResult | Should -Be $SetReleaseId
}
Should -InvokeVerifiable
Should -Invoke 'Remove-GithubRelease' -ModuleName Press -Exactly -Times $RemoveCount
} -TestCases @(
@{
MockFile = 'Null'
Action = 'New-GithubRelease'
RemoveCount = 0
}
@{
MockFile = 'ExistingDraft'
Action = 'Set-GitHubRelease'
RemoveCount = 0
SetReleaseId = 41097540
}
@{
MockFile = 'ExistingPublished'
Action = 'Set-GitHubRelease'
RemoveCount = 0
SetReleaseId = 51097999
}
@{
MockFile = 'EarlierMajorVersionDraft'
Action = 'New-GitHubRelease'
RemoveCount = 0
}
@{
MockFile = 'EarlierMinorVersionDraft'
Action = 'New-GitHubRelease'
RemoveCount = 1
}
@{
MockFile = 'SameVersionPublishedAndDraft'
Action = 'Set-GitHubRelease'
RemoveCount = 1
SetReleaseId = 51097999
}
@{
MockFile = 'MultiplePastDrafts'
Action = 'Set-GitHubRelease'
RemoveCount = 3 #Should not remove other major versions
SetReleaseId = 51097999 #Should select later dated one
}
)
}