From ce3f24642399740e031f8f74fae322b4b2ce8ce6 Mon Sep 17 00:00:00 2001 From: Ivan “CLOVIS” Canet Date: Sat, 20 Dec 2025 14:18:07 +0000 Subject: [PATCH] test(dsl): Technical configuration for running the :dsl tests on more platforms Each platform can configure which BsonFactory implementations are tested using 'testFactories'. However, at the moment, only the JVM configures a factory. The next step is to register a factory for the other platforms. --- dsl/build.gradle.kts | 31 +++++++++++++++++++++++++++++++ dsl/src/commonTest/kotlin/Context.kt | 32 ++++++++++++++++++++++++++++++++ dsl/src/commonTest/kotlin/MultiContext.kt | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ dsl/src/jvmTest/kotlin/Marker.kt | 17 ----------------- dsl/src/jvmTest/kotlin/MultiContext.jvm.kt | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ dsl/src/nativeTest/kotlin/MultiContext.native.kt | 22 ++++++++++++++++++++++ dsl/src/wasmWasiTest/kotlin/MultiContext.wasmWasi.kt | 22 ++++++++++++++++++++++ dsl/src/webTest/kotlin/MultiContext.web.kt | 22 ++++++++++++++++++++++ dsl/src/commonTest/kotlin/aggregation/AggregationStageTest.kt | 6 +++--- dsl/src/commonTest/kotlin/aggregation/AggregationTestUtils.kt | 19 +++++++++++++------ dsl/src/commonTest/kotlin/aggregation/ValueTest.kt | 20 +++++++++++--------- dsl/src/commonTest/kotlin/command/BulkWriteTest.kt | 6 +++--- dsl/src/commonTest/kotlin/command/CountTest.kt | 8 ++++---- dsl/src/commonTest/kotlin/command/DeleteTest.kt | 8 ++++---- dsl/src/commonTest/kotlin/command/DropTest.kt | 8 ++++---- dsl/src/commonTest/kotlin/command/FindTest.kt | 8 ++++---- dsl/src/commonTest/kotlin/command/InsertTest.kt | 19 ++++++++++--------- dsl/src/commonTest/kotlin/command/UpdateTest.kt | 8 ++++---- dsl/src/commonTest/kotlin/command/UpdateWithPipelineTest.kt | 8 ++++---- dsl/src/commonTest/kotlin/options/OptionTest.kt | 8 ++++---- dsl/src/commonTest/kotlin/options/SortTest.kt | 8 ++++---- dsl/src/commonTest/kotlin/options/WriteConcernTest.kt | 8 ++++---- dsl/src/commonTest/kotlin/path/BsonPathConversionsTest.kt | 4 ++-- dsl/src/commonTest/kotlin/path/FieldTest.kt | 6 +++--- dsl/src/commonTest/kotlin/path/PathTest.kt | 6 +++--- dsl/src/commonTest/kotlin/query/ExpressionTestUtils.kt | 5 +---- dsl/src/commonTest/kotlin/query/PredicateExpressionTest.kt | 10 +++++----- dsl/src/jvmTest/kotlin/query/ExpressionTestUtils.jvm.kt | 93 --------------------------------------------------------------------------------------------- dsl/src/commonTest/kotlin/aggregation/operators/ArithmeticValueOperatorsTest.kt | 4 ++-- dsl/src/commonTest/kotlin/aggregation/operators/ArrayValueOperatorsTest.kt | 4 ++-- dsl/src/commonTest/kotlin/aggregation/operators/ConditionalValueOperatorsTest.kt | 4 ++-- dsl/src/commonTest/kotlin/aggregation/operators/StringValueOperatorsTest.kt | 4 ++-- dsl/src/commonTest/kotlin/aggregation/operators/TrigonometryValueOperatorsTest.kt | 4 ++-- dsl/src/commonTest/kotlin/aggregation/operators/TypeValueOperatorsTest.kt | 6 +++--- dsl/src/commonTest/kotlin/aggregation/stages/CountTest.kt | 6 +++--- dsl/src/commonTest/kotlin/aggregation/stages/GroupTest.kt | 4 ++-- dsl/src/commonTest/kotlin/aggregation/stages/LimitTest.kt | 6 +++--- dsl/src/commonTest/kotlin/aggregation/stages/MatchTest.kt | 6 +++--- dsl/src/commonTest/kotlin/aggregation/stages/ProjectTest.kt | 6 +++--- dsl/src/commonTest/kotlin/aggregation/stages/SampleTest.kt | 6 +++--- dsl/src/commonTest/kotlin/aggregation/stages/SetTest.kt | 4 ++-- dsl/src/commonTest/kotlin/aggregation/stages/SkipTest.kt | 6 +++--- dsl/src/commonTest/kotlin/aggregation/stages/SortTest.kt | 6 +++--- dsl/src/commonTest/kotlin/aggregation/stages/UnsetTest.kt | 6 +++--- dsl/src/commonTest/kotlin/query/filter/ArrayFilterTest.kt | 6 +++--- dsl/src/commonTest/kotlin/query/filter/BitwiseFilterTest.kt | 6 +++--- dsl/src/commonTest/kotlin/query/filter/ComparisonFilterTest.kt | 4 ++-- dsl/src/commonTest/kotlin/query/filter/ElementQueryFilterTest.kt | 6 +++--- dsl/src/commonTest/kotlin/query/filter/ExprFilterTest.kt | 4 ++-- dsl/src/commonTest/kotlin/query/filter/FilterUtils.kt | 9 +++++---- dsl/src/commonTest/kotlin/query/filter/LogicalFilterTest.kt | 11 +++++++---- dsl/src/commonTest/kotlin/query/filter/RegexTest.kt | 4 ++-- dsl/src/commonTest/kotlin/query/update/FieldUpdateTest.kt | 4 ++-- dsl/src/commonTest/kotlin/query/update/UpdateUtils.kt | 13 +++++++------ 54 file(s) changed, 470 insertion(s)(+), 265 deletion(s)(-) diff --git a/dsl/build.gradle.kts b/dsl/build.gradle.kts --- a/dsl/build.gradle.kts +++ b/dsl/build.gradle.kts @@ -14,6 +14,10 @@ * limitations under the License. */ +@file:OptIn(ExperimentalWasmDsl::class) + +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl + plugins { alias(opensavvyConventions.plugins.base) alias(opensavvyConventions.plugins.kotlin.library) @@ -24,10 +28,37 @@ kotlin { jvm() + js { + browser() + nodejs() + } + // linuxX64() // TODO https://youtrack.jetbrains.com/issue/KT-83308 Kotlin Native currently crashes on our codebase + // linuxArm64() + // macosX64() + // macosArm64() + // iosArm64() + // iosX64() + // iosSimulatorArm64() + // watchosX64() + // watchosArm32() + // watchosArm64() + // watchosSimulatorArm64() + // tvosX64() + // tvosArm64() + // tvosSimulatorArm64() + // mingwX64() + // wasmJs { // TODO Wasm crashes with a StackOverflow error + // browser() + // nodejs() + // } + // wasmWasi { + // nodejs() + // } sourceSets.commonMain.dependencies { api(projects.bson) api(projects.annotations) + implementation(libsCommon.jetbrains.annotations) } sourceSets.commonTest.dependencies { diff --git a/dsl/src/commonTest/kotlin/Context.kt b/dsl/src/commonTest/kotlin/Context.kt new file mode 100644 --- /dev/null +++ b/dsl/src/commonTest/kotlin/Context.kt @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025-2026, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:OptIn(ExperimentalAtomicApi::class, ExperimentalTime::class) + +package opensavvy.ktmongo.dsl + +import opensavvy.prepared.suite.prepared +import kotlin.concurrent.atomics.ExperimentalAtomicApi +import kotlin.time.ExperimentalTime + +/** + * An instance of [BsonContext] usable for configuring DSL tests. + */ +val testContext by prepared { + BsonContext( + bsonFactory = testBsonFactory(), + ) +} diff --git a/dsl/src/commonTest/kotlin/MultiContext.kt b/dsl/src/commonTest/kotlin/MultiContext.kt new file mode 100644 --- /dev/null +++ b/dsl/src/commonTest/kotlin/MultiContext.kt @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025-2026, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.ktmongo.dsl + +import de.infix.testBalloon.framework.shared.TestDisplayName +import de.infix.testBalloon.framework.shared.TestElementName +import de.infix.testBalloon.framework.shared.TestRegistering +import kotlinx.coroutines.currentCoroutineContext +import opensavvy.ktmongo.bson.BsonFactory +import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.prepared.suite.PreparedDslMarker +import opensavvy.prepared.suite.SuiteDsl +import opensavvy.prepared.suite.TestDsl +import opensavvy.prepared.suite.config.Context +import opensavvy.prepared.suite.config.TestConfig +import opensavvy.prepared.suite.config.plus +import opensavvy.prepared.suite.prepared +import kotlin.coroutines.AbstractCoroutineContextElement +import kotlin.coroutines.CoroutineContext + +/** + * Parameterizes each test by one of the [testBsonFactory] instances. + */ +@PreparedDslMarker +@TestRegistering +fun multiContextSuite( + @TestElementName name: String = "", + @TestDisplayName displayName: String = name, + config: TestConfig = TestConfig.Empty, + content: SuiteDsl.() -> Unit, +) = preparedSuite(name, displayName, preparedConfig = config) { + MultiContextSuite(this).content() +} + +private class MultiContextSuite(private val upstream: SuiteDsl) : SuiteDsl { + override fun suite(name: String, config: TestConfig, block: SuiteDsl.() -> Unit) { + upstream.suite(name, config) { + MultiContextSuite(this).block() + } + } + + override fun test(name: String, config: TestConfig, block: suspend TestDsl.() -> Unit) { + for ((factoryName, factory) in testFactories) { + upstream.test("$name [$factoryName]", config + Context(CurrentBsonFactory(factory)), block) + } + } +} + +private class CurrentBsonFactory(val factory: () -> BsonFactory) : AbstractCoroutineContextElement(CurrentBsonFactory) { + companion object : CoroutineContext.Key +} + +/** + * The different [BsonFactory] implementations that should be used for the test. + * + * The ksys are a human-readable name of the implementation, appended to the test names. + * + * To access the current factory, declare your tests with [multiContextSuite], then access the + * current factory within a test using [testBsonFactory]. + */ +expect val testFactories: Map BsonFactory> + +/** + * The current [BsonFactory]. + * + * This value is only available within tests declared as [multiContextSuite]. + */ +val testBsonFactory by prepared { + val context = currentCoroutineContext()[CurrentBsonFactory] + ?: error("Could not access this test's BsonFactory. Is it declared with multiContextSuite?") + + context.factory() +} diff --git a/dsl/src/jvmTest/kotlin/Marker.kt b/dsl/src/jvmTest/kotlin/Marker.kt deleted file mode 100644 --- a/dsl/src/jvmTest/kotlin/Marker.kt +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2024, OpenSavvy and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package opensavvy.ktmongo.dsl diff --git a/dsl/src/jvmTest/kotlin/MultiContext.jvm.kt b/dsl/src/jvmTest/kotlin/MultiContext.jvm.kt new file mode 100644 --- /dev/null +++ b/dsl/src/jvmTest/kotlin/MultiContext.jvm.kt @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025-2026, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.ktmongo.dsl + +import opensavvy.ktmongo.bson.BsonFactory +import org.bson.codecs.* +import org.bson.codecs.configuration.CodecRegistries +import org.bson.codecs.jsr310.InstantCodec +import org.bson.codecs.jsr310.LocalDateCodec +import org.bson.codecs.jsr310.LocalDateTimeCodec +import org.bson.codecs.jsr310.LocalTimeCodec + +actual val testFactories: Map BsonFactory> = mapOf( + "JVM Official" to { + opensavvy.ktmongo.bson.official.BsonFactory( + codecRegistry = CodecRegistries.fromCodecs( + AtomicBooleanCodec(), + AtomicIntegerCodec(), + AtomicLongCodec(), + BigDecimalCodec(), + BinaryCodec(), + BooleanCodec(), + BsonArrayCodec(), + BsonBinaryCodec(), + BsonBooleanCodec(), + BsonDateTimeCodec(), + BsonDBPointerCodec(), + BsonDecimal128Codec(), + BsonDocumentCodec(), + BsonDoubleCodec(), + BsonInt32Codec(), + BsonInt64Codec(), + BsonJavaScriptCodec(), + BsonMaxKeyCodec(), + BsonMinKeyCodec(), + BsonNullCodec(), + BsonObjectIdCodec(), + BsonRegularExpressionCodec(), + BsonStringCodec(), + BsonSymbolCodec(), + BsonTimestampCodec(), + BsonUndefinedCodec(), + BsonValueCodec(), + ByteArrayCodec(), + ByteCodec(), + CharacterCodec(), + CodeCodec(), + DateCodec(), + Decimal128Codec(), + DocumentCodec(), + DoubleCodec(), + FloatCodec(), + InstantCodec(), + IntegerCodec(), + JsonObjectCodec(), + LocalDateCodec(), + LocalDateTimeCodec(), + LocalTimeCodec(), + LongCodec(), + MaxKeyCodec(), + MinKeyCodec(), + ObjectIdCodec(), + OverridableUuidRepresentationUuidCodec(), + PatternCodec(), + RawBsonDocumentCodec(), + ShortCodec(), + StringCodec(), + SymbolCodec(), + UuidCodec(), + ) + ) + }, +) diff --git a/dsl/src/nativeTest/kotlin/MultiContext.native.kt b/dsl/src/nativeTest/kotlin/MultiContext.native.kt new file mode 100644 --- /dev/null +++ b/dsl/src/nativeTest/kotlin/MultiContext.native.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025-2026, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.ktmongo.dsl + +import opensavvy.ktmongo.bson.BsonFactory + +// TODO: For now, we don't have any implementations for this platform, so no tests run +actual val testFactories: Map BsonFactory> = emptyMap() diff --git a/dsl/src/wasmWasiTest/kotlin/MultiContext.wasmWasi.kt b/dsl/src/wasmWasiTest/kotlin/MultiContext.wasmWasi.kt new file mode 100644 --- /dev/null +++ b/dsl/src/wasmWasiTest/kotlin/MultiContext.wasmWasi.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025-2026, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.ktmongo.dsl + +import opensavvy.ktmongo.bson.BsonFactory + +// TODO: For now, we don't have any implementations for this platform, so no tests run +actual val testFactories: Map BsonFactory> = emptyMap() diff --git a/dsl/src/webTest/kotlin/MultiContext.web.kt b/dsl/src/webTest/kotlin/MultiContext.web.kt new file mode 100644 --- /dev/null +++ b/dsl/src/webTest/kotlin/MultiContext.web.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025-2026, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.ktmongo.dsl + +import opensavvy.ktmongo.bson.BsonFactory + +// TODO: For now, we don't have any implementations for this platform, so no tests run +actual val testFactories: Map BsonFactory> = emptyMap() diff --git a/dsl/src/commonTest/kotlin/aggregation/AggregationStageTest.kt b/dsl/src/commonTest/kotlin/aggregation/AggregationStageTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/AggregationStageTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/AggregationStageTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,10 @@ package opensavvy.ktmongo.dsl.aggregation import opensavvy.ktmongo.dsl.LowLevelApi -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite @OptIn(LowLevelApi::class) -val AggregationStageTest by preparedSuite { +val AggregationStageTest by multiContextSuite { class Target( val foo: String, diff --git a/dsl/src/commonTest/kotlin/aggregation/AggregationTestUtils.kt b/dsl/src/commonTest/kotlin/aggregation/AggregationTestUtils.kt --- a/dsl/src/commonTest/kotlin/aggregation/AggregationTestUtils.kt +++ b/dsl/src/commonTest/kotlin/aggregation/AggregationTestUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,28 +14,32 @@ * limitations under the License. */ +@file:OptIn(LowLevelApi::class) + package opensavvy.ktmongo.dsl.aggregation import opensavvy.ktmongo.bson.BsonFieldWriter +import opensavvy.ktmongo.dsl.BsonContext import opensavvy.ktmongo.dsl.DangerousMongoApi import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext +import opensavvy.ktmongo.dsl.testContext import opensavvy.ktmongo.dsl.tree.BsonNode +import opensavvy.prepared.suite.TestDsl import org.intellij.lang.annotations.Language -@OptIn(LowLevelApi::class) class TestPipeline( - chain: PipelineChainLink = PipelineChainLink(testContext(), null, null) + context: BsonContext, + chain: PipelineChainLink, ) : AbstractPipeline( - testContext(), + context, chain, ), AggregationPipeline, UpdatePipeline { @DangerousMongoApi @LowLevelApi override fun withStage(stage: BsonNode): TestPipeline = - TestPipeline(chain.withStage(stage)) + TestPipeline(context, chain.withStage(stage)) @Suppress("UNCHECKED_CAST") @DangerousMongoApi @@ -51,6 +55,9 @@ } } + +suspend fun TestDsl.TestPipeline(): TestPipeline = + TestPipeline(testContext(), PipelineChainLink(testContext(), null, null)) infix fun Pipeline<*>.shouldBeBson(@Language("MongoDB-JSON") expected: String) { this.toString() shouldBeBson expected diff --git a/dsl/src/commonTest/kotlin/aggregation/ValueTest.kt b/dsl/src/commonTest/kotlin/aggregation/ValueTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/ValueTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/ValueTest.kt @@ -18,18 +18,15 @@ import opensavvy.ktmongo.dsl.BsonContext import opensavvy.ktmongo.dsl.LowLevelApi +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.testContext +import opensavvy.prepared.suite.TestDsl @LowLevelApi -val ValueTest by preparedSuite { +val ValueTest by multiContextSuite { val dollar = "$" - - class AggregationOperatorsImpl : AggregationOperators { - override val context: BsonContext = testContext() - } class Profile( val age: Int, @@ -40,8 +37,13 @@ val profile: Profile, ) - fun value(block: AggregationOperators.() -> Value) = - AggregationOperatorsImpl().block().toString() + suspend fun TestDsl.value(block: AggregationOperators.() -> Value): String { + val context = testContext() + return object : AggregationOperators { + override val context: BsonContext + get() = context + }.block().toString() + } suite("Referring to fields with of") { test("Referring to a top-level field") { diff --git a/dsl/src/commonTest/kotlin/command/BulkWriteTest.kt b/dsl/src/commonTest/kotlin/command/BulkWriteTest.kt --- a/dsl/src/commonTest/kotlin/command/BulkWriteTest.kt +++ b/dsl/src/commonTest/kotlin/command/BulkWriteTest.kt @@ -16,14 +16,14 @@ package opensavvy.ktmongo.dsl.command +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.options.WriteConcern import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.testContext import kotlin.reflect.typeOf import kotlin.time.Duration.Companion.minutes -val BulkWriteTest by preparedSuite { +val BulkWriteTest by multiContextSuite { class Target( val name: String, diff --git a/dsl/src/commonTest/kotlin/command/CountTest.kt b/dsl/src/commonTest/kotlin/command/CountTest.kt --- a/dsl/src/commonTest/kotlin/command/CountTest.kt +++ b/dsl/src/commonTest/kotlin/command/CountTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package opensavvy.ktmongo.dsl.command +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.testContext import kotlin.time.Duration.Companion.minutes -val CountTest by preparedSuite { +val CountTest by multiContextSuite { class Target( val user: String, diff --git a/dsl/src/commonTest/kotlin/command/DeleteTest.kt b/dsl/src/commonTest/kotlin/command/DeleteTest.kt --- a/dsl/src/commonTest/kotlin/command/DeleteTest.kt +++ b/dsl/src/commonTest/kotlin/command/DeleteTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,11 @@ package opensavvy.ktmongo.dsl.command +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.testContext -val DeleteTest by preparedSuite { +val DeleteTest by multiContextSuite { class Target( val user: String, diff --git a/dsl/src/commonTest/kotlin/command/DropTest.kt b/dsl/src/commonTest/kotlin/command/DropTest.kt --- a/dsl/src/commonTest/kotlin/command/DropTest.kt +++ b/dsl/src/commonTest/kotlin/command/DropTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package opensavvy.ktmongo.dsl.command +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.options.WriteConcern import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.testContext -val DropTest by preparedSuite { +val DropTest by multiContextSuite { class Target( val user: String, diff --git a/dsl/src/commonTest/kotlin/command/FindTest.kt b/dsl/src/commonTest/kotlin/command/FindTest.kt --- a/dsl/src/commonTest/kotlin/command/FindTest.kt +++ b/dsl/src/commonTest/kotlin/command/FindTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package opensavvy.ktmongo.dsl.command +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.testContext import kotlin.time.Duration.Companion.minutes -val FindTest by preparedSuite { +val FindTest by multiContextSuite { class Target( val user: String, diff --git a/dsl/src/commonTest/kotlin/command/InsertTest.kt b/dsl/src/commonTest/kotlin/command/InsertTest.kt --- a/dsl/src/commonTest/kotlin/command/InsertTest.kt +++ b/dsl/src/commonTest/kotlin/command/InsertTest.kt @@ -18,22 +18,23 @@ package opensavvy.ktmongo.dsl.command +import opensavvy.ktmongo.bson.BsonDocument import opensavvy.ktmongo.dsl.LowLevelApi +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.options.WriteConcern import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.testContext import kotlin.reflect.typeOf -val InsertTest by preparedSuite { +val InsertTest by multiContextSuite { test("insertOne") { val context = testContext() val daniel = context.buildDocument { writeString("name", "Daniel") - } as opensavvy.ktmongo.bson.official.BsonDocument + } - InsertOne(testContext(), daniel.raw, typeOf()).apply { + InsertOne(testContext(), daniel, typeOf()).apply { options.apply { writeConcern(WriteConcern.FireAndForget) } @@ -57,18 +58,18 @@ val daniel = context.buildDocument { writeString("name", "Daniel") - } as opensavvy.ktmongo.bson.official.BsonDocument + } val fred = context.buildDocument { writeString("name", "Fred") writeInt32("age", 24) - } as opensavvy.ktmongo.bson.official.BsonDocument + } val alice = context.buildDocument { writeString("name", "Alice") - } as opensavvy.ktmongo.bson.official.BsonDocument + } - InsertMany(testContext(), listOf(daniel.raw, fred.raw, alice.raw), typeOf()).apply { + InsertMany(testContext(), listOf(daniel, fred, alice), typeOf()).apply { options.apply { writeConcern(WriteConcern.Primary) } diff --git a/dsl/src/commonTest/kotlin/command/UpdateTest.kt b/dsl/src/commonTest/kotlin/command/UpdateTest.kt --- a/dsl/src/commonTest/kotlin/command/UpdateTest.kt +++ b/dsl/src/commonTest/kotlin/command/UpdateTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package opensavvy.ktmongo.dsl.command +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.options.WriteConcern import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.testContext -val UpdateTest by preparedSuite { +val UpdateTest by multiContextSuite { class Target( val user: String, diff --git a/dsl/src/commonTest/kotlin/command/UpdateWithPipelineTest.kt b/dsl/src/commonTest/kotlin/command/UpdateWithPipelineTest.kt --- a/dsl/src/commonTest/kotlin/command/UpdateWithPipelineTest.kt +++ b/dsl/src/commonTest/kotlin/command/UpdateWithPipelineTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package opensavvy.ktmongo.dsl.command +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.options.WriteConcern import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.testContext -val UpdateWithPipelineTest by preparedSuite { +val UpdateWithPipelineTest by multiContextSuite { class Target( val name: String, diff --git a/dsl/src/commonTest/kotlin/options/OptionTest.kt b/dsl/src/commonTest/kotlin/options/OptionTest.kt --- a/dsl/src/commonTest/kotlin/options/OptionTest.kt +++ b/dsl/src/commonTest/kotlin/options/OptionTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,12 @@ import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.command.CountOptions +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.testContext @LowLevelApi -val OptionTest by preparedSuite { +val OptionTest by multiContextSuite { test("Validate the system") { val countOptions = CountOptions(testContext()) diff --git a/dsl/src/commonTest/kotlin/options/SortTest.kt b/dsl/src/commonTest/kotlin/options/SortTest.kt --- a/dsl/src/commonTest/kotlin/options/SortTest.kt +++ b/dsl/src/commonTest/kotlin/options/SortTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,14 @@ import opensavvy.ktmongo.bson.types.ObjectId import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.command.FindOptions +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.testContext import kotlin.time.ExperimentalTime @OptIn(ExperimentalTime::class) @LowLevelApi -val SortTest by preparedSuite { +val SortTest by multiContextSuite { class Target( val _id: ObjectId, diff --git a/dsl/src/commonTest/kotlin/options/WriteConcernTest.kt b/dsl/src/commonTest/kotlin/options/WriteConcernTest.kt --- a/dsl/src/commonTest/kotlin/options/WriteConcernTest.kt +++ b/dsl/src/commonTest/kotlin/options/WriteConcernTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,13 +18,13 @@ import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.command.UpdateOptions +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.testContext import kotlin.time.Duration.Companion.minutes @LowLevelApi -val WriteConcernTest by preparedSuite { +val WriteConcernTest by multiContextSuite { test("Set majority acknowledgment") { val options = UpdateOptions(testContext()) diff --git a/dsl/src/commonTest/kotlin/path/BsonPathConversionsTest.kt b/dsl/src/commonTest/kotlin/path/BsonPathConversionsTest.kt --- a/dsl/src/commonTest/kotlin/path/BsonPathConversionsTest.kt +++ b/dsl/src/commonTest/kotlin/path/BsonPathConversionsTest.kt @@ -20,13 +20,13 @@ import opensavvy.ktmongo.bson.BsonPath import opensavvy.ktmongo.bson.ExperimentalBsonPathApi +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.update.Friend import opensavvy.ktmongo.dsl.query.update.User import opensavvy.ktmongo.dsl.query.update.update -import opensavvy.prepared.runner.testballoon.preparedSuite import opensavvy.prepared.suite.assertions.checkThrows -val BsonPathConversions by preparedSuite { +val BsonPathConversions by multiContextSuite { test("Simple path with fields") { val _ = update { val name = User::bestFriend / Friend::name diff --git a/dsl/src/commonTest/kotlin/path/FieldTest.kt b/dsl/src/commonTest/kotlin/path/FieldTest.kt --- a/dsl/src/commonTest/kotlin/path/FieldTest.kt +++ b/dsl/src/commonTest/kotlin/path/FieldTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,10 @@ package opensavvy.ktmongo.dsl.path import opensavvy.ktmongo.dsl.LowLevelApi -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite import kotlin.reflect.KProperty1 -val FieldTest by preparedSuite { +val FieldTest by multiContextSuite { class Profile( val name: String, val age: Int, diff --git a/dsl/src/commonTest/kotlin/path/PathTest.kt b/dsl/src/commonTest/kotlin/path/PathTest.kt --- a/dsl/src/commonTest/kotlin/path/PathTest.kt +++ b/dsl/src/commonTest/kotlin/path/PathTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,12 +17,12 @@ package opensavvy.ktmongo.dsl.path import opensavvy.ktmongo.dsl.LowLevelApi +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.path.PathSegment.* import opensavvy.ktmongo.dsl.path.PathSegment.Field -import opensavvy.prepared.runner.testballoon.preparedSuite @OptIn(LowLevelApi::class) -val PathTest by preparedSuite { +val PathTest by multiContextSuite { test("Root field") { check(Path("test").toString() == "test") diff --git a/dsl/src/commonTest/kotlin/query/ExpressionTestUtils.kt b/dsl/src/commonTest/kotlin/query/ExpressionTestUtils.kt --- a/dsl/src/commonTest/kotlin/query/ExpressionTestUtils.kt +++ b/dsl/src/commonTest/kotlin/query/ExpressionTestUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,8 @@ package opensavvy.ktmongo.dsl.query -import opensavvy.ktmongo.dsl.BsonContext import opensavvy.ktmongo.dsl.tree.BsonNode import org.intellij.lang.annotations.Language - -expect fun testContext(): BsonContext infix fun String.shouldBeBson(@Language("MongoDB-JSON") expected: String) { val expected = expected diff --git a/dsl/src/commonTest/kotlin/query/PredicateExpressionTest.kt b/dsl/src/commonTest/kotlin/query/PredicateExpressionTest.kt --- a/dsl/src/commonTest/kotlin/query/PredicateExpressionTest.kt +++ b/dsl/src/commonTest/kotlin/query/PredicateExpressionTest.kt @@ -17,20 +17,20 @@ package opensavvy.ktmongo.dsl.query import opensavvy.ktmongo.bson.BsonType -import opensavvy.ktmongo.dsl.KtMongoDsl import opensavvy.ktmongo.dsl.LowLevelApi -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite +import opensavvy.ktmongo.dsl.testContext +import opensavvy.prepared.suite.TestDsl @OptIn(LowLevelApi::class) -@KtMongoDsl -private inline fun predicate(block: FilterQueryPredicate.() -> Unit): String = +private suspend inline fun TestDsl.predicate(block: FilterQueryPredicate.() -> Unit): String = FilterQueryPredicate(testContext()) .apply(block) .toBson() .toString() @OptIn(LowLevelApi::class) -val PredicateExpressionTest by preparedSuite { +val PredicateExpressionTest by multiContextSuite { suite($$"Operator $eq") { test("Integer") { diff --git a/dsl/src/jvmTest/kotlin/query/ExpressionTestUtils.jvm.kt b/dsl/src/jvmTest/kotlin/query/ExpressionTestUtils.jvm.kt deleted file mode 100644 --- a/dsl/src/jvmTest/kotlin/query/ExpressionTestUtils.jvm.kt +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2024-2026, OpenSavvy and contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package opensavvy.ktmongo.dsl.query - -import opensavvy.ktmongo.bson.official.BsonFactory -import opensavvy.ktmongo.dsl.BsonContext -import org.bson.codecs.* -import org.bson.codecs.configuration.CodecRegistries -import org.bson.codecs.jsr310.InstantCodec -import org.bson.codecs.jsr310.LocalDateCodec -import org.bson.codecs.jsr310.LocalDateTimeCodec -import org.bson.codecs.jsr310.LocalTimeCodec -import org.bson.codecs.kotlin.DataClassCodecProvider -import kotlin.concurrent.atomics.ExperimentalAtomicApi -import kotlin.time.ExperimentalTime - -@OptIn(ExperimentalAtomicApi::class, ExperimentalTime::class) -actual fun testContext(): BsonContext = BsonContext( - bsonFactory = BsonFactory( - codecRegistry = CodecRegistries.fromProviders( - DataClassCodecProvider(), - CodecRegistries.fromCodecs( - AtomicBooleanCodec(), - AtomicIntegerCodec(), - AtomicLongCodec(), - BigDecimalCodec(), - BinaryCodec(), - BooleanCodec(), - BsonArrayCodec(), - BsonBinaryCodec(), - BsonBooleanCodec(), - BsonDateTimeCodec(), - BsonDBPointerCodec(), - BsonDecimal128Codec(), - BsonDocumentCodec(), - BsonDoubleCodec(), - BsonInt32Codec(), - BsonInt64Codec(), - BsonJavaScriptCodec(), - BsonMaxKeyCodec(), - BsonMinKeyCodec(), - BsonNullCodec(), - BsonObjectIdCodec(), - BsonRegularExpressionCodec(), - BsonStringCodec(), - BsonSymbolCodec(), - BsonTimestampCodec(), - BsonUndefinedCodec(), - BsonValueCodec(), - ByteArrayCodec(), - ByteCodec(), - CharacterCodec(), - CodeCodec(), - DateCodec(), - Decimal128Codec(), - DocumentCodec(), - DoubleCodec(), - FloatCodec(), - InstantCodec(), - IntegerCodec(), - JsonObjectCodec(), - LocalDateCodec(), - LocalDateTimeCodec(), - LocalTimeCodec(), - LongCodec(), - MaxKeyCodec(), - MinKeyCodec(), - ObjectIdCodec(), - OverridableUuidRepresentationUuidCodec(), - PatternCodec(), - RawBsonDocumentCodec(), - ShortCodec(), - StringCodec(), - SymbolCodec(), - UuidCodec(), - ) - ) - ) -) diff --git a/dsl/src/commonTest/kotlin/aggregation/operators/ArithmeticValueOperatorsTest.kt b/dsl/src/commonTest/kotlin/aggregation/operators/ArithmeticValueOperatorsTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/operators/ArithmeticValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/ArithmeticValueOperatorsTest.kt @@ -21,9 +21,9 @@ import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val ArithmeticValueOperatorsTest by preparedSuite { +val ArithmeticValueOperatorsTest by multiContextSuite { class Target( val score: Int, diff --git a/dsl/src/commonTest/kotlin/aggregation/operators/ArrayValueOperatorsTest.kt b/dsl/src/commonTest/kotlin/aggregation/operators/ArrayValueOperatorsTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/operators/ArrayValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/ArrayValueOperatorsTest.kt @@ -22,9 +22,9 @@ import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.Value import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val ArrayValueOperatorsTest by preparedSuite { +val ArrayValueOperatorsTest by multiContextSuite { class User( val name: String, diff --git a/dsl/src/commonTest/kotlin/aggregation/operators/ConditionalValueOperatorsTest.kt b/dsl/src/commonTest/kotlin/aggregation/operators/ConditionalValueOperatorsTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/operators/ConditionalValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/ConditionalValueOperatorsTest.kt @@ -21,9 +21,9 @@ import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val ConditionalValueOperatorsTest by preparedSuite { +val ConditionalValueOperatorsTest by multiContextSuite { class User( val name: String, diff --git a/dsl/src/commonTest/kotlin/aggregation/operators/StringValueOperatorsTest.kt b/dsl/src/commonTest/kotlin/aggregation/operators/StringValueOperatorsTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/operators/StringValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/StringValueOperatorsTest.kt @@ -21,9 +21,9 @@ import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val StringValueOperatorsTest by preparedSuite { +val StringValueOperatorsTest by multiContextSuite { class Target( val text: String, diff --git a/dsl/src/commonTest/kotlin/aggregation/operators/TrigonometryValueOperatorsTest.kt b/dsl/src/commonTest/kotlin/aggregation/operators/TrigonometryValueOperatorsTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/operators/TrigonometryValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/TrigonometryValueOperatorsTest.kt @@ -21,9 +21,9 @@ import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val TrigonometryValueOperatorsTest by preparedSuite { +val TrigonometryValueOperatorsTest by multiContextSuite { class Target( val a: Double, val b: Double, diff --git a/dsl/src/commonTest/kotlin/aggregation/operators/TypeValueOperatorsTest.kt b/dsl/src/commonTest/kotlin/aggregation/operators/TypeValueOperatorsTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/operators/TypeValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/TypeValueOperatorsTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,14 +23,14 @@ import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.path.Field -import opensavvy.prepared.runner.testballoon.preparedSuite import kotlin.time.ExperimentalTime import kotlin.time.Instant import kotlin.uuid.ExperimentalUuidApi import kotlin.uuid.Uuid -val TypeValueOperatorsTest by preparedSuite { +val TypeValueOperatorsTest by multiContextSuite { class Target( val name: String, diff --git a/dsl/src/commonTest/kotlin/aggregation/stages/CountTest.kt b/dsl/src/commonTest/kotlin/aggregation/stages/CountTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/stages/CountTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/stages/CountTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,9 @@ import opensavvy.ktmongo.dsl.aggregation.Pipeline import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val CountTest by preparedSuite { +val CountTest by multiContextSuite { class Score( val score: Int, diff --git a/dsl/src/commonTest/kotlin/aggregation/stages/GroupTest.kt b/dsl/src/commonTest/kotlin/aggregation/stages/GroupTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/stages/GroupTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/stages/GroupTest.kt @@ -22,9 +22,9 @@ import opensavvy.ktmongo.dsl.aggregation.Pipeline import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val GroupTest by preparedSuite { +val GroupTest by multiContextSuite { class Score( val score: Int, diff --git a/dsl/src/commonTest/kotlin/aggregation/stages/LimitTest.kt b/dsl/src/commonTest/kotlin/aggregation/stages/LimitTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/stages/LimitTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/stages/LimitTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,9 @@ import io.kotest.assertions.throwables.shouldThrow import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val LimitTest by preparedSuite{ +val LimitTest by multiContextSuite { test($$"Nominal $limit") { TestPipeline() diff --git a/dsl/src/commonTest/kotlin/aggregation/stages/MatchTest.kt b/dsl/src/commonTest/kotlin/aggregation/stages/MatchTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/stages/MatchTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/stages/MatchTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,9 @@ import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val MatchTest by preparedSuite { +val MatchTest by multiContextSuite { class Target( val foo: String, diff --git a/dsl/src/commonTest/kotlin/aggregation/stages/ProjectTest.kt b/dsl/src/commonTest/kotlin/aggregation/stages/ProjectTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/stages/ProjectTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/stages/ProjectTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,9 @@ import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val ProjectTest by preparedSuite { +val ProjectTest by multiContextSuite { class Target( val _id: String, diff --git a/dsl/src/commonTest/kotlin/aggregation/stages/SampleTest.kt b/dsl/src/commonTest/kotlin/aggregation/stages/SampleTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/stages/SampleTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/stages/SampleTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,9 @@ import io.kotest.assertions.throwables.shouldThrow import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val SampleTest by preparedSuite { +val SampleTest by multiContextSuite { test($$"$sample") { TestPipeline() diff --git a/dsl/src/commonTest/kotlin/aggregation/stages/SetTest.kt b/dsl/src/commonTest/kotlin/aggregation/stages/SetTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/stages/SetTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/stages/SetTest.kt @@ -18,9 +18,9 @@ import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val SetTest by preparedSuite { +val SetTest by multiContextSuite { class Target( val foo: String, diff --git a/dsl/src/commonTest/kotlin/aggregation/stages/SkipTest.kt b/dsl/src/commonTest/kotlin/aggregation/stages/SkipTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/stages/SkipTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/stages/SkipTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,9 @@ import io.kotest.assertions.throwables.shouldThrow import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val SkipTest by preparedSuite { +val SkipTest by multiContextSuite { test("Skip 5 elements") { TestPipeline() diff --git a/dsl/src/commonTest/kotlin/aggregation/stages/SortTest.kt b/dsl/src/commonTest/kotlin/aggregation/stages/SortTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/stages/SortTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/stages/SortTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,9 @@ import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val SortTest by preparedSuite { +val SortTest by multiContextSuite { class Target( val _id: String, diff --git a/dsl/src/commonTest/kotlin/aggregation/stages/UnsetTest.kt b/dsl/src/commonTest/kotlin/aggregation/stages/UnsetTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/stages/UnsetTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/stages/UnsetTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,9 @@ import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.aggregation.TestPipeline import opensavvy.ktmongo.dsl.aggregation.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite +import opensavvy.ktmongo.dsl.multiContextSuite -val UnsetTest by preparedSuite { +val UnsetTest by multiContextSuite { class Target( val _id: String, diff --git a/dsl/src/commonTest/kotlin/query/filter/ArrayFilterTest.kt b/dsl/src/commonTest/kotlin/query/filter/ArrayFilterTest.kt --- a/dsl/src/commonTest/kotlin/query/filter/ArrayFilterTest.kt +++ b/dsl/src/commonTest/kotlin/query/filter/ArrayFilterTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ package opensavvy.ktmongo.dsl.query.filter +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite -val ArrayFilterTest by preparedSuite { +val ArrayFilterTest by multiContextSuite { test("Test on an array element") { filter { User::grades.any eq 12 diff --git a/dsl/src/commonTest/kotlin/query/filter/BitwiseFilterTest.kt b/dsl/src/commonTest/kotlin/query/filter/BitwiseFilterTest.kt --- a/dsl/src/commonTest/kotlin/query/filter/BitwiseFilterTest.kt +++ b/dsl/src/commonTest/kotlin/query/filter/BitwiseFilterTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, OpenSavvy and contributors. + * Copyright (c) 2025-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,11 @@ package opensavvy.ktmongo.dsl.query.filter import opensavvy.ktmongo.bson.types.ObjectId +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite import kotlin.time.ExperimentalTime -val BitwiseFilterTest by preparedSuite { +val BitwiseFilterTest by multiContextSuite { suite($$"$bitsAllClear") { test("Int mask") { diff --git a/dsl/src/commonTest/kotlin/query/filter/ComparisonFilterTest.kt b/dsl/src/commonTest/kotlin/query/filter/ComparisonFilterTest.kt --- a/dsl/src/commonTest/kotlin/query/filter/ComparisonFilterTest.kt +++ b/dsl/src/commonTest/kotlin/query/filter/ComparisonFilterTest.kt @@ -16,10 +16,10 @@ package opensavvy.ktmongo.dsl.query.filter +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite -val ComparisonFilterTest by preparedSuite { +val ComparisonFilterTest by multiContextSuite { suite($$"Operator $eq") { test("Integer") { diff --git a/dsl/src/commonTest/kotlin/query/filter/ElementQueryFilterTest.kt b/dsl/src/commonTest/kotlin/query/filter/ElementQueryFilterTest.kt --- a/dsl/src/commonTest/kotlin/query/filter/ElementQueryFilterTest.kt +++ b/dsl/src/commonTest/kotlin/query/filter/ElementQueryFilterTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,10 @@ package opensavvy.ktmongo.dsl.query.filter import opensavvy.ktmongo.bson.BsonType +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite -val ElementQueryFilterTest by preparedSuite { +val ElementQueryFilterTest by multiContextSuite { suite($$"Operator $exists") { test("Exists") { diff --git a/dsl/src/commonTest/kotlin/query/filter/ExprFilterTest.kt b/dsl/src/commonTest/kotlin/query/filter/ExprFilterTest.kt --- a/dsl/src/commonTest/kotlin/query/filter/ExprFilterTest.kt +++ b/dsl/src/commonTest/kotlin/query/filter/ExprFilterTest.kt @@ -16,10 +16,10 @@ package opensavvy.ktmongo.dsl.query.filter +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite -val ExprFilterTest by preparedSuite { +val ExprFilterTest by multiContextSuite { test("Reading a field") { filter { expr { diff --git a/dsl/src/commonTest/kotlin/query/filter/FilterUtils.kt b/dsl/src/commonTest/kotlin/query/filter/FilterUtils.kt --- a/dsl/src/commonTest/kotlin/query/filter/FilterUtils.kt +++ b/dsl/src/commonTest/kotlin/query/filter/FilterUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,12 @@ package opensavvy.ktmongo.dsl.query.filter +import opensavvy.ktmongo.bson.types.ObjectId import opensavvy.ktmongo.dsl.KtMongoDsl import opensavvy.ktmongo.dsl.LowLevelApi import opensavvy.ktmongo.dsl.query.FilterQuery -import opensavvy.ktmongo.dsl.query.testContext -import org.bson.types.ObjectId +import opensavvy.ktmongo.dsl.testContext +import opensavvy.prepared.suite.TestDsl class Pet( val name: String, @@ -38,5 +39,5 @@ @OptIn(LowLevelApi::class) @KtMongoDsl -fun filter(block: FilterQuery.() -> Unit): String = +suspend fun TestDsl.filter(block: FilterQuery.() -> Unit): String = FilterQuery(testContext()).apply(block).toString() diff --git a/dsl/src/commonTest/kotlin/query/filter/LogicalFilterTest.kt b/dsl/src/commonTest/kotlin/query/filter/LogicalFilterTest.kt --- a/dsl/src/commonTest/kotlin/query/filter/LogicalFilterTest.kt +++ b/dsl/src/commonTest/kotlin/query/filter/LogicalFilterTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, OpenSavvy and contributors. + * Copyright (c) 2024-2026, OpenSavvy and contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,16 @@ * limitations under the License. */ +@file:OptIn(ExperimentalTime::class) + package opensavvy.ktmongo.dsl.query.filter +import opensavvy.ktmongo.bson.types.ObjectId +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite -import org.bson.types.ObjectId +import kotlin.time.ExperimentalTime -val LogicalFilterTest by preparedSuite { +val LogicalFilterTest by multiContextSuite { suite($$"Operators $and, $or, and $nor") { test("And") { filter { diff --git a/dsl/src/commonTest/kotlin/query/filter/RegexTest.kt b/dsl/src/commonTest/kotlin/query/filter/RegexTest.kt --- a/dsl/src/commonTest/kotlin/query/filter/RegexTest.kt +++ b/dsl/src/commonTest/kotlin/query/filter/RegexTest.kt @@ -16,8 +16,8 @@ package opensavvy.ktmongo.dsl.query.filter +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite /** * The examples [in the documentation](https://www.mongodb.com/docs/manual/reference/operator/query/regex/) use syntax: @@ -58,7 +58,7 @@ * However, this is misleading because it looks like a nested object, when it isn't, it's the JSON representation of the native type. * Copy-pasting this JSON request into a MongoDB editor will not work. */ -val RegexTest by preparedSuite { +val RegexTest by multiContextSuite { suite("Regex") { test("Basic usage") { filter { diff --git a/dsl/src/commonTest/kotlin/query/update/FieldUpdateTest.kt b/dsl/src/commonTest/kotlin/query/update/FieldUpdateTest.kt --- a/dsl/src/commonTest/kotlin/query/update/FieldUpdateTest.kt +++ b/dsl/src/commonTest/kotlin/query/update/FieldUpdateTest.kt @@ -18,11 +18,11 @@ package opensavvy.ktmongo.dsl.query.update +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.prepared.runner.testballoon.preparedSuite import kotlin.time.ExperimentalTime -val FieldUpdateTest by preparedSuite { +val FieldUpdateTest by multiContextSuite { suite($$"Operator $set") { test("Single field") { update { diff --git a/dsl/src/commonTest/kotlin/query/update/UpdateUtils.kt b/dsl/src/commonTest/kotlin/query/update/UpdateUtils.kt --- a/dsl/src/commonTest/kotlin/query/update/UpdateUtils.kt +++ b/dsl/src/commonTest/kotlin/query/update/UpdateUtils.kt @@ -19,15 +19,16 @@ package opensavvy.ktmongo.dsl.query.update import kotlinx.serialization.Serializable +import opensavvy.ktmongo.bson.types.ObjectId import opensavvy.ktmongo.bson.types.Timestamp import opensavvy.ktmongo.dsl.KtMongoDsl import opensavvy.ktmongo.dsl.LowLevelApi +import opensavvy.ktmongo.dsl.multiContextSuite import opensavvy.ktmongo.dsl.query.UpdateQuery import opensavvy.ktmongo.dsl.query.UpsertQuery import opensavvy.ktmongo.dsl.query.shouldBeBson -import opensavvy.ktmongo.dsl.query.testContext -import opensavvy.prepared.runner.testballoon.preparedSuite -import org.bson.types.ObjectId +import opensavvy.ktmongo.dsl.testContext +import opensavvy.prepared.suite.TestDsl import kotlin.time.ExperimentalTime import kotlin.time.Instant @@ -53,15 +54,15 @@ @OptIn(LowLevelApi::class) @KtMongoDsl -fun update(block: UpdateQuery.() -> Unit): String = +suspend fun TestDsl.update(block: UpdateQuery.() -> Unit): String = UpdateQuery(testContext()).apply(block).toString() @OptIn(LowLevelApi::class) @KtMongoDsl -fun upsert(block: UpsertQuery.() -> Unit): String = +suspend fun TestDsl.upsert(block: UpsertQuery.() -> Unit): String = UpsertQuery(testContext()).apply(block).toString() -val EmptyUpdateTest by preparedSuite { +val EmptyUpdateTest by multiContextSuite { test("Empty update") { update { } shouldBeBson "{}" } -- tangled.sh