Skip to content

Commit

Permalink
Remove autoconfig testapp, use real env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
DariaKunoichi committed Aug 12, 2024
1 parent d5b1184 commit 8507abc
Show file tree
Hide file tree
Showing 29 changed files with 180 additions and 344 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu, windows]
#go-version: ['1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20', '1.21', '1.22']
go-version: ['1.11']
go-version: ['1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20', '1.21', '1.22']

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -59,4 +58,4 @@ jobs:
if: matrix.os == 'ubuntu'
env:
GO_VERSION: ${{ matrix.go-version }}
run: bundle exec maze-runner ./features/user.feature --color --format progress
run: bundle exec maze-runner --color --format progress
6 changes: 3 additions & 3 deletions features/apptype.feature
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Feature: Configuring app type

Background:
Given I set environment variable "APP_TYPE" to "background-queue"
Given I set environment variable "BUGSNAG_APP_TYPE" to "background-queue"

Scenario: An error report contains the configured app type when running a go app
Given I set environment variable "AUTO_CAPTURE_SESSIONS" to "false"
Given I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "false"
When I start the service "app"
And I run "HandledScenario"
And I wait to receive an error
And the event "app.type" equals "background-queue"

Scenario: An session report contains the configured app type when running a go app
Given I set environment variable "AUTO_CAPTURE_SESSIONS" to "true"
Given I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "true"
When I start the service "app"
And I run "SendSessionScenario"
And I wait to receive a session
Expand Down
6 changes: 3 additions & 3 deletions features/appversion.feature
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Feature: Configuring app version

Background:
And I set environment variable "APP_VERSION" to "3.1.2"
And I set environment variable "BUGSNAG_APP_VERSION" to "3.1.2"

Scenario: An error report contains the configured app type when running a go app
Given I set environment variable "AUTO_CAPTURE_SESSIONS" to "false"
Given I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "false"
When I start the service "app"
And I run "HandledScenario"
And I wait to receive an error
And the event "app.version" equals "3.1.2"

Scenario: A session report contains the configured app type when running a go app
Given I set environment variable "AUTO_CAPTURE_SESSIONS" to "true"
Given I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "true"
When I start the service "app"
And I run "SendSessionScenario"
And I wait to receive a session
Expand Down
81 changes: 41 additions & 40 deletions features/configuration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,52 @@ Feature: Configure integration with environment variables

Background:
Given I set environment variable "BUGSNAG_API_KEY" to "a35a2a72bd230ac0aa0f52715bbdc6aa"
And I set environment variable "BUGSNAG_NOTIFY_ENDPOINT" to the notify endpoint
And I set environment variable "BUGSNAG_SESSIONS_ENDPOINT" to the sessions endpoint
And I have built the service "autoconfigure"

Scenario Outline: Adding content to handled events through env variables
Given I set environment variable "<variable>" to "<value>"
And I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "0"
When I run the go service "autoconfigure" with the test case "<testcase>"
Then I wait to receive a request
And the request is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
When I start the service "app"
And I run "<testcase>"
And I wait to receive an error
And the event "<field>" equals "<value>"

Examples:
| testcase | variable | value | field |
| panic | BUGSNAG_APP_VERSION | 1.4.34 | app.version |
| panic | BUGSNAG_APP_TYPE | mailer-daemon | app.type |
| panic | BUGSNAG_RELEASE_STAGE | beta1 | app.releaseStage |
| panic | BUGSNAG_HOSTNAME | dream-machine-2 | device.hostname |
| panic | BUGSNAG_METADATA_device_instance | kube2-33-A | metaData.device.instance |
| panic | BUGSNAG_METADATA_framework_version | v3.1.0 | metaData.framework.version |
| panic | BUGSNAG_METADATA_device_runtime_level | 1C | metaData.device.runtime_level |
| panic | BUGSNAG_METADATA_Carrot | orange | metaData.custom.Carrot |
| AutoconfigPanicScenario | BUGSNAG_APP_VERSION | 1.4.34 | app.version |
| AutoconfigPanicScenario | BUGSNAG_APP_TYPE | mailer-daemon | app.type |
| AutoconfigPanicScenario | BUGSNAG_RELEASE_STAGE | beta1 | app.releaseStage |
| AutoconfigPanicScenario | BUGSNAG_HOSTNAME | dream-machine-2 | device.hostname |
| AutoconfigPanicScenario | BUGSNAG_METADATA_device_instance | kube2-33-A | metaData.device.instance |
| AutoconfigPanicScenario | BUGSNAG_METADATA_framework_version | v3.1.0 | metaData.framework.version |
| AutoconfigPanicScenario | BUGSNAG_METADATA_device_runtime_level | 1C | metaData.device.runtime_level |
| AutoconfigPanicScenario | BUGSNAG_METADATA_Carrot | orange | metaData.custom.Carrot |

