Skip to content

Commit 75b2a22

Browse files
committed
Fix tests
1 parent e3dcd5a commit 75b2a22

File tree

4 files changed

+112
-174
lines changed

4 files changed

+112
-174
lines changed
Lines changed: 4 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,9 @@
11
package io.sentry.kotlin.multiplatform
22

33
import io.sentry.kotlin.multiplatform.log.toCocoaMap
4-
import kotlin.test.Test
5-
import kotlin.test.assertEquals
6-
import kotlin.test.assertTrue
74

8-
/** Tests for SentryAttributes to Cocoa map conversion. */
9-
class SentryAttributesConversionTest {
10-
@Test
11-
fun `empty attributes converts to empty map`() {
12-
val attrs = SentryAttributes.empty()
13-
14-
val map = attrs.toCocoaMap()
15-
16-
assertTrue(map.isEmpty())
17-
}
18-
19-
@Test
20-
fun `string attribute converts correctly`() {
21-
val attrs = SentryAttributes.empty()
22-
attrs["key"] = "value"
23-
24-
val map = attrs.toCocoaMap()
25-
26-
assertEquals("value", map["key"])
27-
}
28-
29-
@Test
30-
fun `long attribute converts correctly`() {
31-
val attrs = SentryAttributes.empty()
32-
attrs["count"] = 42L
33-
34-
val map = attrs.toCocoaMap()
35-
36-
assertEquals(42L, map["count"])
37-
}
38-
39-
@Test
40-
fun `double attribute converts correctly`() {
41-
val attrs = SentryAttributes.empty()
42-
attrs["ratio"] = 3.14
43-
44-
val map = attrs.toCocoaMap()
45-
46-
assertEquals(3.14, map["ratio"])
47-
}
48-
49-
@Test
50-
fun `boolean attribute converts correctly`() {
51-
val attrs = SentryAttributes.empty()
52-
attrs["enabled"] = true
53-
54-
val map = attrs.toCocoaMap()
55-
56-
assertEquals(true, map["enabled"])
57-
}
58-
59-
@Test
60-
fun `multiple attributes convert correctly`() {
61-
val attrs = SentryAttributes.empty()
62-
attrs["string"] = "text"
63-
attrs["number"] = 123L
64-
attrs["decimal"] = 1.5
65-
attrs["flag"] = false
66-
67-
val map = attrs.toCocoaMap()
68-
69-
assertEquals(4, map.size)
70-
assertEquals("text", map["string"])
71-
assertEquals(123L, map["number"])
72-
assertEquals(1.5, map["decimal"])
73-
assertEquals(false, map["flag"])
74-
}
75-
76-
@Test
77-
fun `int converts to long`() {
78-
val attrs = SentryAttributes.empty()
79-
attrs["int_value"] = 42 // Int gets stored as Long
80-
81-
val map = attrs.toCocoaMap()
82-
83-
assertEquals(42L, map["int_value"])
84-
}
85-
86-
@Test
87-
fun `unicode values convert correctly`() {
88-
val attrs = SentryAttributes.empty()
89-
attrs["emoji"] = "🚀"
90-
attrs["chinese"] = "中文"
91-
92-
val map = attrs.toCocoaMap()
93-
94-
assertEquals("🚀", map["emoji"])
95-
assertEquals("中文", map["chinese"])
96-
}
5+
class SentryAttributesConversionTest : BaseSentryAttributesConversionTest() {
6+
@Suppress("UNCHECKED_CAST")
7+
override fun SentryAttributes.toMap(): Map<String, Any?> =
8+
toCocoaMap() as Map<String, Any?>
979
}
Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,7 @@
11
package io.sentry.kotlin.multiplatform
22

33
import io.sentry.kotlin.multiplatform.log.toJvmSentryAttributes
4-
import kotlin.test.Test
5-
import kotlin.test.assertEquals
6-
import kotlin.test.assertTrue
74

8-
/** Tests for SentryAttributes to JVM conversion. */
9-
class SentryAttributesConversionTest {
10-
@Test
11-
fun `empty attributes converts to empty JVM attributes`() {
12-
val kmpAttrs = SentryAttributes.empty()
13-
14-
val jvmAttrs = kmpAttrs.toJvmSentryAttributes()
15-
16-
assertTrue(jvmAttrs.attributes.isEmpty())
17-
}
18-
19-
@Test
20-
fun `string attribute converts correctly`() {
21-
val kmpAttrs = SentryAttributes.empty()
22-
kmpAttrs["key"] = "value"
23-
24-
val jvmAttrs = kmpAttrs.toJvmSentryAttributes()
25-
26-
assertEquals("value", jvmAttrs.attributes["key"])
27-
}
28-
29-
@Test
30-
fun `long attribute converts correctly`() {
31-
val kmpAttrs = SentryAttributes.empty()
32-
kmpAttrs["count"] = 42L
33-
34-
val jvmAttrs = kmpAttrs.toJvmSentryAttributes()
35-
36-
assertEquals(42L, jvmAttrs.attributes["count"])
37-
}
38-
39-
@Test
40-
fun `double attribute converts correctly`() {
41-
val kmpAttrs = SentryAttributes.empty()
42-
kmpAttrs["ratio"] = 3.14
43-
44-
val jvmAttrs = kmpAttrs.toJvmSentryAttributes()
45-
46-
assertEquals(3.14, jvmAttrs.attributes["ratio"])
47-
}
48-
49-
@Test
50-
fun `boolean attribute converts correctly`() {
51-
val kmpAttrs = SentryAttributes.empty()
52-
kmpAttrs["enabled"] = true
53-
54-
val jvmAttrs = kmpAttrs.toJvmSentryAttributes()
55-
56-
assertEquals(true, jvmAttrs.attributes["enabled"])
57-
}
58-
59-
@Test
60-
fun `multiple attributes convert correctly`() {
61-
val kmpAttrs = SentryAttributes.empty()
62-
kmpAttrs["string"] = "text"
63-
kmpAttrs["number"] = 123L
64-
kmpAttrs["decimal"] = 1.5
65-
kmpAttrs["flag"] = false
66-
67-
val jvmAttrs = kmpAttrs.toJvmSentryAttributes()
68-
69-
assertEquals(4, jvmAttrs.attributes.size)
70-
assertEquals("text", jvmAttrs.attributes["string"])
71-
assertEquals(123L, jvmAttrs.attributes["number"])
72-
assertEquals(1.5, jvmAttrs.attributes["decimal"])
73-
assertEquals(false, jvmAttrs.attributes["flag"])
74-
}
75-
76-
@Test
77-
fun `int converts to long`() {
78-
val kmpAttrs = SentryAttributes.empty()
79-
kmpAttrs["int_value"] = 42 // Int gets stored as Long
80-
81-
val jvmAttrs = kmpAttrs.toJvmSentryAttributes()
82-
83-
assertEquals(42L, jvmAttrs.attributes["int_value"])
84-
}
5+
class SentryAttributesConversionTest : BaseSentryAttributesConversionTest() {
6+
override fun SentryAttributes.toMap(): Map<String, Any?> = toJvmSentryAttributes().attributes
857
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package io.sentry.kotlin.multiplatform
2+
3+
import kotlin.test.Test
4+
import kotlin.test.assertEquals
5+
import kotlin.test.assertTrue
6+
7+
/**
8+
* Base test class for SentryAttributes conversion tests.
9+
* Platform-specific tests should extend this class and provide
10+
* the conversion implementation.
11+
*/
12+
abstract class BaseSentryAttributesConversionTest {
13+
/**
14+
* Converts SentryAttributes to a platform-specific map for assertions.
15+
* Each platform provides its own implementation using the appropriate converter.
16+
*/
17+
abstract fun SentryAttributes.toMap(): Map<String, Any?>
18+
19+
@Test
20+
fun `empty attributes converts to empty map`() {
21+
val attrs = SentryAttributes.empty()
22+
23+
val map = attrs.toMap()
24+
25+
assertTrue(map.isEmpty())
26+
}
27+
28+
@Test
29+
fun `string attribute converts correctly`() {
30+
val attrs = SentryAttributes.empty()
31+
attrs["key"] = "value"
32+
33+
val map = attrs.toMap()
34+
35+
assertEquals("value", map["key"])
36+
}
37+
38+
@Test
39+
fun `long attribute converts correctly`() {
40+
val attrs = SentryAttributes.empty()
41+
attrs["count"] = 42L
42+
43+
val map = attrs.toMap()
44+
45+
assertEquals(42L, map["count"])
46+
}
47+
48+
@Test
49+
fun `double attribute converts correctly`() {
50+
val attrs = SentryAttributes.empty()
51+
attrs["ratio"] = 3.14
52+
53+
val map = attrs.toMap()
54+
55+
assertEquals(3.14, map["ratio"])
56+
}
57+
58+
@Test
59+
fun `boolean attribute converts correctly`() {
60+
val attrs = SentryAttributes.empty()
61+
attrs["enabled"] = true
62+
63+
val map = attrs.toMap()
64+
65+
assertEquals(true, map["enabled"])
66+
}
67+
68+
@Test
69+
fun `multiple attributes convert correctly`() {
70+
val attrs = SentryAttributes.empty()
71+
attrs["string"] = "text"
72+
attrs["number"] = 123L
73+
attrs["decimal"] = 1.5
74+
attrs["flag"] = false
75+
76+
val map = attrs.toMap()
77+
78+
assertEquals(4, map.size)
79+
assertEquals("text", map["string"])
80+
assertEquals(123L, map["number"])
81+
assertEquals(1.5, map["decimal"])
82+
assertEquals(false, map["flag"])
83+
}
84+
85+
@Test
86+
fun `int converts to long`() {
87+
val attrs = SentryAttributes.empty()
88+
attrs["int_value"] = 42
89+
90+
val map = attrs.toMap()
91+
92+
assertEquals(42L, map["int_value"])
93+
}
94+
95+
@Test
96+
fun `unicode values convert correctly`() {
97+
val attrs = SentryAttributes.empty()
98+
attrs["emoji"] = "🚀"
99+
attrs["chinese"] = "中文"
100+
101+
val map = attrs.toMap()
102+
103+
assertEquals("🚀", map["emoji"])
104+
assertEquals("中文", map["chinese"])
105+
}
106+
}

sentry-samples/kmp-app-cocoapods/shared/src/commonMain/kotlin/sample.kmp.app/LoginImpl.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package sample.kmp.app
22

33
import io.sentry.kotlin.multiplatform.Sentry
4-
import io.sentry.kotlin.multiplatform.SentryAttributeValue
5-
import io.sentry.kotlin.multiplatform.SentryAttributes
64
import io.sentry.kotlin.multiplatform.SentryLevel
75
import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
86
import io.sentry.kotlin.multiplatform.protocol.User

0 commit comments

Comments
 (0)