Skip to content

Commit 6f95db3

Browse files
authored
feat: support envelopes in integration test (#58)
1 parent fe18d6e commit 6f95db3

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Sentry-CLI integration test action: support envelopes ([#58](https://github.com/getsentry/github-workflows/pull/58))
8+
39
## 2.7.0
410

511
### Features

sentry-cli/integration-test/action.psm1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,28 @@ class InvokeSentryResult
1717
return @($this.ServerStdOut | Where-Object { $_.StartsWith($prefix) } | ForEach-Object { $_.Substring($prefix.Length).Trim() })
1818
}
1919

20+
# Envelopes are collected to a list, each envelope body a single item.
21+
[string[]]Envelopes()
22+
{
23+
$envelopes = @()
24+
$this.ServerStdOut | ForEach-Object {
25+
if ($_.Trim() -eq "envelope start")
26+
{
27+
$envelope = ''
28+
}
29+
elseif ($_ -eq "envelope end")
30+
{
31+
$envelopes += $envelope
32+
$envelope = $null
33+
}
34+
elseif ($null -ne $envelope)
35+
{
36+
$envelope += $_ + "\n"
37+
}
38+
}
39+
return $envelopes
40+
}
41+
2042
[bool]HasErrors()
2143
{
2244
return $this.ServerStdErr.Length -gt 0

sentry-cli/integration-test/sentry-server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ def do_POST(self):
9292
self.writeJSON('{ }')
9393
elif self.isApi('api/0/organizations/{}/chunk-upload/'.format(apiOrg)):
9494
self.writeJSON('{ }')
95+
elif self.isApi('api/0/envelope'):
96+
sys.stdout.write(" envelope start\n")
97+
sys.stdout.write(self.body)
98+
sys.stdout.write("\n envelope end\n")
99+
self.writeJSON('{ }')
95100
else:
96101
self.writeNoApiMatchesError()
97102

sentry-cli/integration-test/tests/action.Tests.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,26 @@ Describe 'Invoke-SentryServer' {
4242
Should -ActualValue $result.HasErrors() -BeFalse
4343
$result.UploadedDebugFiles() | Should -Be @('file3.dylib', 'file2.so', 'file1.dll')
4444
}
45+
46+
It "collects envelopes" {
47+
$result = Invoke-SentryServer {
48+
Param([string]$url)
49+
Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @'
50+
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc","dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42"}
51+
{"type":"attachment","length":10,"content_type":"text/plain","filename":"hello.txt"}
52+
\xef\xbb\xbfHello\r\n
53+
{"type":"event","length":41,"content_type":"application/json","filename":"application.log"}
54+
{"message":"hello world","level":"error"}
55+
'@
56+
Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @'
57+
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"}
58+
{"type":"attachment"}
59+
helloworld
60+
'@
61+
}
62+
Should -ActualValue $result.HasErrors() -BeFalse
63+
$result.Envelopes().Length | Should -Be 2
64+
$result.Envelopes()[0].Length | Should -Be 357
65+
$result.Envelopes()[1].Length | Should -Be 84
66+
}
4567
}

0 commit comments

Comments
 (0)