From 282ca94cdf7bcdd20cf980efd0021f985224d25f Mon Sep 17 00:00:00 2001 From: Ivan “CLOVIS” Canet Date: Sun, 30 Nov 2025 16:48:45 +0000 Subject: [PATCH] test(cache): Migrate to TestBalloon --- cache/build.gradle.kts | 5 ++++- cache/src/commonTest/kotlin/CacheAdapterTest.kt | 6 +++--- cache/src/commonTest/kotlin/ContextualCacheTest.kt | 6 +++--- cache/src/commonTest/kotlin/ExpirationCacheTest.kt | 8 +++----- cache/src/commonTest/kotlin/MemoryCacheTest.kt | 6 +++--- cache/src/commonTest/kotlin/properties/BatchingCacheAdapter.kt | 8 ++++---- 6 file(s) changed, 20 insertion(s)(+), 19 deletion(s)(-) diff --git a/cache/build.gradle.kts b/cache/build.gradle.kts --- a/cache/build.gradle.kts +++ b/cache/build.gradle.kts @@ -17,6 +17,7 @@ plugins { alias(opensavvyConventions.plugins.base) alias(opensavvyConventions.plugins.kotlin.library) + alias(libsCommon.plugins.testBalloon) } kotlin { @@ -50,7 +51,9 @@ } sourceSets.commonTest.dependencies { - implementation(libs.bundles.prepared) + implementation(libsCommon.opensavvy.prepared.testBalloon) + implementation(libsCommon.opensavvy.prepared.kotlinx.datetime) + implementation(libsCommon.kotlin.test) } } diff --git a/cache/src/commonTest/kotlin/CacheAdapterTest.kt b/cache/src/commonTest/kotlin/CacheAdapterTest.kt --- a/cache/src/commonTest/kotlin/CacheAdapterTest.kt +++ b/cache/src/commonTest/kotlin/CacheAdapterTest.kt @@ -18,11 +18,11 @@ import opensavvy.cache.properties.contextPassthrough import opensavvy.cache.properties.readingValues -import opensavvy.prepared.runner.kotest.PreparedSpec +import opensavvy.prepared.runner.testballoon.preparedSuite -class CacheAdapterTest : PreparedSpec({ +val CacheAdapterTest by preparedSuite { readingValues { it } contextPassthrough { it } -}) +} diff --git a/cache/src/commonTest/kotlin/ContextualCacheTest.kt b/cache/src/commonTest/kotlin/ContextualCacheTest.kt --- a/cache/src/commonTest/kotlin/ContextualCacheTest.kt +++ b/cache/src/commonTest/kotlin/ContextualCacheTest.kt @@ -25,7 +25,7 @@ import opensavvy.cache.contextual.cachedInMemory import opensavvy.cache.contextual.expireAfter import opensavvy.prepared.compat.kotlinx.datetime.clock -import opensavvy.prepared.runner.kotest.PreparedSpec +import opensavvy.prepared.runner.testballoon.preparedSuite import opensavvy.prepared.suite.backgroundScope import opensavvy.prepared.suite.time import opensavvy.state.arrow.out @@ -58,7 +58,7 @@ } @OptIn(ExperimentalTime::class, ExperimentalCoroutinesApi::class) -class ContextualCacheTest : PreparedSpec({ +val ContextualCacheTest by preparedSuite { test("Read") { val cache = createCache() @@ -188,4 +188,4 @@ } } -}) +} diff --git a/cache/src/commonTest/kotlin/ExpirationCacheTest.kt b/cache/src/commonTest/kotlin/ExpirationCacheTest.kt --- a/cache/src/commonTest/kotlin/ExpirationCacheTest.kt +++ b/cache/src/commonTest/kotlin/ExpirationCacheTest.kt @@ -22,9 +22,7 @@ import kotlinx.coroutines.job import kotlinx.coroutines.withTimeout import opensavvy.cache.properties.* -import opensavvy.prepared.compat.kotlinx.datetime.clock -import opensavvy.prepared.compat.kotlinx.datetime.now -import opensavvy.prepared.runner.kotest.PreparedSpec +import opensavvy.prepared.runner.testballoon.preparedSuite import opensavvy.prepared.suite.* import opensavvy.state.coroutines.now import opensavvy.state.outcome.valueOrNull @@ -34,7 +32,7 @@ private val expirationDuration = 10.seconds @OptIn(ExperimentalCoroutinesApi::class, ExperimentalTime::class) -class ExpirationCacheTest : PreparedSpec({ +val ExpirationCacheTest by preparedSuite { fun TestDsl.decorateExpiration(upstream: Cache): Cache = upstream .expireAfter(expirationDuration, backgroundScope, time.clock) @@ -54,7 +52,7 @@ automaticallyExpires { decorateMemoryAndExpiration(it) } contextPassthrough { decorateMemoryAndExpiration(it) } } -}) +} @OptIn(ExperimentalTime::class, ExperimentalCoroutinesApi::class) private fun SuiteDsl.automaticallyExpires( diff --git a/cache/src/commonTest/kotlin/MemoryCacheTest.kt b/cache/src/commonTest/kotlin/MemoryCacheTest.kt --- a/cache/src/commonTest/kotlin/MemoryCacheTest.kt +++ b/cache/src/commonTest/kotlin/MemoryCacheTest.kt @@ -21,7 +21,7 @@ import kotlinx.coroutines.job import kotlinx.coroutines.yield import opensavvy.cache.properties.* -import opensavvy.prepared.runner.kotest.PreparedSpec +import opensavvy.prepared.runner.testballoon.preparedSuite import opensavvy.prepared.suite.TestDsl import opensavvy.prepared.suite.backgroundScope import opensavvy.prepared.suite.launchInBackground @@ -29,7 +29,7 @@ import opensavvy.state.progressive.ProgressiveOutcome import opensavvy.state.progressive.successfulWithProgress -class MemoryCacheTest : PreparedSpec({ +val MemoryCacheTest by preparedSuite { fun TestDsl.decorate(upstream: Cache): Cache = upstream .cachedInMemory(backgroundScope.coroutineContext.job) @@ -64,7 +64,7 @@ check(result == "1".successfulWithProgress()) } -}) +} private suspend fun yieldUntil(predicate: () -> Boolean) { while (!predicate()) { diff --git a/cache/src/commonTest/kotlin/properties/BatchingCacheAdapter.kt b/cache/src/commonTest/kotlin/properties/BatchingCacheAdapter.kt --- a/cache/src/commonTest/kotlin/properties/BatchingCacheAdapter.kt +++ b/cache/src/commonTest/kotlin/properties/BatchingCacheAdapter.kt @@ -22,9 +22,9 @@ import opensavvy.cache.batchingCache import opensavvy.cache.cachedInMemory import opensavvy.cache.expireAfter -import opensavvy.prepared.compat.kotlinx.datetime.clock -import opensavvy.prepared.runner.kotest.PreparedSpec +import opensavvy.prepared.runner.testballoon.preparedSuite import opensavvy.prepared.suite.backgroundScope +import opensavvy.prepared.suite.clock import opensavvy.prepared.suite.time import opensavvy.progress.loading import opensavvy.state.coroutines.now @@ -35,7 +35,7 @@ import kotlin.time.ExperimentalTime @OptIn(ExperimentalCoroutinesApi::class, ExperimentalTime::class) -class BatchingCacheAdapter : PreparedSpec({ +val BatchingCacheAdapter by preparedSuite { test("Checking for batching") { val cache = batchingCache(backgroundScope) { ids -> @@ -63,4 +63,4 @@ check("1" == cache[1].now().valueOrNull) } -}) +} -- tangled.sh