Skip to content

dataconnect: modernize SerializationTestData.kt to use Arb instead of bespoke random data generation #6339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.google.firebase.dataconnect

import com.google.firebase.dataconnect.SerializationTestData.serializationTestDataAllTypes
import com.google.firebase.dataconnect.SerializationTestData.withEmptyListOfUnitRecursive
import com.google.firebase.dataconnect.testutil.shouldContainWithNonAbuttingTextIgnoringCase
import com.google.firebase.dataconnect.util.ProtoUtil.buildStructProto
import com.google.firebase.dataconnect.util.ProtoUtil.decodeFromStruct
Expand All @@ -31,9 +33,9 @@ import io.kotest.property.arbitrary.arbitrary
import io.kotest.property.arbitrary.boolean
import io.kotest.property.arbitrary.constant
import io.kotest.property.arbitrary.double
import io.kotest.property.arbitrary.filter
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.list
import io.kotest.property.arbitrary.map
import io.kotest.property.arbitrary.orNull
import io.kotest.property.arbitrary.string
import io.kotest.property.checkAll
Expand All @@ -47,17 +49,21 @@ class ProtoStructDecoderUnitTest {

@Test
fun `decodeFromStruct() can encode and decode complex objects`() = runTest {
val seeds = Arb.string().filter { it.hashCode() != 0 }
checkAll(iterations = 20, seeds) { seed ->
val obj = SerializationTestData.AllTheTypes.newInstance(seed).withEmptyUnitLists()
// TODO(b/370992204) Remove the call to withEmptyListOfUnitRecursive() once the bug that a list
// of Unit is incorrectly decoded as an empty list is fixed.
val arb = Arb.serializationTestDataAllTypes().map { it.withEmptyListOfUnitRecursive() }
checkAll(iterations = 20, arb) { obj ->
val struct = encodeToStruct(obj)
val decodedObj = decodeFromStruct<SerializationTestData.AllTheTypes>(struct)
decodedObj shouldBe obj
}
}

@Ignore(
"b/370992204: Re-enable this test once the bug that a list of Unit is incorrectly " +
"decoded as an empty list is fixed"
)
@Test
@Ignore("A List<Unit> gets decoded as an empty list; if anyone cares, fix it.")
fun `decodeFromStruct() can encode and decode a list of non-nullable Unit`() = runTest {
@Serializable data class TestData(val list: List<Unit>)
checkAll(Arb.list(Arb.constant(Unit))) { list ->
Expand Down
Loading
Loading