Skip to content

Commit

Permalink
test: improve existing mazerunner scenario for internal reports to ve…
Browse files Browse the repository at this point in the history
…rify more payload data
  • Loading branch information
fractalwrench committed Sep 24, 2019
1 parent 9047172 commit 4f272ab
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.bugsnag.android.mazerunner.scenarios

import android.app.Activity
import android.content.Context
import android.content.Intent

import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import java.io.File
Expand All @@ -13,12 +16,24 @@ internal class InternalReportScenario(config: Configuration,

init {
config.setAutoCaptureSessions(false)
disableAllDelivery(config)
config.beforeSend { true }

if (context is Activity) {
eventMetaData = context.intent.getStringExtra("EVENT_METADATA")
if (eventMetaData != "non-crashy") {
disableAllDelivery(config)
} else {
val files = File(context.cacheDir, "bugsnag-errors").listFiles()
files.forEach { it.writeText("{[]}") }
}
}
}

override fun run() {
super.run()
Bugsnag.notify(java.lang.RuntimeException("Whoops"))
}

}
if (eventMetaData != "non-crashy") {
Bugsnag.notify(java.lang.RuntimeException("Whoops"))
}
}
}
10 changes: 9 additions & 1 deletion features/internal_report.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: Sending internal error reports

Scenario: Send a report about an error triggered within the notifier
When I run "InternalReportScenario"
And I set environment variable "EVENT_TYPE" to "EmptyReportScenario"
And I configure the app to run in the "non-crashy" state
And I relaunch the app
Then I should receive 1 request
And the "Bugsnag-Internal-Error" header equals "true"
Expand All @@ -12,3 +12,11 @@ Scenario: Send a report about an error triggered within the notifier
And the event "breadcrumbs" is null
And the event "app.type" equals "android"
And the event "device.osName" equals "android"
And the event "metaData.BugsnagDiagnostics.cacheTombstone" is false
And the event "metaData.BugsnagDiagnostics.filename" is not null
And the event "metaData.BugsnagDiagnostics.notifierName" is not null
And the event "metaData.BugsnagDiagnostics.apiKey" equals "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event "metaData.BugsnagDiagnostics.cacheGroup" is false
And the event "metaData.BugsnagDiagnostics.packageName" equals "com.bugsnag.android.mazerunner"
And the event "metaData.BugsnagDiagnostics.notifierVersion" is not null
And the event "metaData.BugsnagDiagnostics.fileLength" equals 4
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.bugsnag.android.mazerunner.scenarios

import android.app.Activity
import android.content.Context
import android.content.Intent

import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import java.io.File
Expand All @@ -13,12 +16,24 @@ internal class InternalReportScenario(config: Configuration,

init {
config.setAutoCaptureSessions(false)
disableAllDelivery(config)
config.beforeSend { true }

if (context is Activity) {
eventMetaData = context.intent.getStringExtra("eventMetaData")
if (eventMetaData != "non-crashy") {
disableAllDelivery(config)
} else {
val files = File(context.cacheDir, "bugsnag-errors").listFiles()
files.forEach { it.writeText("{[]}") }
}
}
}

override fun run() {
super.run()
Bugsnag.notify(java.lang.RuntimeException("Whoops"))
}

}
if (eventMetaData != "non-crashy") {
Bugsnag.notify(java.lang.RuntimeException("Whoops"))
}
}
}
12 changes: 11 additions & 1 deletion tests/features/internal_report.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Feature: Sending internal error reports

@skip_below_android_9
Scenario: Sending internal error reports
When I run "InternalReportScenario" and relaunch the app
And I configure Bugsnag for "EmptyReportScenario"
And I configure the app to run in the "non-crashy" state
And I run "InternalReportScenario"
And I wait to receive a request
And the "Bugsnag-Internal-Error" header equals "true"
And the payload field "apiKey" is null
Expand All @@ -11,3 +13,11 @@ Scenario: Sending internal error reports
And the event "breadcrumbs" is null
And the event "app.type" equals "android"
And the event "device.osName" equals "android"
And the event "metaData.BugsnagDiagnostics.cacheTombstone" is false
And the event "metaData.BugsnagDiagnostics.filename" is not null
And the event "metaData.BugsnagDiagnostics.notifierName" is not null
And the event "metaData.BugsnagDiagnostics.apiKey" equals "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"
And the event "metaData.BugsnagDiagnostics.cacheGroup" is false
And the event "metaData.BugsnagDiagnostics.packageName" equals "com.bugsnag.android.mazerunner"
And the event "metaData.BugsnagDiagnostics.notifierVersion" is not null
And the event "metaData.BugsnagDiagnostics.fileLength" equals 4
4 changes: 4 additions & 0 deletions tests/features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
skip_this_scenario("Skipping scenario") if bs_device == 'ANDROID_9'
end

Before('@skip_below_android_9') do |scenario|
skip_this_scenario("Skipping scenario") if bs_device != 'ANDROID_9'
end

AfterConfiguration do |config|
AppAutomateDriver.new(bs_username, bs_access_key, bs_local_id, bs_device, app_location)
$driver.start_driver
Expand Down

0 comments on commit 4f272ab

Please sign in to comment.