Skip to content

add out-sentry integration-test script #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/integration-test-script.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true

Import-Module ../modules/Sentry/Sentry.psd1
. ./utils.ps1

$events = [System.Collections.Generic.List[Sentry.SentryEvent]]::new();
$transport = [RecordingTransport]::new()
StartSentryForEventTests ([ref] $events) ([ref] $transport)

try
{
funcA 'throw' 'error'
}
catch
{
$_ | Out-Sentry | Out-Null
}

$events[0].SentryThreads.Stacktrace.Frames | ForEach-Object {
'----------------' | Out-String
$frame = $_
$properties = $frame | Get-Member -MemberType Properties | Select-Object -ExpandProperty Name
foreach ($prop in $properties)
{
$value = $frame.$prop | Out-String -Width 500
"$($prop):$value"
}
}
173 changes: 173 additions & 0 deletions tests/integration.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
BeforeAll {
$integrationTestScript = "$PSScriptRoot$([IO.Path]::DirectorySeparatorChar)integration-test-script.ps1"
$integrationTestScriptContent = Get-Content -Raw $integrationTestScript

$checkOutput = {
param([string[]] $output, [string[]] $expected)
# Remove empty lines
$output = $output | Where-Object { $_ -ne '' }

# Print out so that we can compare the whole output if the test fails
$output | Write-Host

for ($i = 0; $i -lt $expected.Count -and $i -lt $output.Count; $i++)
{
$output[$i] | Should -Be $expected[$i] -Because "Output line $i"
}
$output.Count | Should -Be $expected.Count
}
}

Describe 'Out-Sentry captures expected stack traces for command input' {
BeforeEach {
Push-Location "$PSScriptRoot"
$expected = @(

Check warning

Code scanning / PSScriptAnalyzer

The variable 'expected' is assigned but never used. Warning test

The variable 'expected' is assigned but never used.
'----------------'
'AbsolutePath:<No file>'
'AddressMode:'
'ColumnNumber:'
'ContextLine:'
'FileName:'
'FramesOmitted:'
'Function:<ScriptBlock>'
'FunctionId:'
'ImageAddress:'
'InApp:True'
'InstructionAddress:'
'LineNumber:1'
'Module:'
'Package:'
'Platform:'
'PostContext:'
'PreContext:'
'SymbolAddress:'
'Vars:'
'----------------'
'AbsolutePath:<No file>'
'AddressMode:'
'ColumnNumber:'
'ContextLine:'
'FileName:'
'FramesOmitted:'
'Function:<ScriptBlock>'
'FunctionId:'
'ImageAddress:'
'InApp:True'
'InstructionAddress:'
'LineNumber:14'
'Module:'
'Package:'
'Platform:'
'PostContext:'
'PreContext:'
'SymbolAddress:'
'Vars:'
'----------------'
'AbsolutePath:'
'AddressMode:'
'ColumnNumber:5'
"ContextLine: funcA 'throw' 'error'"
'FileName:'
'FramesOmitted:'
'Function:'
'FunctionId:'
'ImageAddress:'
'InApp:True'
'InstructionAddress:'
'LineNumber:14'
'Module:'
'Package:'
'Platform:'
'PostContext:'
'PreContext:'
'SymbolAddress:'
'Vars:'
)

}

AfterEach {
Pop-Location
}

It 'Windows PowerShell' -Skip:($env:OS -ne 'Windows_NT') {
$output = powershell.exe -Command "& {$integrationTestScriptContent}" -ErrorAction Continue
$checkOutput.Invoke($output, $expected)
}

It 'PowerShell' {
$output = pwsh -Command "& {$integrationTestScriptContent}" -ErrorAction Continue
$checkOutput.Invoke($output, $expected)
}
}

Describe 'Out-Sentry captures expected stack traces for file input' {
BeforeEach {
Push-Location "$PSScriptRoot"
$expected = @(

Check warning

Code scanning / PSScriptAnalyzer

The variable 'expected' is assigned but never used. Warning test

The variable 'expected' is assigned but never used.

Check warning

Code scanning / PSScriptAnalyzer

The variable 'expected' is assigned but never used. Warning test

The variable 'expected' is assigned but never used.
'----------------'
'AbsolutePath:<No file>'
'AddressMode:'
'ColumnNumber:'
'ContextLine:'
'FileName:'
'FramesOmitted:'
'Function:<ScriptBlock>'
'FunctionId:'
'ImageAddress:'
'InApp:True'
'InstructionAddress:'
'LineNumber:1'
'Module:'
'Package:'
'Platform:'
'PostContext:'
'PreContext:'
'SymbolAddress:'
'Vars:'
'----------------'
"AbsolutePath:$integrationTestScript"
'AddressMode:'
'ColumnNumber:5'
"ContextLine: funcA 'throw' 'error'"
'FileName:'
'FramesOmitted:'
'Function:<ScriptBlock>'
'FunctionId:'
'ImageAddress:'
'InApp:True'
'InstructionAddress:'
'LineNumber:14'
'Module:'
'Package:'
'Platform:'
'PostContext:}'
'catch'
'{'
' $_ | Out-Sentry | Out-Null'
'}'
'PreContext:$transport = [RecordingTransport]::new()'
'StartSentryForEventTests ([ref] $events) ([ref] $transport)'
'try'
'{'
'SymbolAddress:'
'Vars:'
)
}

AfterEach {
Pop-Location
}

It 'Windows PowerShell' -Skip:($env:OS -ne 'Windows_NT') {
$PSNativeCommandUseErrorActionPreference = $false
$output = powershell.exe $integrationTestScript
$checkOutput.Invoke($output, $expected)
}

It 'PowerShell' {
$PSNativeCommandUseErrorActionPreference = $false
$output = pwsh -Command $integrationTestScript
$checkOutput.Invoke($output, $expected)
}
}
Loading