| handled | BUGSNAG_APP_VERSION | 1.4.34 | app.version |
| handled | BUGSNAG_APP_TYPE | mailer-daemon | app.type |
| handled | BUGSNAG_RELEASE_STAGE | beta1 | app.releaseStage |
| handled | BUGSNAG_HOSTNAME | dream-machine-2 | device.hostname |
| handled | BUGSNAG_METADATA_device_instance | kube2-33-A | metaData.device.instance |
| handled | BUGSNAG_METADATA_framework_version | v3.1.0 | metaData.framework.version |
| handled | BUGSNAG_METADATA_device_runtime_level | 1C | metaData.device.runtime_level |
| handled | BUGSNAG_METADATA_Carrot | orange | metaData.custom.Carrot |
| AutoconfigHandledScenario | BUGSNAG_APP_VERSION | 1.4.34 | app.version |
| AutoconfigHandledScenario | BUGSNAG_APP_TYPE | mailer-daemon | app.type |
| AutoconfigHandledScenario | BUGSNAG_RELEASE_STAGE | beta1 | app.releaseStage |
| AutoconfigHandledScenario | BUGSNAG_HOSTNAME | dream-machine-2 | device.hostname |
| AutoconfigHandledScenario | BUGSNAG_METADATA_device_instance | kube2-33-A | metaData.device.instance |
| AutoconfigHandledScenario | BUGSNAG_METADATA_framework_version | v3.1.0 | metaData.framework.version |
| AutoconfigHandledScenario | BUGSNAG_METADATA_device_runtime_level | 1C | metaData.device.runtime_level |
| AutoconfigHandledScenario | BUGSNAG_METADATA_Carrot | orange | metaData.custom.Carrot |

Scenario: Configuring project packages
Given I set environment variable "BUGSNAG_PROJECT_PACKAGES" to "main,test"
And I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "0"
When I run the go service "autoconfigure" with the test case "panic"
Then I wait to receive a request
And the request is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
When I start the service "app"
And I run "AutoconfigPanicScenario"
And I wait to receive an error
And the in-project frames of the stacktrace are:
| file | method | lineNumber |
| cases.go | explicitPanic | 22 |
| main.go | main | 11 |

Scenario: Configuring source root
Given I set environment variable "BUGSNAG_SOURCE_ROOT" to the app directory
Given I set environment variable "BUGSNAG_SOURCE_ROOT" to "/app/src/features/fixtures/app/"
And I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "0"
And I run the go service "autoconfigure" with the test case "panic"
Then I wait to receive a request
And the request is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
When I start the service "app"
And I run "AutoconfigPanicScenario"
And I wait to receive an error
And the in-project frames of the stacktrace are:
| file | method | lineNumber |
| cases.go | explicitPanic | 22 |
Expand All @@ -63,34 +60,38 @@ Feature: Configure integration with environment variables
Given I set environment variable "BUGSNAG_NOTIFY_RELEASE_STAGES" to "prod,beta"
And I set environment variable "BUGSNAG_RELEASE_STAGE" to "beta"
And I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "0"
And I run the go service "autoconfigure" with the test case "panic"
Then I wait to receive a request
And the request is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
When I start the service "app"
And I run "AutoconfigPanicScenario"
And I wait to receive an error

Scenario: Suppressing events through notify release stages
Given I set environment variable "BUGSNAG_NOTIFY_RELEASE_STAGES" to "prod,beta"
And I set environment variable "BUGSNAG_RELEASE_STAGE" to "dev"
And I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "0"
And I run the go service "autoconfigure" with the test case "panic"
Then 0 requests were received
When I start the service "app"
And I run "AutoconfigPanicScenario"
Then I should receive no errors

Scenario: Suppressing events using panic handler
Given I set environment variable "BUGSNAG_DISABLE_PANIC_HANDLER" to "1"
And I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "0"
And I run the go service "autoconfigure" with the test case "panic"
When I start the service "app"
And I run "AutoconfigPanicScenario"
And I wait for 2 seconds
Then 0 requests were received
Then I should receive no errors

