Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: set status and associate events with transactions (#1426)
- Loading branch information
1 parent
1ba7b8e
commit 407f709
Showing
17 changed files
with
211 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
public final class io/sentry/test/AssertionsKt { | ||
public static final fun checkEvent (Lkotlin/jvm/functions/Function1;)Lio/sentry/SentryEnvelope; | ||
public static final fun checkTransaction (Lkotlin/jvm/functions/Function1;)Lio/sentry/SentryEnvelope; | ||
} | ||
|
27 changes: 23 additions & 4 deletions
27
sentry-test-support/src/main/kotlin/io/sentry/test/assertions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,39 @@ | ||
package io.sentry.test | ||
|
||
import com.nhaarman.mockitokotlin2.check | ||
import io.sentry.GsonSerializer | ||
import io.sentry.SentryEnvelope | ||
import io.sentry.SentryEvent | ||
import io.sentry.SentryOptions | ||
import io.sentry.protocol.SentryTransaction | ||
import java.lang.AssertionError | ||
|
||
/** | ||
* Verifies is [SentryEnvelope] contains first event matching a predicate. | ||
*/ | ||
inline fun checkEvent(noinline predicate: (SentryEvent) -> Unit): SentryEnvelope { | ||
fun checkEvent(predicate: (SentryEvent) -> Unit): SentryEnvelope { | ||
val options = SentryOptions().apply { | ||
setSerializer(GsonSerializer(SentryOptions())) | ||
} | ||
return check { | ||
val event: SentryEvent? = it.items.first().getEvent(options.serializer) | ||
if (event != null) { | ||
predicate(event) | ||
} else { | ||
throw AssertionError("event is null") | ||
} | ||
} | ||
} | ||
|
||
fun checkTransaction(predicate: (SentryTransaction) -> Unit): SentryEnvelope { | ||
val options = SentryOptions().apply { | ||
setSerializer(GsonSerializer(SentryOptions())) | ||
} | ||
return check { | ||
val event = it.items.first().getEvent(options.serializer)!! | ||
predicate(event) | ||
val transaction = it.items.first().getTransaction(options.serializer) | ||
if (transaction != null) { | ||
predicate(transaction) | ||
} else { | ||
throw AssertionError("transaction is null") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.