Skip to content

Commit

Permalink
Maze runner tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesLindsay0 committed Aug 8, 2024
1 parent 109c13f commit 4277bcb
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 6 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.3
47 changes: 47 additions & 0 deletions features/breadcrumbs.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Feature: Breadcrumbs

Background:
Given I set environment variable "API_KEY" to "a35a2a72bd230ac0aa0f52715bbdc6aa"
Given I configure the bugsnag endpoint
Given I have built the service "app"

Scenario: Disabling breadcrumbs
Given I set environment variable "ENABLED_BREADCRUMB_TYPES" to "[]"
When I run the go service "app" with the test case "disable-breadcrumbs"
When I wait to receive 2 requests after the start up session

Then the request 0 is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
Then the payload field "events.0.breadcrumbs" is null for request 0

Then the request 1 is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
Then the payload field "events.0.breadcrumbs" is null for request 1

Scenario: Automatic breadcrumbs
When I run the go service "app" with the test case "automatic-breadcrumbs"
When I wait to receive 2 requests after the start up session

Then the request 0 is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
Then the payload field "events.0.breadcrumbs" is an array with 1 elements for request 0
Then the payload field "events.0.breadcrumbs.0.name" equals "Bugsnag loaded" for request 0
Then the payload field "events.0.breadcrumbs.0.type" equals "state" for request 0

Then the request 1 is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
Then the payload field "events.0.breadcrumbs" is an array with 2 elements for request 1
Then the payload field "events.0.breadcrumbs.0.name" equals "oops" for request 1
Then the payload field "events.0.breadcrumbs.0.type" equals "error" for request 1
Then the payload field "events.0.breadcrumbs.1.name" equals "Bugsnag loaded" for request 1
Then the payload field "events.0.breadcrumbs.1.type" equals "state" for request 1

Scenario: Setting max breadcrumbs
Given I set environment variable "ENABLED_BREADCRUMB_TYPES" to "[]"
Given I set environment variable "MAXIMUM_BREADCRUMBS" to "5"
When I run the go service "app" with the test case "maximum-breadcrumbs"
When I wait to receive 1 requests after the start up session

Then the request 0 is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
Then the payload field "events.0.breadcrumbs" is an array with 5 elements
Then the payload field "events.0.breadcrumbs.0.name" equals "Crumb 9"
Then the payload field "events.0.breadcrumbs.1.name" equals "Crumb 8"
Then the payload field "events.0.breadcrumbs.2.name" equals "Crumb 7"
Then the payload field "events.0.breadcrumbs.3.name" equals "Crumb 6"
Then the payload field "events.0.breadcrumbs.4.name" equals "Crumb 5"
23 changes: 22 additions & 1 deletion features/fixtures/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"encoding/json"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -45,6 +46,15 @@ func configureBasicBugsnag(testcase string, ctx context.Context) {
config.AutoCaptureSessions = acs
}

if maximumBreadcrumbs, err := strconv.Atoi(os.Getenv("MAXIMUM_BREADCRUMBS")); err == nil {
config.MaximumBreadcrumbs = bugsnag.MaximumBreadcrumbs(maximumBreadcrumbs)
}

var enabledBreadcrumbTypes []bugsnag.BreadcrumbType
if err := json.Unmarshal([]byte(os.Getenv("ENABLED_BREADCRUMB_TYPES")), &enabledBreadcrumbTypes); err == nil {
config.EnabledBreadcrumbTypes = enabledBreadcrumbTypes
}

switch testcase {
case "endpoint-notify":
config.Endpoints = bugsnag.Endpoints{Notify: os.Getenv("BUGSNAG_ENDPOINT")}
Expand Down Expand Up @@ -98,14 +108,16 @@ func main() {
sendAndExit()
case "user":
user()
case "multiple-handled":
case "multiple-handled", "disable-breadcrumbs", "automatic-breadcrumbs":
multipleHandled()
case "multiple-unhandled":
multipleUnhandled()
case "make-unhandled-with-callback":
handledToUnhandled()
case "nested-error":
nestedHandledError()
case "maximum-breadcrumbs":
maximumBreadcrumbs()
default:
log.Println("Not a valid test flag: " + *test)
os.Exit(1)
Expand Down Expand Up @@ -309,6 +321,15 @@ func nestedHandledError() {
}
}

func maximumBreadcrumbs() {
bugsnag.Configure(bugsnag.Configuration{Synchronous: true})
ctx := bugsnag.StartSession(context.Background())
for i := 0; i < 10; i++ {
bugsnag.LeaveBreadcrumb(fmt.Sprintf("Crumb %v", i))
}
bugsnag.Notify(fmt.Errorf("test error"), ctx)
}

func login(token string) error {
val, err := checkValue(len(token) * -1)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions features/fixtures/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ services:
- APP_VERSION
- APP_TYPE
- AUTO_CAPTURE_SESSIONS
- MAXIMUM_BREADCRUMBS
- ENABLED_BREADCRUMB_TYPES
- HOSTNAME
- NOTIFY_RELEASE_STAGES
- RELEASE_STAGE
Expand Down
10 changes: 5 additions & 5 deletions features/handled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Scenario: Sending an event using a callback to modify report contents
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 245 to 253
And stack frame 0 contains a local function spanning 257 to 265
And the "file" of stack frame 1 equals ">insertion<"
And the "lineNumber" of stack frame 1 equals 0

Expand All @@ -50,7 +50,7 @@ Scenario: Marking an error as unhandled in a callback
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 257 to 262
And stack frame 0 contains a local function spanning 269 to 274

Scenario: Unwrapping the causes of a handled error
When I run the go service "app" with the test case "nested-error"
Expand All @@ -59,12 +59,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 295
And the "lineNumber" of stack frame 0 equals 307
And the "file" of stack frame 0 equals "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 315
And the event "exceptions.1.stacktrace.0.lineNumber" equals 336
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 323
And the event "exceptions.2.stacktrace.0.lineNumber" equals 344

0 comments on commit 4277bcb

Please sign in to comment.