Skip to content

Commit

Permalink
feat: support envelopes in integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Nov 27, 2023
1 parent fe18d6e commit 029ec39
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Sentry-CLI integration test action: support envelopes ([#58](https://github.com/getsentry/github-workflows/pull/58))

## 2.7.0

### Features
Expand Down
22 changes: 22 additions & 0 deletions sentry-cli/integration-test/action.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ class InvokeSentryResult
return @($this.ServerStdOut | Where-Object { $_.StartsWith($prefix) } | ForEach-Object { $_.Substring($prefix.Length).Trim() })
}

# Envelopes are collected to a list, each envelope body a single item.
[string[]]Envelopes()
{
$envelopes = @()
$this.ServerStdOut | ForEach-Object {
if ($_.Trim() -eq "envelope start")
{
$envelope = ''
}
elseif ($_ -eq "envelope end")
{
$envelopes += $envelope
$envelope = $null
}
elseif ($null -ne $envelope)
{
$envelope += $_ + "\n"
}
}
return $envelopes
}

[bool]HasErrors()
{
return $this.ServerStdErr.Length -gt 0
Expand Down
5 changes: 5 additions & 0 deletions sentry-cli/integration-test/sentry-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def do_POST(self):
self.writeJSON('{ }')
elif self.isApi('api/0/organizations/{}/chunk-upload/'.format(apiOrg)):
self.writeJSON('{ }')
elif self.isApi('api/0/envelope'):
sys.stdout.write(" envelope start\n")
sys.stdout.write(self.body)
sys.stdout.write("\n envelope end\n")
self.writeJSON('{ }')
else:
self.writeNoApiMatchesError()

Expand Down
22 changes: 22 additions & 0 deletions sentry-cli/integration-test/tests/action.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,26 @@ Describe 'Invoke-SentryServer' {
Should -ActualValue $result.HasErrors() -BeFalse
$result.UploadedDebugFiles() | Should -Be @('file3.dylib', 'file2.so', 'file1.dll')
}

It "collects envelopes" {
$result = Invoke-SentryServer {
Param([string]$url)
Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @'
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc","dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42"}
{"type":"attachment","length":10,"content_type":"text/plain","filename":"hello.txt"}
\xef\xbb\xbfHello\r\n
{"type":"event","length":41,"content_type":"application/json","filename":"application.log"}
{"message":"hello world","level":"error"}
'@
Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @'
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"}
{"type":"attachment"}
helloworld
'@
}
Should -ActualValue $result.HasErrors() -BeFalse
$result.Envelopes().Length | Should -Be 2
$result.Envelopes()[0].Length | Should -Be 357
$result.Envelopes()[1].Length | Should -Be 84
}
}

0 comments on commit 029ec39

Please sign in to comment.