From 83f0192f1f318fd7b11bca72923ed193e03b4e9e Mon Sep 17 00:00:00 2001 From: Gijs van Veen Date: Mon, 15 Apr 2024 17:39:42 +0200 Subject: [PATCH] Make raw internal/Disable Android DB test --- .../kotlin/dev/gitlive/firebase/internal/EncodedObject.kt | 2 +- .../kotlin/dev/gitlive/firebase/internal/EncodedObject.kt | 8 +++++--- .../kotlin/dev/gitlive/firebase/internal/EncodersTest.kt | 6 +++--- .../kotlin/dev/gitlive/firebase/internal/EncodedObject.kt | 2 +- .../kotlin/dev/gitlive/firebase/internal/EncodedObject.kt | 2 +- .../kotlin/dev/gitlive/firebase/database/database.kt | 3 +++ .../kotlin/dev/gitlive/firebase/database/database.kt | 1 + .../kotlin/dev/gitlive/firebase/database/database.kt | 3 +++ .../kotlin/dev/gitlive/firebase/database/database.kt | 2 ++ .../kotlin/dev/gitlive/firebase/database/database.kt | 2 ++ gradle.properties | 2 +- 11 files changed, 23 insertions(+), 10 deletions(-) diff --git a/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt b/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt index 6d7f8d63a..1e5fc20a8 100644 --- a/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt +++ b/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt @@ -1,7 +1,7 @@ @file:JvmName("AndroidEncodedObject") package dev.gitlive.firebase.internal -val EncodedObject.android: Map get() = raw +val EncodedObject.android: Map get() = getRaw() @PublishedApi internal actual fun Any.asNativeMap(): Map<*, *>? = this as? Map<*, *> diff --git a/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt index e02664500..9c070b82d 100644 --- a/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt +++ b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt @@ -6,13 +6,15 @@ import kotlin.jvm.JvmInline * Platform specific object for storing encoded data that can be used for methods that explicitly require an object. * This is essentially a [Map] of [String] and [Any]? (as represented by [raw]) but since [encode] gives a platform specific value, this method wraps that. */ -sealed interface EncodedObject { - val raw: Map +sealed interface EncodedObject + +internal fun EncodedObject.getRaw(): Map = when (this) { + is EncodedObjectImpl -> raw } @JvmInline @PublishedApi -internal value class EncodedObjectImpl(override val raw: Map) : EncodedObject +internal value class EncodedObjectImpl(val raw: Map) : EncodedObject @PublishedApi internal expect fun Any.asNativeMap(): Map<*, *>? diff --git a/firebase-common-internal/src/commonTest/kotlin/dev/gitlive/firebase/internal/EncodersTest.kt b/firebase-common-internal/src/commonTest/kotlin/dev/gitlive/firebase/internal/EncodersTest.kt index 124a431e4..1e2385846 100644 --- a/firebase-common-internal/src/commonTest/kotlin/dev/gitlive/firebase/internal/EncodersTest.kt +++ b/firebase-common-internal/src/commonTest/kotlin/dev/gitlive/firebase/internal/EncodersTest.kt @@ -428,12 +428,12 @@ class EncodersTest { testDataClass ) { encodeDefaults = false } - nativeAssertEquals(mapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "valueClass" to 42), encodedObject.raw) + nativeAssertEquals(mapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "valueClass" to 42), encodedObject.getRaw()) val testMap = mapOf("one" to 1, "two" to null, "three" to false) - assertEquals(testMap, encodeAsObject(testMap).raw) + assertEquals(testMap, encodeAsObject(testMap).getRaw()) - assertEquals(emptyMap(), encodeAsObject(TestObject).raw) + assertEquals(emptyMap(), encodeAsObject(TestObject).getRaw()) assertFailsWith { encodeAsObject( diff --git a/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt b/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt index c261934f1..9d4e6643a 100644 --- a/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt +++ b/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt @@ -1,6 +1,6 @@ package dev.gitlive.firebase.internal -val EncodedObject.ios: Map get() = raw.mapKeys { (key, _) -> key } +val EncodedObject.ios: Map get() = getRaw().mapKeys { (key, _) -> key } @PublishedApi internal actual fun Any.asNativeMap(): Map<*, *>? = this as? Map<*, *> diff --git a/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt b/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt index 5fc84a829..47f3aad5e 100644 --- a/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt +++ b/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt @@ -3,7 +3,7 @@ package dev.gitlive.firebase.internal import kotlin.js.Json import kotlin.js.json -val EncodedObject.js: Json get() = json(*raw.entries.map { (key, value) -> key to value }.toTypedArray()) +val EncodedObject.js: Json get() = json(*getRaw().entries.map { (key, value) -> key to value }.toTypedArray()) @PublishedApi internal actual fun Any.asNativeMap(): Map<*, *>? { diff --git a/firebase-database/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/database/database.kt index d0b8ea390..c10dd8972 100644 --- a/firebase-database/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/database/database.kt @@ -6,9 +6,12 @@ package dev.gitlive.firebase.database import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Ignore actual val emulatorHost: String = "10.0.2.2" actual val context: Any = InstrumentationRegistry.getInstrumentation().targetContext @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) actual annotation class IgnoreForAndroidUnitTest + +actual typealias IgnoreForAndroidTest = Ignore diff --git a/firebase-database/src/androidUnitTest/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/androidUnitTest/kotlin/dev/gitlive/firebase/database/database.kt index b0fbae1d3..a54a41bbd 100644 --- a/firebase-database/src/androidUnitTest/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/androidUnitTest/kotlin/dev/gitlive/firebase/database/database.kt @@ -11,3 +11,4 @@ actual val emulatorHost: String = "10.0.2.2" actual val context: Any = "" actual typealias IgnoreForAndroidUnitTest = Ignore +actual typealias IgnoreForAndroidTest = Ignore diff --git a/firebase-database/src/commonTest/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/commonTest/kotlin/dev/gitlive/firebase/database/database.kt index 568d0868d..4c1c9a754 100644 --- a/firebase-database/src/commonTest/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/commonTest/kotlin/dev/gitlive/firebase/database/database.kt @@ -25,6 +25,7 @@ import kotlin.time.Duration.Companion.minutes expect val emulatorHost: String expect val context: Any expect annotation class IgnoreForAndroidUnitTest() +expect annotation class IgnoreForAndroidTest() @IgnoreForAndroidUnitTest class FirebaseDatabaseTest { @@ -197,6 +198,8 @@ class FirebaseDatabaseTest { assertFalse(valueEvents.first().exists) } + // Ignoring on Android Instrumented Tests due to bug in Firebase: https://github.com/firebase/firebase-android-sdk/issues/5870 + @IgnoreForAndroidTest @Test fun testUpdateChildrenOnDisconnect() = runTest { setupRealtimeData() diff --git a/firebase-database/src/iosTest/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/iosTest/kotlin/dev/gitlive/firebase/database/database.kt index 410cf18bb..294fe1913 100644 --- a/firebase-database/src/iosTest/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/iosTest/kotlin/dev/gitlive/firebase/database/database.kt @@ -10,3 +10,5 @@ actual val context: Any = Unit @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) actual annotation class IgnoreForAndroidUnitTest +@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) +actual annotation class IgnoreForAndroidTest diff --git a/firebase-database/src/jsTest/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/jsTest/kotlin/dev/gitlive/firebase/database/database.kt index 48e4649bb..f1821d3c3 100644 --- a/firebase-database/src/jsTest/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/jsTest/kotlin/dev/gitlive/firebase/database/database.kt @@ -6,3 +6,5 @@ actual val context: Any = Unit @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) actual annotation class IgnoreForAndroidUnitTest +@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) +actual annotation class IgnoreForAndroidTest diff --git a/gradle.properties b/gradle.properties index e8d09666a..adc37e244 100644 --- a/gradle.properties +++ b/gradle.properties @@ -67,6 +67,6 @@ gradlePluginVersion=8.1.3 kotlinVersion=1.9.21 coroutinesVersion=1.7.3 serializationVersion=1.6.0 -firebaseBoMVersion=32.7.0 +firebaseBoMVersion=32.8.1 apiVersion=1.8 languageVersion=1.9