-
Notifications
You must be signed in to change notification settings - Fork 7
/
SessionBehaviorTest.kt
92 lines (82 loc) · 3.05 KB
/
SessionBehaviorTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package io.embrace.android.embracesdk.config.behavior
import io.embrace.android.embracesdk.config.local.SessionLocalConfig
import io.embrace.android.embracesdk.config.remote.RemoteConfig
import io.embrace.android.embracesdk.config.remote.SessionRemoteConfig
import io.embrace.android.embracesdk.fakes.fakeSessionBehavior
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
internal class SessionBehaviorTest {
private val local = SessionLocalConfig(
sessionComponents = setOf("breadcrumbs"),
fullSessionEvents = setOf("crash"),
sessionEnableErrorLogStrictMode = true
)
private val remote = RemoteConfig(
sessionConfig = SessionRemoteConfig(
isEnabled = true,
useV2Payload = true,
sessionComponents = setOf("test"),
fullSessionEvents = setOf("test2")
),
maxSessionProperties = 57,
)
@Test
fun testDefaults() {
with(fakeSessionBehavior()) {
assertFalse(isSessionErrorLogStrictModeEnabled())
assertEquals(emptySet<String>(), getFullSessionEvents())
assertNull(getSessionComponents())
assertFalse(isGatingFeatureEnabled())
assertFalse(isSessionControlEnabled())
assertEquals(10, getMaxSessionProperties())
assertFalse(useV2Payload())
}
}
@Test
fun testLocalOnly() {
with(fakeSessionBehavior(localCfg = { local })) {
assertTrue(isSessionErrorLogStrictModeEnabled())
assertEquals(setOf("breadcrumbs"), getSessionComponents())
assertEquals(setOf("crash"), getFullSessionEvents())
assertTrue(isGatingFeatureEnabled())
assertFalse(useV2Payload())
}
}
@Test
fun testRemoteAndLocal() {
with(fakeSessionBehavior(localCfg = { local }, remoteCfg = { remote })) {
assertTrue(isGatingFeatureEnabled())
assertTrue(isSessionControlEnabled())
assertEquals(setOf("test"), getSessionComponents())
assertEquals(setOf("test2"), getFullSessionEvents())
assertEquals(57, getMaxSessionProperties())
assertTrue(useV2Payload())
}
}
@Test
fun `test upper case full session events`() {
val behavior = fakeSessionBehavior(
remoteCfg = {
buildGatingConfig(setOf("CRASHES", "ERRORS"))
}
)
assertEquals(setOf("crashes", "errors"), behavior.getFullSessionEvents())
}
@Test
fun `test lower case full session events`() {
val behavior = fakeSessionBehavior(
remoteCfg = {
buildGatingConfig(setOf("crashes", "errors"))
}
)
assertEquals(setOf("crashes", "errors"), behavior.getFullSessionEvents())
}
private fun buildGatingConfig(events: Set<String>) = RemoteConfig(
sessionConfig = SessionRemoteConfig(
fullSessionEvents = events
)
)
}