Skip to content

Commit

Permalink
Rework test fixture Dockerfile, add integrity header
Browse files Browse the repository at this point in the history
  • Loading branch information
DariaKunoichi committed Aug 12, 2024
1 parent 11cbd89 commit b57f1c0
Show file tree
Hide file tree
Showing 27 changed files with 204 additions and 112 deletions.
23 changes: 14 additions & 9 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on: [ push, pull_request ]

jobs:
test:

runs-on: ${{ matrix.os }}-latest
defaults:
run:
Expand All @@ -13,7 +12,8 @@ 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', '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']

steps:
- uses: actions/checkout@v2
Expand All @@ -27,31 +27,36 @@ jobs:
if: matrix.os == 'windows'
run: |
bash -c 'echo "GOPATH=$GITHUB_WORKSPACE\\\\go" >> $GITHUB_ENV'
- name: set GO111MODULE
run: |
bash -c 'echo "GO111MODULE=on >> $GITHUB_ENV'
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: install dependencies
run: go get -v -d ./...
- name: run tests
run: go test ./...
run: go test $(go list ./... | grep -v /features/)
- name: vet package
# go1.12 vet shows spurious 'unknown identifier' issues
if: matrix.go-version != '1.12'
run: go vet ./...
run: go vet $(go list ./... | grep -v /features/)

- name: install integration dependencies
if: matrix.os == 'ubuntu'
run: |
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev
- name: install Ruby
if: matrix.os == 'ubuntu'
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: '3.2'
bundler-cache: true
working-directory: go/src/github.com/bugsnag/bugsnag-go # relative to $GITHUB_WORKSPACE
- name: install integration dependencies
if: matrix.os == 'ubuntu'
run: sudo apt-get install docker-compose
- name: maze tests
working-directory: go/src/github.com/bugsnag/bugsnag-go
if: matrix.os == 'ubuntu'
env:
GO_VERSION: ${{ matrix.go-version }}
run: bundle exec bugsnag-maze-runner --color --format progress
run: bundle exec maze-runner ./features/user.feature --color --format progress
4 changes: 2 additions & 2 deletions features/apptype.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Background:
Scenario: An error report contains the configured app type when running a go app
Given I set environment variable "AUTO_CAPTURE_SESSIONS" to "false"
When I start the service "app"
And I run HandledScenario
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"
When I start the service "app"
And I run SendSessionScenario
And I run "SendSessionScenario"
And I wait to receive a session
And the session payload field "app.type" equals "background-queue"
4 changes: 2 additions & 2 deletions features/appversion.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Background:
Scenario: An error report contains the configured app type when running a go app
Given I set environment variable "AUTO_CAPTURE_SESSIONS" to "false"
When I start the service "app"
And I run HandledScenario
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"
When I start the service "app"
And I run SendSessionScenario
And I run "SendSessionScenario"
And I wait to receive a session
And the session payload field "app.version" equals "3.1.2"
4 changes: 2 additions & 2 deletions features/autonotify.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: Using auto notify

Scenario: An error report is sent when an AutoNotified crash occurs which later gets recovered
When I start the service "app"
And I run AutonotifyPanicScenario
And I run "AutonotifyPanicScenario"
And I wait to receive an error
And the exception "errorClass" equals "Error"
And the exception "errorClass" equals "*errors.errorString"
And the exception "message" equals "Go routine killed with auto notify"
15 changes: 7 additions & 8 deletions features/fixtures/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
ARG GO_VERSION
FROM golang:${GO_VERSION}-alpine

RUN apk update && apk upgrade && apk add git bash
RUN apk update && apk upgrade && apk add git bash build-base

ENV GOPATH /app
ENV GO111MODULE="on"

COPY features /app/src/features
COPY v2 /app/src/v2
WORKDIR /app/src/v2
COPY v2 /app/src/github.com/bugsnag/bugsnag-go/v2
WORKDIR /app/src/github.com/bugsnag/bugsnag-go/v2

# Ensure subsequent steps are re-run if the GO_VERSION variable changes
ARG GO_VERSION
Expand All @@ -25,8 +26,6 @@ WORKDIR /app/src/features/fixtures/app

# Create app module - avoid locking bugsnag dep by not checking it in
# Skip on old versions of Go which pre-date modules
RUN if [[ $GO_VERSION != '1.11' && $GO_VERSION != '1.12' ]]; then \
go mod init && go mod tidy; \
echo "replace github.com/bugsnag/bugsnag-go/v2 => /app/src/v2" >> go.mod; \
go mod tidy; \
fi
RUN go mod init && go mod tidy && \
echo "replace github.com/bugsnag/bugsnag-go/v2 => /app/src/github.com/bugsnag/bugsnag-go/v2" >> go.mod && \
go mod tidy
48 changes: 36 additions & 12 deletions features/fixtures/app/handled_scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import (
"github.com/bugsnag/bugsnag-go/v2"
)

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

