Skip to content

Commit 80fe8ed

Browse files
authored
test: use Pester instead of self-rolled util scripts (#81)
* rename test files to accomodate pester * migrate updater tests to pester * update ci
1 parent 378130a commit 80fe8ed

12 files changed

+430
-499
lines changed

.github/workflows/script-tests.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ jobs:
2020

2121
- uses: actions/checkout@v4
2222

23-
- name: Install make
24-
if: ${{ matrix.host == 'macos' }}
25-
run: |
26-
brew install make
27-
echo "$(brew --prefix)/opt/make/libexec/gnubin" >> $GITHUB_PATH
28-
29-
- run: make test
23+
- run: Invoke-Pester
3024
working-directory: updater
25+
shell: pwsh

updater/Makefile

Lines changed: 0 additions & 10 deletions
This file was deleted.

updater/tests/common/test-utils.ps1

Lines changed: 0 additions & 70 deletions
This file was deleted.

updater/tests/get-changelog.Tests.ps1

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
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 = @'
7+
## Changelog
8+
### 2.1.0
9+
10+
#### Features
11+
12+
- New reusable workflow, `danger.yml`, to check Pull Requests with predefined rules ([#34](https://github-redirect.dependabot.com/getsentry/github-workflows/pull/34))
13+
14+
### 2.0.0
15+
16+
#### Changes
17+
18+
- Rename `api_token` secret to `api-token` ([#21](https://github-redirect.dependabot.com/getsentry/github-workflows/pull/21))
19+
- Change changelog target section header from "Features" to "Dependencies" ([#19](https://github-redirect.dependabot.com/getsentry/github-workflows/pull/19))
20+
21+
#### Features
22+
23+
- Add `pr-strategy` switch to choose between creating new PRs or updating an existing one ([#22](https://github-redirect.dependabot.com/getsentry/github-workflows/pull/22))
24+
- Add `changelog-section` input setting to specify target changelog section header ([#19](https://github-redirect.dependabot.com/getsentry/github-workflows/pull/19))
25+
26+
#### Fixes
27+
28+
- Preserve changelog bullet-point format ([#20](https://github-redirect.dependabot.com/getsentry/github-workflows/pull/20))
29+
- 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))
30+
'@
31+
32+
$actual | Should -Be $expected
33+
}
34+
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+
}
40+
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+
}
47+
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+
}
54+
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 = @'
59+
## Changelog
60+
### 2.2.0
61+
62+
#### Various fixes & improvements
63+
64+
- feat: Compute and upload il2cpp line mappings ([#1248](https://github-redirect.dependabot.com/getsentry/sentry-cli/issues/1248)) by loewenheim
65+
- ref: Skip protected zip files when uploading debug files ([#1245](https://github-redirect.dependabot.com/getsentry/sentry-cli/issues/1245)) by kamilogorek
66+
'@
67+
68+
$actual | Should -Be $expected
69+
}
70+
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 = @'
75+
## Changelog
76+
### 0.4.17
77+
78+
**Fixes**:
79+
80+
- sentry-native now successfully builds when examples aren't included. ([#702](https://github-redirect.dependabot.com/getsentry/sentry-native/pull/702))
81+
82+
**Thank you**:
83+
84+
Features, fixes and improvements in this release have been contributed by:
85+
86+
- [AenBleidd](https://github-redirect.dependabot.com/AenBleidd)
87+
'@
88+
89+
$actual | Should -Be $expected
90+
}
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+
}
105+
}
106+
}

updater/tests/get-changelog.ps1

Lines changed: 0 additions & 105 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Set-StrictMode -Version latest
2+
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+
}
20+
}
21+
22+
It 'empty-if-all-commits-by-bot' {
23+
$commits = NonBotCommits 'deps/updater/tests/sentry-cli.properties'
24+
$commits | Should -BeNullOrEmpty
25+
}
26+
27+
It 'empty-if-branch-doesnt-exist' {
28+
$commits = NonBotCommits 'non-existent-branch'
29+
$commits | Should -BeNullOrEmpty
30+
}
31+
32+
It 'non-empty-if-changed' {
33+
$commits = NonBotCommits 'test/nonbot-commits'
34+
$commits | Should -Be '0b7d9cc test: keep this branch'
35+
}
36+
}
37+
}

updater/tests/nonbot-commits.ps1

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)