Skip to content

Commit

Permalink
test: fix assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Nov 21, 2024
1 parent 597da7c commit 2bfd09d
Show file tree
Hide file tree
Showing 25 changed files with 209 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ internal class EmbraceInternalInterfaceTest {
assertAction = {
val session = getSingleSessionEnvelope()
val tapBreadcrumb = session.findSessionSpan().findEventOfType(EmbType.Ux.Tap)
tapBreadcrumb.attributes?.assertMatches {
"view.name" to "button"
"tap.coords" to "10,99"
"tap.type" to "tap"
}
tapBreadcrumb.attributes?.assertMatches(mapOf(
"view.name" to "button",
"tap.coords" to "0,0",
"tap.type" to "tap",
))
}
)
}
Expand Down Expand Up @@ -282,15 +282,15 @@ internal class EmbraceInternalInterfaceTest {
.associateBy { it.name })
assertEquals(4, spans.size)
with(checkNotNull(spans["tz-parent-span"])) {
attributes?.assertMatches {
"testkey" to "testvalue"
}
attributes?.assertMatches(mapOf(
"testkey" to "testvalue",
))
}
with(checkNotNull(spans["tz-child-span"])) {
val spanEvent = checkNotNull(events)[0]
spanEvent.attributes?.assertMatches {
"key" to "value"
}
spanEvent.attributes?.assertMatches(mapOf(
"key" to "value",
))
assertEquals("cool event bro", spanEvent.name)
assertEquals(Span.Status.ERROR, status)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ internal class FlutterInternalInterfaceTest {
expectedEmbType = "sys.flutter_exception",
expectedState = "foreground",
)
log.attributes?.assertMatches {
ExceptionAttributes.EXCEPTION_STACKTRACE.key to expectedStacktrace
"emb.exception.context" to expectedContext
"emb.exception.library" to expectedLibrary
}
log.attributes?.assertMatches(mapOf(
ExceptionAttributes.EXCEPTION_STACKTRACE.key to expectedStacktrace,
"emb.exception.context" to expectedContext,
"emb.exception.library" to expectedLibrary,
))
}
)
}
Expand Down Expand Up @@ -238,11 +238,11 @@ internal class FlutterInternalInterfaceTest {
expectedEmbType = "sys.flutter_exception",
expectedState = "foreground",
)
log.attributes?.assertMatches {
ExceptionAttributes.EXCEPTION_STACKTRACE.key to expectedStacktrace
"emb.exception.context" to expectedContext
"emb.exception.library" to expectedLibrary
}
log.attributes?.assertMatches(mapOf(
ExceptionAttributes.EXCEPTION_STACKTRACE.key to expectedStacktrace,
"emb.exception.context" to expectedContext,
"emb.exception.library" to expectedLibrary,
))
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ internal class NetworkRequestApiTest {
}
},
assertAction = {
validateAndReturnExpectedNetworkSpan().attributes?.assertMatches {
validateAndReturnExpectedNetworkSpan().attributes?.assertMatches(mapOf(
"url.full" to URL
}
))
}
)
}
Expand Down Expand Up @@ -307,32 +307,32 @@ internal class NetworkRequestApiTest {
assertEquals(Span.Status.ERROR, status)
}

