Skip to content

Commit

Permalink
Adjust tests for new path trimming for main file
Browse files Browse the repository at this point in the history
  • Loading branch information
DariaKunoichi committed Feb 28, 2024
1 parent aecd5bd commit 4fc85cb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
15 changes: 8 additions & 7 deletions features/fixtures/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func multipleUnhandled() {
defer notifier.AutoNotify(ctx)
panic("oops")
}

//go:noinline
func unhandledCrash() {
// Invalid type assertion, will panic
Expand Down Expand Up @@ -259,17 +260,17 @@ func handledToUnhandled() {
}

type customErr struct {
msg string
cause error
msg string
cause error
callers []uintptr
}

func newCustomErr(msg string, cause error) error {
callers := make([]uintptr, 8)
runtime.Callers(2, callers)
return customErr {
msg: msg,
cause: cause,
return customErr{
msg: msg,
cause: cause,
callers: callers,
}
}
Expand Down Expand Up @@ -297,7 +298,7 @@ func nestedHandledError() {
if val, err := checkValue(i); err != nil {
fmt.Printf("err: %v, val: %d", err, val)
}
if val, err := checkValue(i-46); err != nil {
if val, err := checkValue(i - 46); err != nil {
fmt.Printf("err: %v, val: %d", err, val)
}

Expand All @@ -317,7 +318,7 @@ func login(token string) error {
func checkValue(i int) (int, error) {
if i < 0 {
return 0, newCustomErr("invalid token", nil)
} else if i % 2 == 0 {
} else if i%2 == 0 {
return i / 2, nil
} else if i < 9 {
return i * 3, nil
Expand Down
24 changes: 12 additions & 12 deletions features/handled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Scenario: A handled error sends a report
And the event "severity" equals "warning"
And the event "severityReason.type" equals "handledError"
And the exception is a PathError for request 0
And the "file" of stack frame 0 equals "main.go"
And the "file" of stack frame 0 ends with "main.go"

Scenario: A handled error sends a report with a custom name
Given I set environment variable "ERROR_CLASS" to "MyCustomErrorClass"
Expand All @@ -25,7 +25,7 @@ Scenario: A handled error sends a report with a custom name
And the event "severity" equals "warning"
And the event "severityReason.type" equals "handledError"
And the exception "errorClass" equals "MyCustomErrorClass"
And the "file" of stack frame 0 equals "main.go"
And the "file" of stack frame 0 ends with "main.go"

Scenario: Sending an event using a callback to modify report contents
When I run the go service "app" with the test case "handled-with-callback"
Expand All @@ -35,8 +35,8 @@ Scenario: Sending an event using a callback to modify report contents
And the event "severity" equals "info"
And the event "severityReason.type" equals "userCallbackSetSeverity"
And the event "context" equals "nonfatal.go:14"
And the "file" of stack frame 0 equals "main.go"
And stack frame 0 contains a local function spanning 241 to 247
And the "file" of stack frame 0 ends with "main.go"
And stack frame 0 contains a local function spanning 242 to 248
And the "file" of stack frame 1 equals ">insertion<"
And the "lineNumber" of stack frame 1 equals 0

Expand All @@ -48,8 +48,8 @@ Scenario: Marking an error as unhandled in a callback
And the event "severity" equals "error"
And the event "severityReason.type" equals "userCallbackSetSeverity"
And the event "severityReason.unhandledOverridden" is true
And the "file" of stack frame 0 equals "main.go"
And stack frame 0 contains a local function spanning 253 to 256
And the "file" of stack frame 0 ends with "main.go"
And stack frame 0 contains a local function spanning 254 to 257

Scenario: Unwrapping the causes of a handled error
When I run the go service "app" with the test case "nested-error"
Expand All @@ -58,12 +58,12 @@ Scenario: Unwrapping the causes of a handled error
And the event "unhandled" is false
And the event "severity" equals "warning"
And the event "exceptions.0.message" equals "terminate process"
And the "lineNumber" of stack frame 0 equals 291
And the "file" of stack frame 0 equals "main.go"
And the "lineNumber" of stack frame 0 equals 292
And the "file" of stack frame 0 ends with "main.go"
And the "method" of stack frame 0 equals "nestedHandledError"
And the event "exceptions.1.message" equals "login failed"
And the event "exceptions.1.stacktrace.0.file" equals "main.go"
And the event "exceptions.1.stacktrace.0.lineNumber" equals 311
And the event "exceptions.1.stacktrace.0.file" ends with "main.go"
And the event "exceptions.1.stacktrace.0.lineNumber" equals 312
And the event "exceptions.2.message" equals "invalid token"
And the event "exceptions.2.stacktrace.0.file" equals "main.go"
And the event "exceptions.2.stacktrace.0.lineNumber" equals 319
And the event "exceptions.2.stacktrace.0.file" ends with "main.go"
And the event "exceptions.2.stacktrace.0.lineNumber" equals 320
4 changes: 2 additions & 2 deletions features/net-http/handled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Scenario: A handled error sends a report
And the event "severity" equals "warning" for request 0
And the event "severityReason.type" equals "handledError" for request 0
And the exception is a PathError for request 0
And the "file" of stack frame 0 equals "main.go" for request 0
And the "file" of stack frame 0 ends with "main.go" for request 0

Scenario: A handled error sends a report with a custom name
Given I set environment variable "ERROR_CLASS" to "MyCustomErrorClass"
Expand All @@ -31,4 +31,4 @@ Scenario: A handled error sends a report with a custom name
And the event "severity" equals "warning" for request 0
And the event "severityReason.type" equals "handledError" for request 0
And the exception "errorClass" equals "MyCustomErrorClass" for request 0
And the "file" of stack frame 0 equals "main.go" for request 0
And the "file" of stack frame 0 ends with "main.go" for request 0
8 changes: 4 additions & 4 deletions features/plain_features/panics.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Panic handling
And the exception "message" is one of:
| interface conversion: interface is struct {}, not string |
| interface conversion: interface {} is struct {}, not string |
And the in-project frames of the stacktrace are:
| file | method |
| main.go | unhandledCrash.func1 |
| main.go | unhandledCrash |
And the "method" of stack frame 0 equals "unhandledCrash.func1"
And the "file" of stack frame 0 ends with "main.go"
And the "method" of stack frame 1 equals "unhandledCrash"
And the "file" of stack frame 1 ends with "main.go"

0 comments on commit 4fc85cb

Please sign in to comment.