From 7d56c3fefdfc0e7283483f7bab1fc2a74caef3c9 Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Wed, 18 Mar 2026 20:20:40 -0500 Subject: [PATCH] test(data): Add Kotest property-based tests for PacketHandler --- core/data/build.gradle.kts | 2 ++ .../data/manager/PacketHandlerImplTest.kt | 22 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/data/build.gradle.kts b/core/data/build.gradle.kts index b4e18e47c..d032e36e9 100644 --- a/core/data/build.gradle.kts +++ b/core/data/build.gradle.kts @@ -71,6 +71,8 @@ kotlin { commonTest.dependencies { implementation(kotlin("test")) implementation(libs.kotlinx.coroutines.test) + implementation(libs.kotest.assertions) + implementation(libs.kotest.property) } } } diff --git a/core/data/src/commonTest/kotlin/org/meshtastic/core/data/manager/PacketHandlerImplTest.kt b/core/data/src/commonTest/kotlin/org/meshtastic/core/data/manager/PacketHandlerImplTest.kt index a3f39da1c..8e8466132 100644 --- a/core/data/src/commonTest/kotlin/org/meshtastic/core/data/manager/PacketHandlerImplTest.kt +++ b/core/data/src/commonTest/kotlin/org/meshtastic/core/data/manager/PacketHandlerImplTest.kt @@ -22,6 +22,9 @@ import dev.mokkery.every import dev.mokkery.matcher.any import dev.mokkery.mock import dev.mokkery.verifySuspend +import io.kotest.property.Arb +import io.kotest.property.arbitrary.int +import io.kotest.property.checkAll import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestScope @@ -39,6 +42,7 @@ import org.meshtastic.proto.QueueStatus import org.meshtastic.proto.ToRadio import kotlin.test.BeforeTest import kotlin.test.Test +import kotlin.test.assertNotNull class PacketHandlerImplTest { @@ -70,13 +74,16 @@ class PacketHandlerImplTest { handler.start(testScope) } + @Test + fun testInitialization() { + assertNotNull(handler) + } + @Test fun `sendToRadio with ToRadio sends immediately`() { val toRadio = ToRadio(packet = MeshPacket(id = 123)) handler.sendToRadio(toRadio) - - // No explicit assertion here in original test, but we could verify call } @Test @@ -107,6 +114,17 @@ class PacketHandlerImplTest { testScheduler.runCurrent() } + @Test + fun `handleQueueStatus property test`() = runTest(testDispatcher) { + checkAll(Arb.int(0, 10), Arb.int(0, 32), Arb.int(0, 100000)) { res, free, packetId -> + val status = QueueStatus(res = res, free = free, mesh_packet_id = packetId) + + // Ensure it doesn't crash on any input + handler.handleQueueStatus(status) + testScheduler.runCurrent() + } + } + @Test fun `outgoing packets are logged with NODE_NUM_LOCAL`() = runTest(testDispatcher) { val packet = MeshPacket(id = 123, decoded = Data(portnum = PortNum.TEXT_MESSAGE_APP))