attributes?.assertMatches {
"url.full" to expectedRequest.url
HttpAttributes.HTTP_REQUEST_METHOD.key to expectedRequest.httpMethod
"emb.trace_id" to expectedRequest.traceId
"emb.w3c_traceparent" to expectedRequest.w3cTraceparent
attributes?.assertMatches(mapOf(
"url.full" to expectedRequest.url,
HttpAttributes.HTTP_REQUEST_METHOD.key to expectedRequest.httpMethod,
"emb.trace_id" to expectedRequest.traceId,
"emb.w3c_traceparent" to expectedRequest.w3cTraceparent,
HttpAttributes.HTTP_RESPONSE_STATUS_CODE.key to when {
completed -> expectedRequest.responseCode
else -> null
}
},
HttpIncubatingAttributes.HTTP_REQUEST_BODY_SIZE.key to when {
completed -> expectedRequest.bytesSent
else -> null
}
},
HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE.key to when {
completed -> expectedRequest.bytesReceived
else -> null
}
},
"error.type" to when {
completed -> null
else -> expectedRequest.errorType
}
},
ExceptionAttributes.EXCEPTION_MESSAGE.key to when {
completed -> null
else -> expectedRequest.errorMessage
}
}
},
))
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ internal class PushNotificationApiTest {
val sessionSpan = payload.findSessionSpan()
val event = sessionSpan.findEventOfType(EmbType.System.PushNotification)
assertTrue(checkNotNull(event.timestampNanos) > 0)
event.attributes?.assertMatches {
EmbType.System.PushNotification.toEmbraceKeyValuePair()
"notification.title" to "title"
"notification.type" to "notif-data"
"notification.body" to "body"
"notification.id" to "id"
"notification.from" to "from"
"notification.priority" to 1
}
event.attributes?.assertMatches(mapOf(
EmbType.System.PushNotification.toEmbraceKeyValuePair(),
"notification.title" to "title",
"notification.type" to "notif-data",
"notification.body" to "body",
"notification.id" to "id",
"notification.from" to "from",
"notification.priority" to 1,
))
}
)
}
Expand All @@ -115,11 +115,11 @@ internal class PushNotificationApiTest {
val sessionSpan = findSessionSpan()
val event = sessionSpan.findEventOfType(EmbType.System.PushNotification)
assertTrue(checkNotNull(event.timestampNanos) > 0)
event.attributes?.assertMatches {
EmbType.System.PushNotification.toEmbraceKeyValuePair()
"notification.type" to type
"notification.id" to "id"
"notification.priority" to 1
}
event.attributes?.assertMatches(mapOf(
EmbType.System.PushNotification.toEmbraceKeyValuePair(),
"notification.type" to type,
"notification.id" to "id",
"notification.priority" to 1,
))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ internal class ReactNativeInternalInterfaceTest {
assertEquals(1000L, span.startTimeNanos?.nanosToMillis())
assertEquals(5000L, span.endTimeNanos?.nanosToMillis())

span.attributes?.assertMatches {
"emb.type" to "sys.rn_action"
"name" to "MyAction"
"outcome" to "SUCCESS"
"payload_size" to "100"
"emb.properties.key" to "value"
}
span.attributes?.assertMatches(mapOf(
"emb.type" to "sys.rn_action",
"name" to "MyAction",
"outcome" to "SUCCESS",
"payload_size" to "100",
"emb.properties.key" to "value",
))
}
)
}
Expand All @@ -184,16 +184,16 @@ internal class ReactNativeInternalInterfaceTest {
val secondSpan = message.findSpanSnapshotOfType(EmbType.Ux.View)

assertEquals("emb-screen-view", firstSpan.name)
firstSpan.attributes?.assertMatches {
"emb.type" to "ux.view"
"view.name" to "HomeScreen"
}
firstSpan.attributes?.assertMatches(mapOf(
"emb.type" to "ux.view",
"view.name" to "HomeScreen",
))

assertEquals("emb-screen-view", secondSpan.name)
secondSpan.attributes?.assertMatches {
"emb.type" to "ux.view"
"view.name" to "DetailsScreen"
}
secondSpan.attributes?.assertMatches(mapOf(
"emb.type" to "ux.view",
"view.name" to "DetailsScreen",
))
}
)
}
Expand All @@ -217,17 +217,17 @@ internal class ReactNativeInternalInterfaceTest {
val message = getSingleSessionEnvelope()
val firstSpan = message.findSpanOfType(EmbType.Ux.View)
assertEquals("emb-screen-view", firstSpan.name)
firstSpan.attributes?.assertMatches {
"emb.type" to "ux.view"
"view.name" to "HomeScreen"
}
firstSpan.attributes?.assertMatches(mapOf(
"emb.type" to "ux.view",
"view.name" to "HomeScreen",
))

val secondSpan = message.findSpanSnapshotOfType(EmbType.Ux.View)
assertEquals("emb-screen-view", secondSpan.name)
secondSpan.attributes?.assertMatches {
"emb.type" to "ux.view"
"view.name" to "HomeScreen"
}
secondSpan.attributes?.assertMatches(mapOf(
"emb.type" to "ux.view",
"view.name" to "HomeScreen",
))
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ internal class SessionApiTest {
// validate network status span
val networkStatusSpan = snapshots.single { it.name == "emb-network-status" }
assertEquals(startTime, networkStatusSpan.startTimeNanos?.nanosToMillis())
networkStatusSpan.attributes?.assertMatches {
"emb.type" to "sys.network_status"
}
networkStatusSpan.attributes?.assertMatches(mapOf(
"emb.type" to "sys.network_status",
))

// validate session span
val spans = checkNotNull(message.data.spans)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ internal class ActivityFeatureTest {
val message = getSingleSessionEnvelope()
val viewSpan = message.findSpanOfType(EmbType.Ux.View)

viewSpan.attributes?.assertMatches {
viewSpan.attributes?.assertMatches(mapOf(
"view.name" to "android.app.Activity"
}
))

with(viewSpan) {
assertEquals(startTimeMs, startTimeNanos?.nanosToMillis())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ internal class AeiFeatureTest {
val log = getSingleLogEnvelope().getLastLog()

// assert AEI fields populated
log.attributes?.assertMatches {
"timestamp" to 15000000000L
"aei_session_id" to "1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d"
"process_importance" to 125
"pss" to 1509123409L
"rss" to 1123409L
"exit_status" to 1
"description" to "testDescription"
"reason" to 4
"emb.type" to "sys.exit"
}
log.attributes?.assertMatches(mapOf(
"timestamp" to 15000000000L,
"aei_session_id" to "1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d",
"process_importance" to 125,
"pss" to 1509123409L,
"rss" to 1123409L,
"exit_status" to 1,
"description" to "testDescription",
"reason" to 4,
"emb.type" to "sys.exit",
))
assertEquals("testInputStream", log.body)
}
)
Expand All @@ -75,4 +75,4 @@ internal class AeiFeatureTest {
every { traceInputStream } returns "testInputStream".byteInputStream()
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,25 @@ internal class AnrFeatureTest {
assertEquals(endTime, span.endTimeNanos?.nanosToMillis())

// assert span attributes
span.attributes?.assertMatches {
"emb.type" to "perf.thread_blockage"
span.attributes?.assertMatches(mapOf(
"emb.type" to "perf.thread_blockage",
"interval_code" to expectedIntervalCode
}
))

val events = checkNotNull(span.events)

events.forEachIndexed { index, event ->
assertEquals("perf.thread_blockage_sample", event.name)

// assert attributes
event.attributes?.assertMatches {
"emb.type" to "perf.thread_blockage_sample"
"sample_overhead" to 0
event.attributes?.assertMatches(mapOf(
"emb.type" to "perf.thread_blockage_sample",
"sample_overhead" to 0,
"sample_code" to when {
index < MAX_SAMPLE_COUNT -> "0"
else -> "1"
}
}
))

// assert interval time
val expectedTime = startTime + ANR_THRESHOLD_MS + ((index + 1) * INTERVAL_MS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ internal class BreadcrumbFeatureTest {
}

private fun Envelope<SessionPayload>.assertBreadcrumbWithMessage(message: String) {
findSessionSpan().findEventOfType(EmbType.System.Breadcrumb).attributes?.assertMatches {
findSessionSpan().findEventOfType(EmbType.System.Breadcrumb).attributes?.assertMatches(mapOf(
"message" to message
}
))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ internal class JvmCrashFeatureTest {
val message = getSingleSessionEnvelope()
val crashId = message.getSessionSpan()?.attributes?.findAttributeValue(embCrashId.name)
assertNotNull(crashId)
log.attributes?.assertMatches {
"emb.android.react_native_crash.js_exception" to expectedJsException
"emb.android.crash_number" to 1
"emb.android.crash.exception_cause" to expectedExceptionCause
log.attributes?.assertMatches(mapOf(
"emb.android.react_native_crash.js_exception" to expectedJsException,
"emb.android.crash_number" to 1,
"emb.android.crash.exception_cause" to expectedExceptionCause,
LogIncubatingAttributes.LOG_RECORD_UID.key to crashId
}
))
assertNotNull(log.attributes?.findAttributeValue("emb.android.threads"))
}
)
Expand Down Expand Up @@ -155,12 +155,12 @@ internal class JvmCrashFeatureTest {
val exceptionInfo = LegacyExceptionInfo.ofThrowable(testException)
val expectedExceptionCause = serializer.toJson(listOf(exceptionInfo), List::class.java)

attributes?.assertMatches {
embState.attributeKey.key to state
"emb.android.crash_number" to 1
"emb.android.crash.exception_cause" to expectedExceptionCause
attributes?.assertMatches(mapOf(
embState.attributeKey.key to state,
"emb.android.crash_number" to 1,
"emb.android.crash.exception_cause" to expectedExceptionCause,
LogIncubatingAttributes.LOG_RECORD_UID.key to crashId
}
))
assertNotNull(attributes?.findAttributeValue("emb.android.threads"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ internal class LowPowerFeatureTest {
assertAction = {
val message = getSingleSessionEnvelope()
val span = message.findSpanOfType(EmbType.System.LowPower)
span.attributes?.assertMatches {
span.attributes?.assertMatches(mapOf(
"emb.type" to "sys.low_power"
}
))
assertEquals("emb-device-low-power", span.name)
assertEquals(startTimeMs, span.startTimeNanos?.nanosToMillis())
assertEquals(startTimeMs + tickTimeMs, span.endTimeNanos?.nanosToMillis())
Expand Down
Loading

0 comments on commit 2bfd09d

Please sign in to comment.