Skip to content

Commit 10b6394

Browse files
committed
migrate updater tests to pester
1 parent 49c5b61 commit 10b6394

File tree

6 files changed

+291
-345
lines changed

6 files changed

+291
-345
lines changed

updater/tests/common/test-utils.ps1

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
. "$PSScriptRoot/common/test-utils.ps1"
21

3-
RunTest 'get-changelog with existing versions' {
4-
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
5-
-RepoUrl 'https://github.com/getsentry/github-workflows' -OldTag '1.0.0' -NewTag '2.1.0'
6-
$expected = @'
2+
Describe 'get-changelog' {
3+
It 'with existing versions' {
4+
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
5+
-RepoUrl 'https://github.com/getsentry/github-workflows' -OldTag '1.0.0' -NewTag '2.1.0'
6+
$expected = @'
77
## Changelog
88
### 2.1.0
99
@@ -29,33 +29,33 @@ RunTest 'get-changelog with existing versions' {
2929
- Changelog section parsing when an entry text contains the section name in the text ([#25](https://github-redirect.dependabot.com/getsentry/github-workflows/pull/25))
3030
'@
3131

32-
AssertEqual $expected $actual
33-
}
32+
$actual | Should -Be $expected
33+
}
3434

35-
RunTest 'get-changelog with missing versions' {
36-
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
37-
-RepoUrl 'https://github.com/getsentry/sentry-javascript' -OldTag 'XXXXXXX' -NewTag 'YYYYYYYYY'
38-
AssertEqual '' $actual
39-
}
35+
It 'with missing versions' {
36+
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
37+
-RepoUrl 'https://github.com/getsentry/sentry-javascript' -OldTag 'XXXXXXX' -NewTag 'YYYYYYYYY'
38+
$actual | Should -BeNullOrEmpty
39+
}
4040

41-
RunTest 'get-changelog with missing repo' {
42-
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
43-
-RepoUrl 'https://github.com/getsentry/foo-bar' -OldTag 'XXXXXXX' -NewTag 'YYYYYYYYY'
44-
# May print a warning but still returns (an empty string)
45-
AssertEqual '' $actual
46-
}
41+
It 'with missing repo' {
42+
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
43+
-RepoUrl 'https://github.com/getsentry/foo-bar' -OldTag 'XXXXXXX' -NewTag 'YYYYYYYYY'
44+
# May print a warning but still returns (an empty string)
45+
$actual | Should -BeNullOrEmpty
46+
}
4747

48-
RunTest 'get-changelog with unsupported repo' {
49-
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
50-
-RepoUrl 'https://dart.googlesource.com/args' -OldTag 'XXXXXXX' -NewTag 'YYYYYYYYY'
51-
# May print a warning but still returns (an empty string)
52-
AssertEqual '' $actual
53-
}
48+
It 'with unsupported repo' {
49+
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
50+
-RepoUrl 'https://dart.googlesource.com/args' -OldTag 'XXXXXXX' -NewTag 'YYYYYYYYY'
51+
# May print a warning but still returns (an empty string)
52+
$actual | Should -BeNullOrEmpty
53+
}
5454

55-
RunTest 'get-changelog removes at-mentions' {
56-
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
57-
-RepoUrl 'https://github.com/getsentry/sentry-cli' -OldTag '2.1.0' -NewTag '2.2.0'
58-
$expected = @'
55+
It 'removes at-mentions' {
56+
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
57+
-RepoUrl 'https://github.com/getsentry/sentry-cli' -OldTag '2.1.0' -NewTag '2.2.0'
58+
$expected = @'
5959
## Changelog
6060
### 2.2.0
6161
@@ -65,13 +65,13 @@ RunTest 'get-changelog removes at-mentions' {
6565
- ref: Skip protected zip files when uploading debug files ([#1245](https://github-redirect.dependabot.com/getsentry/sentry-cli/issues/1245)) by kamilogorek
6666
'@
6767

68-
AssertEqual $expected $actual
69-
}
68+
$actual | Should -Be $expected
69+
}
7070

71-
RunTest "get-changelog removes doesn't duplicate PR links" {
72-
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
73-
-RepoUrl 'https://github.com/getsentry/sentry-native' -OldTag '0.4.16' -NewTag '0.4.17'
74-
$expected = @'
71+
It "get-changelog removes doesn't duplicate PR links" {
72+
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
73+
-RepoUrl 'https://github.com/getsentry/sentry-native' -OldTag '0.4.16' -NewTag '0.4.17'
74+
$expected = @'
7575
## Changelog
7676
### 0.4.17
7777
@@ -86,20 +86,21 @@ Features, fixes and improvements in this release have been contributed by:
8686
- [AenBleidd](https://github-redirect.dependabot.com/AenBleidd)
8787
'@
8888

89-
AssertEqual $expected $actual
90-
}
91-
92-
RunTest 'get-changelog truncates too long text' {
93-
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
94-
-RepoUrl 'https://github.com/getsentry/sentry-cli' -OldTag '1.0.0' -NewTag '2.4.0'
95-
if ($actual.Length -gt 61000)
96-
{
97-
throw "Expected the content to be truncated to less-than 61k characters, but got: $($actual.Length)"
89+
$actual | Should -Be $expected
9890
}
99-
$msg = "Changelog content truncated by [0-9]+ characters because it was over the limit \(60000\) and wouldn't fit into PR description."
100-
if ("$actual" -notmatch $msg)
101-
{
102-
Write-Host $actual
103-
throw "Expected changelog to contain message '$msg'"
91+
92+
It 'truncates too long text' {
93+
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
94+
-RepoUrl 'https://github.com/getsentry/sentry-cli' -OldTag '1.0.0' -NewTag '2.4.0'
95+
if ($actual.Length -gt 61000)
96+
{
97+
throw "Expected the content to be truncated to less-than 61k characters, but got: $($actual.Length)"
98+
}
99+
$msg = "Changelog content truncated by [0-9]+ characters because it was over the limit \(60000\) and wouldn't fit into PR description."
100+
if ("$actual" -notmatch $msg)
101+
{
102+
Write-Host $actual
103+
throw "Expected changelog to contain message '$msg'"
104+
}
104105
}
105106
}
Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
Set-StrictMode -Version latest
22

3-
. "$PSScriptRoot/common/test-utils.ps1"
4-
5-
foreach ($repoUrl in @('https://github.com/getsentry/github-workflows', '[email protected]:getsentry/github-workflows.git'))
6-
{
7-
function NonBotCommits([Parameter(Mandatory = $true)][string] $branch)
8-
{
9-
$result = & "$PSScriptRoot/../scripts/nonbot-commits.ps1" -RepoUrl $repoUrl -MainBranch 'main' -PrBranch $branch
10-
if (-not $?)
11-
{
12-
throw $result
13-
}
14-
elseif ($LASTEXITCODE -ne 0)
15-
{
16-
throw "Script finished with exit code $LASTEXITCODE"
3+
Describe 'nonbot-commits' {
4+
Context 'Repo <_>' -ForEach @('https://github.com/getsentry/github-workflows', '[email protected]:getsentry/github-workflows.git') {
5+
BeforeEach {
6+
$repoUrl = $_
7+
function NonBotCommits([Parameter(Mandatory = $true)][string] $branch)
8+
{
9+
$result = & "$PSScriptRoot/../scripts/nonbot-commits.ps1" -RepoUrl $repoUrl -MainBranch 'main' -PrBranch $branch
10+
if (-not $?)
11+
{
12+
throw $result
13+
}
14+
elseif ($LASTEXITCODE -ne 0)
15+
{
16+
throw "Script finished with exit code $LASTEXITCODE"
17+
}
18+
$result
19+
}
1720
}
18-
$result
19-
}
2021

21-
RunTest 'empty-if-all-commits-by-bot' {
22-
$commits = NonBotCommits 'deps/updater/tests/sentry-cli.properties'
23-
AssertEqual '' "$commits"
24-
}
22+
It 'empty-if-all-commits-by-bot' {
23+
$commits = NonBotCommits 'deps/updater/tests/sentry-cli.properties'
24+
$commits | Should -BeNullOrEmpty
25+
}
2526

26-
RunTest 'empty-if-branch-doesnt-exist' {
27-
$commits = NonBotCommits 'non-existent-branch'
28-
AssertEqual '' "$commits"
29-
}
27+
It 'empty-if-branch-doesnt-exist' {
28+
$commits = NonBotCommits 'non-existent-branch'
29+
$commits | Should -BeNullOrEmpty
30+
}
3031

31-
RunTest 'non-empty-if-changed' {
32-
$commits = NonBotCommits 'test/nonbot-commits'
33-
AssertEqual '0b7d9cc test: keep this branch' "$commits"
32+
It 'non-empty-if-changed' {
33+
$commits = NonBotCommits 'test/nonbot-commits'
34+
$commits | Should -Be '0b7d9cc test: keep this branch'
35+
}
3436
}
35-
}
37+
}
Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
. "$PSScriptRoot/common/test-utils.ps1"
21

3-
function SortVersions([Parameter(Mandatory = $true)][string[]] $List)
4-
{
5-
$result = & "$PSScriptRoot/../scripts/sort-versions.ps1" $List
6-
if (-not $?)
2+
BeforeAll {
3+
function SortVersions([Parameter(Mandatory = $true)][string[]] $List)
74
{
8-
throw $result
5+
$result = & "$PSScriptRoot/../scripts/sort-versions.ps1" $List
6+
if (-not $?)
7+
{
8+
throw $result
9+
}
10+
$result
911
}
10-
$result
1112
}
1213

13-
RunTest "sort standard versions" {
14-
$sorted = SortVersions @('3.0.0', '5.4.11', 'v1.2.3', '5.4.1')
15-
AssertEqual @('v1.2.3', '3.0.0', '5.4.1', '5.4.11') $sorted
16-
}
14+
Describe 'sort-versions' {
15+
It 'standard versions' {
16+
$sorted = SortVersions @('3.0.0', '5.4.11', 'v1.2.3', '5.4.1')
17+
$sorted | Should -Be @('v1.2.3', '3.0.0', '5.4.1', '5.4.11')
18+
}
1719

18-
RunTest "sort standard versions v2" {
19-
$sorted = SortVersions @('3.0.0', 'v6.0', '5.4.11', '5.5', 'v1.2.3', '5.4.1')
20-
AssertEqual @('v1.2.3', '3.0.0', '5.4.1', '5.4.11', '5.5', 'v6.0') $sorted
21-
}
20+
It 'standard versions v2' {
21+
$sorted = SortVersions @('3.0.0', 'v6.0', '5.4.11', '5.5', 'v1.2.3', '5.4.1')
22+
$sorted | Should -Be @('v1.2.3', '3.0.0', '5.4.1', '5.4.11', '5.5', 'v6.0')
23+
}
2224

23-
# https://semver.org/#spec-item-11
24-
RunTest "sort with pre-releases" {
25-
$sorted = SortVersions @('1.0.0-rc.1', '1.0.0', '1.0.0-beta.11', '1.0.0-alpha.1', '1.0.0-beta', '1.0.0-alpha.beta', '1.0.0-alpha', '1.0.0-beta.2')
26-
AssertEqual @('1.0.0-alpha', '1.0.0-alpha.1', '1.0.0-alpha.beta', '1.0.0-beta', '1.0.0-beta.2', '1.0.0-beta.11', '1.0.0-rc.1', '1.0.0') $sorted
25+
# https://semver.org/#spec-item-11
26+
It 'pre-releases' {
27+
$sorted = SortVersions @('1.0.0-rc.1', '1.0.0', '1.0.0-beta.11', '1.0.0-alpha.1', '1.0.0-beta', '1.0.0-alpha.beta', '1.0.0-alpha', '1.0.0-beta.2')
28+
$sorted | Should -Be @('1.0.0-alpha', '1.0.0-alpha.1', '1.0.0-alpha.beta', '1.0.0-beta', '1.0.0-beta.2', '1.0.0-beta.11', '1.0.0-rc.1', '1.0.0')
29+
}
2730
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
. "$PSScriptRoot/common/test-utils.ps1"
21

3-
$testCases = Get-ChildItem "$PSScriptRoot/testdata/changelog/"
2+
$testCases =
43

5-
foreach ($testCase in $testCases)
6-
{
7-
RunTest $testCase {
4+
Describe 'update-changelog' {
5+
It '<_>' -ForEach @(Get-ChildItem "$PSScriptRoot/testdata/changelog/") {
6+
$testCase = $_
87
Copy-Item "$testCase/CHANGELOG.md.original" "$testCase/CHANGELOG.md"
98

109
pwsh -WorkingDirectory $testCase -File "$PSScriptRoot/../scripts/update-changelog.ps1" `
@@ -16,6 +15,6 @@ foreach ($testCase in $testCases)
1615
-NewTag '7.17.0' `
1716
-Section 'Dependencies'
1817

19-
AssertEqual (Get-Content "$testCase/CHANGELOG.md.expected") (Get-Content "$testCase/CHANGELOG.md")
18+
Get-Content "$testCase/CHANGELOG.md" | Should -Be (Get-Content "$testCase/CHANGELOG.md.expected")
2019
}
2120
}

0 commit comments

Comments
 (0)