Scenario: Enabling synchronous event delivery
Given I set environment variable "BUGSNAG_SYNCHRONOUS" to "1"
And I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "0"
When I run the go service "autoconfigure" with the test case "handled"
Then 1 request was received
When I start the service "app"
And I run "AutoconfigHandledScenario"
And I wait to receive an error

Scenario: Filtering metadata
Given I set environment variable "BUGSNAG_PARAMS_FILTERS" to "tomato,pears"
And I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "0"
When I run the go service "autoconfigure" with the test case "handled-metadata"
Then I wait to receive a request
When I start the service "app"
And I run "AutoconfigMetadataScenario"
And I wait to receive an error
And the event "metaData.fruit.Tomato" equals "[FILTERED]"
And the event "metaData.snacks.Carrot" equals "4"
39 changes: 39 additions & 0 deletions features/fixtures/app/autoconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"fmt"

bugsnag "github.com/bugsnag/bugsnag-go/v2"
)

func AutoconfigPanicScenario(command Command) (bugsnag.Configuration, func()) {
config := ConfigureBugsnag(command)

scenarioFunc := func() {
panic("PANIQ!")
}
return config, scenarioFunc
}

func AutoconfigHandledScenario(command Command) (bugsnag.Configuration, func()) {
config := ConfigureBugsnag(command)

scenarioFunc := func() {
bugsnag.Notify(fmt.Errorf("gone awry!"))
}
return config, scenarioFunc
}

func AutoconfigMetadataScenario(command Command) (bugsnag.Configuration, func()) {
config := ConfigureBugsnag(command)

scenarioFunc := func() {
bugsnag.OnBeforeNotify(func(event *bugsnag.Event, config *bugsnag.Configuration) error {
event.MetaData.Add("fruit", "Tomato", "beefsteak")
event.MetaData.Add("snacks", "Carrot", "4")
return nil
})
bugsnag.Notify(fmt.Errorf("gone awry!"))
}
return config, scenarioFunc
}
42 changes: 5 additions & 37 deletions features/fixtures/app/configure.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,15 @@
package main

import (
"os"
"strconv"
"strings"

bugsnag "github.com/bugsnag/bugsnag-go/v2"
)

