Skip to content

Commit

Permalink
add function
Browse files Browse the repository at this point in the history
  • Loading branch information
buenaflor committed Sep 27, 2024
1 parent 6ed4593 commit 1d3e602
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ internal actual class SentryBridge actual constructor(private val sentryInstance
return SentrySDK.crashedLastRun()
}

actual fun isEnabled(): Boolean {
return SentrySDK.isEnabled()
}

actual fun close() {
SentrySDK.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ internal actual class SentryBridge actual constructor(private val sentryInstance
return Sentry.isCrashedLastRun() ?: false
}

actual fun isEnabled(): Boolean {
return Sentry.isEnabled()
}

actual fun close() {
Sentry.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ internal expect class SentryBridge(sentryInstance: SentryInstance = SentryPlatfo

fun isCrashedLastRun(): Boolean

fun isEnabled(): Boolean

fun close()
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ public object Sentry {
throw RuntimeException("Uncaught Exception from Kotlin Multiplatform.")
}

/**
* Checks if the SDK is enabled.
*/
public fun isEnabled(): Boolean {
return bridge.isEnabled()
}

/**
* Closes the SDK.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
import io.sentry.kotlin.multiplatform.protocol.User
import io.sentry.kotlin.multiplatform.utils.fakeDsn
import kotlinx.coroutines.test.runTest
import kotlin.test.AfterTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlin.test.*

class SentryIntegrationTest : BaseSentryTest() {
@AfterTest
Expand Down Expand Up @@ -225,6 +220,20 @@ class SentryIntegrationTest : BaseSentryTest() {
assertEquals(expectedUsername, actualUsername)
}

@Test
fun `isEnabled returns true when SDK is enabled`() {
sentryInit {
it.dsn = fakeDsn
}

assertTrue(Sentry.isEnabled())
}

@Test
fun `isEnabled returns false when SDK is disabled`() {
assertFalse(Sentry.isEnabled())
}

@Test
fun `global scope sets context correctly with different data types`() = runTest {
val stringKey = "stringKey"
Expand Down

0 comments on commit 1d3e602

Please sign in to comment.