From 4f272abba2c959d36d6c19c0d6cf1c62cb202521 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Tue, 24 Sep 2019 10:45:30 +0100 Subject: [PATCH] test: improve existing mazerunner scenario for internal reports to verify more payload data --- .../scenarios/InternalReportScenario.kt | 23 +++++++++++++++---- features/internal_report.feature | 10 +++++++- .../scenarios/InternalReportScenario.kt | 23 +++++++++++++++---- tests/features/internal_report.feature | 12 +++++++++- tests/features/support/env.rb | 4 ++++ 5 files changed, 62 insertions(+), 10 deletions(-) diff --git a/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/InternalReportScenario.kt b/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/InternalReportScenario.kt index 93b249a3ac..774e4669ce 100644 --- a/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/InternalReportScenario.kt +++ b/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/InternalReportScenario.kt @@ -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 @@ -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")) - } -} \ No newline at end of file + if (eventMetaData != "non-crashy") { + Bugsnag.notify(java.lang.RuntimeException("Whoops")) + } + } +} diff --git a/features/internal_report.feature b/features/internal_report.feature index 39c220a0dc..ca1c97a9e3 100644 --- a/features/internal_report.feature +++ b/features/internal_report.feature @@ -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" @@ -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 diff --git a/tests/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/InternalReportScenario.kt b/tests/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/InternalReportScenario.kt index 93b249a3ac..1c7686b73b 100644 --- a/tests/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/InternalReportScenario.kt +++ b/tests/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/InternalReportScenario.kt @@ -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 @@ -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")) - } -} \ No newline at end of file + if (eventMetaData != "non-crashy") { + Bugsnag.notify(java.lang.RuntimeException("Whoops")) + } + } +} diff --git a/tests/features/internal_report.feature b/tests/features/internal_report.feature index 50ac46c10b..8945c8e0ee 100644 --- a/tests/features/internal_report.feature +++ b/tests/features/internal_report.feature @@ -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 @@ -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 diff --git a/tests/features/support/env.rb b/tests/features/support/env.rb index 057da55076..901aa42850 100644 --- a/tests/features/support/env.rb +++ b/tests/features/support/env.rb @@ -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