func ConfigureBugsnag() bugsnag.Configuration {
config := bugsnag.Configuration{
APIKey: os.Getenv("API_KEY"),
AppVersion: os.Getenv("APP_VERSION"),
AppType: os.Getenv("APP_TYPE"),
Hostname: os.Getenv("HOSTNAME"),
}

if notifyReleaseStages := os.Getenv("NOTIFY_RELEASE_STAGES"); notifyReleaseStages != "" {
config.NotifyReleaseStages = strings.Split(notifyReleaseStages, ",")
}

if releaseStage := os.Getenv("RELEASE_STAGE"); releaseStage != "" {
config.ReleaseStage = releaseStage
}

if filters := os.Getenv("PARAMS_FILTERS"); filters != "" {
config.ParamsFilters = []string{filters}
}

sync, err := strconv.ParseBool(os.Getenv("SYNCHRONOUS"))
if err == nil {
config.Synchronous = sync
}
func ConfigureBugsnag(command Command) bugsnag.Configuration {
config := bugsnag.Configuration{}

acs, err := strconv.ParseBool(os.Getenv("AUTO_CAPTURE_SESSIONS"))
if err == nil {
config.AutoCaptureSessions = acs
}
config.APIKey = command.APIKey
config.Endpoints.Sessions = command.SessionsEndpoint
config.Endpoints.Notify = command.NotifyEndpoint

config.Endpoints = bugsnag.Endpoints{
Notify: os.Getenv("BUGSNAG_NOTIFY_ENDPOINT"),
Sessions: os.Getenv("BUGSNAG_SESSIONS_ENDPOINT"),
}

return config
}
33 changes: 8 additions & 25 deletions features/fixtures/app/handled_scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import (
)

func HandledErrorScenario(command Command) (bugsnag.Configuration, func()) {
config := ConfigureBugsnag()
config.APIKey = command.APIKey
config.Endpoints.Sessions = command.SessionsEndpoint
config.Endpoints.Notify = command.NotifyEndpoint
config := ConfigureBugsnag(command)

scenarioFunc := func() {
if _, err := os.Open("nonexistent_file.txt"); err != nil {
Expand All @@ -29,10 +26,7 @@ func HandledErrorScenario(command Command) (bugsnag.Configuration, func()) {

func MultipleHandledErrorsScenario(command Command) (bugsnag.Configuration, func()) {
//Make the order of the below predictable
config := ConfigureBugsnag()
config.APIKey = command.APIKey
config.Endpoints.Sessions = command.SessionsEndpoint
config.Endpoints.Notify = command.NotifyEndpoint
config := ConfigureBugsnag(command)
config.Synchronous = true

scenarioFunc := func() {
Expand All @@ -44,10 +38,7 @@ func MultipleHandledErrorsScenario(command Command) (bugsnag.Configuration, func
}

func NestedHandledErrorScenario(command Command) (bugsnag.Configuration, func()) {
config := ConfigureBugsnag()
config.APIKey = command.APIKey
config.Endpoints.Sessions = command.SessionsEndpoint
config.Endpoints.Notify = command.NotifyEndpoint
config := ConfigureBugsnag(command)

scenarioFunc := func() {
if err := Login("token " + os.Getenv("API_KEY")); err != nil {
Expand All @@ -69,10 +60,7 @@ func NestedHandledErrorScenario(command Command) (bugsnag.Configuration, func())
}

func HandledCallbackErrorScenario(command Command) (bugsnag.Configuration, func()) {
config := ConfigureBugsnag()
config.APIKey = command.APIKey
config.Endpoints.Sessions = command.SessionsEndpoint
config.Endpoints.Notify = command.NotifyEndpoint
config := ConfigureBugsnag(command)

scenarioFunc := func() {
bugsnag.Notify(fmt.Errorf("inadequent Prep Error"), func(event *bugsnag.Event) {
Expand All @@ -87,10 +75,7 @@ func HandledCallbackErrorScenario(command Command) (bugsnag.Configuration, func(
}

func HandledToUnhandledScenario(command Command) (bugsnag.Configuration, func()) {
config := ConfigureBugsnag()
config.APIKey = command.APIKey
config.Endpoints.Sessions = command.SessionsEndpoint
config.Endpoints.Notify = command.NotifyEndpoint
config := ConfigureBugsnag(command)

scenarioFunc := func() {
bugsnag.Notify(fmt.Errorf("unknown event"), func(event *bugsnag.Event) {
Expand All @@ -102,10 +87,8 @@ func HandledToUnhandledScenario(command Command) (bugsnag.Configuration, func())
}

func OnBeforeNotifyScenario(command Command) (bugsnag.Configuration, func()) {
config := ConfigureBugsnag()
config.APIKey = command.APIKey
config.Endpoints.Sessions = command.SessionsEndpoint
config.Endpoints.Notify = command.NotifyEndpoint
config := ConfigureBugsnag(command)
config.Synchronous = true

scenarioFunc := func() {
bugsnag.OnBeforeNotify(
Expand All @@ -115,7 +98,7 @@ func OnBeforeNotifyScenario(command Command) (bugsnag.Configuration, func()) {
}
// continue notifying as normal
if event.Message == "change error message" {
event.Message = "Error message was changed"
event.Message = "error message was changed"
}
return nil
})
Expand Down
6 changes: 6 additions & 0 deletions features/fixtures/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var scenariosMap = map[string] func(Command)(bugsnag.Configuration, func()){
"AutonotifyPanicScenario": AutonotifyPanicScenario,
"SessionAndErrorScenario": SessionAndErrorScenario,
"OnBeforeNotifyScenario": OnBeforeNotifyScenario,
"AutoconfigPanicScenario": AutoconfigPanicScenario,
"AutoconfigHandledScenario": AutoconfigHandledScenario,
"AutoconfigMetadataScenario": AutoconfigMetadataScenario,
}

func main() {
Expand All @@ -34,6 +37,9 @@ func main() {
signal.Notify(signalsChan, syscall.SIGINT, syscall.SIGTERM)
ticker := time.NewTicker(1 * time.Second)

// Increase publish rate for testing
bugsnag.DefaultSessionPublishInterval = time.Millisecond * 50

addr := os.Getenv("DEFAULT_MAZE_ADDRESS")
if (addr == "") {
addr = DEFAULT_MAZE_ADDRESS
Expand Down
Loading

0 comments on commit 8507abc

Please sign in to comment.