scenarioFunc := func() {
if _, err := os.Open("nonexistent_file.txt"); err != nil {
if errClass := os.Getenv("ERROR_CLASS"); errClass != "" {
Expand All @@ -23,9 +27,13 @@ func HandledErrorScenario() (bugsnag.Configuration, func()) {
return config, scenarioFunc
}

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

scenarioFunc := func() {
ctx := bugsnag.StartSession(context.Background())
Expand All @@ -35,8 +43,12 @@ func MultipleHandledErrorsScenario() (bugsnag.Configuration, func()) {
return config, scenarioFunc
}

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

scenarioFunc := func() {
if err := Login("token " + os.Getenv("API_KEY")); err != nil {
bugsnag.Notify(NewCustomErr("terminate process", err))
Expand All @@ -56,8 +68,12 @@ func NestedHandledErrorScenario() (bugsnag.Configuration, func()) {
return config, scenarioFunc
}

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

scenarioFunc := func() {
bugsnag.Notify(fmt.Errorf("inadequent Prep Error"), func(event *bugsnag.Event) {
event.Context = "nonfatal.go:14"
Expand All @@ -70,8 +86,12 @@ func HandledCallbackErrorScenario() (bugsnag.Configuration, func()) {
return config, scenarioFunc
}

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

scenarioFunc := func() {
bugsnag.Notify(fmt.Errorf("unknown event"), func(event *bugsnag.Event) {
event.Unhandled = true
Expand All @@ -81,8 +101,12 @@ func HandledToUnhandledScenario() (bugsnag.Configuration, func()) {
return config, scenarioFunc
}

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

scenarioFunc := func() {
bugsnag.OnBeforeNotify(
func(event *bugsnag.Event, config *bugsnag.Configuration) error {
Expand Down
15 changes: 8 additions & 7 deletions features/fixtures/app/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"context"
"fmt"
"os"
"os/signal"
Expand All @@ -11,7 +10,7 @@ import (
"github.com/bugsnag/bugsnag-go/v2"
)

var scenariosMap = map[string] func()(bugsnag.Configuration, func()){
var scenariosMap = map[string] func(Command)(bugsnag.Configuration, func()){
"UnhandledScenario": UnhandledCrashScenario,
"HandledScenario": HandledErrorScenario,
"MultipleUnhandledScenario": MultipleUnhandledErrorsScenario,
Expand All @@ -31,7 +30,8 @@ var scenariosMap = map[string] func()(bugsnag.Configuration, func()){

func main() {
// Listening to the OS Signals
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
signalsChan := make(chan os.Signal, 1)
signal.Notify(signalsChan, syscall.SIGINT, syscall.SIGTERM)
ticker := time.NewTicker(1 * time.Second)

addr := os.Getenv("DEFAULT_MAZE_ADDRESS")
Expand All @@ -42,19 +42,20 @@ func main() {
for {
select {
case <-ticker.C:
fmt.Println("[Bugsnag] Get command")
command := GetCommand(DEFAULT_MAZE_ADDRESS)
command := GetCommand(addr)
fmt.Printf("[Bugsnag] Received command: %+v\n", command)

if command.Action == "run-scenario" {
prepareScenarioFunc, ok := scenariosMap[command.ScenarioName]
if ok {
config, scenarioFunc := prepareScenarioFunc()
config, scenarioFunc := prepareScenarioFunc(command)
bugsnag.Configure(config)
time.Sleep(200 * time.Millisecond)
scenarioFunc()
time.Sleep(200 * time.Millisecond)
}
}
case <-ctx.Done():
case <-signalsChan:
fmt.Println("[Bugsnag] Context is done, closing")
ticker.Stop()
return
Expand Down
16 changes: 12 additions & 4 deletions features/fixtures/app/metadata_scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import (
"github.com/bugsnag/bugsnag-go/v2"
)

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

scenarioFunc := func() {
customerData := map[string]string{"Name": "Joe Bloggs", "Age": "21"}
bugsnag.Notify(fmt.Errorf("oops"), bugsnag.MetaData{
Expand All @@ -20,8 +24,12 @@ func MetadataScenario() (bugsnag.Configuration, func()) {
return config, scenarioFunc
}

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

scenarioFunc := func() {
bugsnag.Notify(fmt.Errorf("oops"), bugsnag.MetaData{
"Account": {
Expand Down
18 changes: 13 additions & 5 deletions features/fixtures/app/panic_scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import (
"github.com/bugsnag/bugsnag-go/v2"
)

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

scenarioFunc := func() {
defer bugsnag.AutoNotify()
panic("Go routine killed with auto notify")
Expand All @@ -14,11 +18,15 @@ func AutonotifyPanicScenario()(bugsnag.Configuration, func()) {
return config, scenarioFunc
}

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

scenarioFunc := func() {
defer bugsnag.Recover()
panic("Go routine killed but recovered")
}
return config, scenarioFunc
}
}
16 changes: 12 additions & 4 deletions features/fixtures/app/session_scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ import (
"github.com/bugsnag/bugsnag-go/v2"
)

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

scenarioFunc := func() {
bugsnag.StartSession(context.Background())
}
return config, scenarioFunc
}

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

scenarioFunc := func() {
ctx := bugsnag.StartSession(context.Background())
bugsnag.Notify(fmt.Errorf("oops"), ctx)
Expand Down
Loading

0 comments on commit b57f1c0

Please sign in to comment.