diff --git a/dsl/build.gradle.kts b/dsl/build.gradle.kts index 53a48af4..e156b3c9 100644 --- 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 @@ plugins { 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 index 00000000..3a932ba4 --- /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 index 00000000..3ed2084f --- /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/commonTest/kotlin/aggregation/AggregationStageTest.kt b/dsl/src/commonTest/kotlin/aggregation/AggregationStageTest.kt index 99d36f03..0434556b 100644 --- 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 index 63909ba2..933fa9f3 100644 --- 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 @@ -52,6 +56,9 @@ class TestPipeline( } +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 index 2ebeee3e..400ef0c1 100644 --- a/dsl/src/commonTest/kotlin/aggregation/ValueTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/ValueTest.kt @@ -18,19 +18,16 @@ package opensavvy.ktmongo.dsl.aggregation 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 ValueTest by preparedSuite { 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/aggregation/operators/ArithmeticValueOperatorsTest.kt b/dsl/src/commonTest/kotlin/aggregation/operators/ArithmeticValueOperatorsTest.kt index 7d63919b..1bc983a8 100644 --- a/dsl/src/commonTest/kotlin/aggregation/operators/ArithmeticValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/ArithmeticValueOperatorsTest.kt @@ -21,9 +21,9 @@ package opensavvy.ktmongo.dsl.aggregation.operators 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 index 135acb54..11934ebf 100644 --- 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.LowLevelApi 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 index ae3fa18c..9aaf21a5 100644 --- a/dsl/src/commonTest/kotlin/aggregation/operators/ConditionalValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/ConditionalValueOperatorsTest.kt @@ -21,9 +21,9 @@ package opensavvy.ktmongo.dsl.aggregation.operators 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 index 416ec80d..a46925ae 100644 --- a/dsl/src/commonTest/kotlin/aggregation/operators/StringValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/StringValueOperatorsTest.kt @@ -21,9 +21,9 @@ package opensavvy.ktmongo.dsl.aggregation.operators 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 index db90b7f2..8222224f 100644 --- a/dsl/src/commonTest/kotlin/aggregation/operators/TrigonometryValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/TrigonometryValueOperatorsTest.kt @@ -21,9 +21,9 @@ package opensavvy.ktmongo.dsl.aggregation.operators 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 index 3aa61e3b..ba437888 100644 --- 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.bson.types.ObjectId 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 index ffa3b294..da422996 100644 --- 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 @@ package opensavvy.ktmongo.dsl.aggregation.stages 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 index 8538c35f..e1734161 100644 --- 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.LowLevelApi 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 index 07410dc2..0e307fed 100644 --- 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 @@ package opensavvy.ktmongo.dsl.aggregation.stages 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 index e417d98d..609cde16 100644 --- 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 @@ package opensavvy.ktmongo.dsl.aggregation.stages 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 index 1e2c3770..d94905dc 100644 --- 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 @@ package opensavvy.ktmongo.dsl.aggregation.stages 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 index 788e72ad..aa5e1dd5 100644 --- 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 @@ package opensavvy.ktmongo.dsl.aggregation.stages 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 index 1972bbe7..760d1d16 100644 --- a/dsl/src/commonTest/kotlin/aggregation/stages/SetTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/stages/SetTest.kt @@ -18,9 +18,9 @@ package opensavvy.ktmongo.dsl.aggregation.stages 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 index 93ff8d00..27044054 100644 --- 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 @@ package opensavvy.ktmongo.dsl.aggregation.stages 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 index a413d64c..8fd7453d 100644 --- 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 @@ package opensavvy.ktmongo.dsl.aggregation.stages 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 index 1fef5981..73965339 100644 --- 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 @@ package opensavvy.ktmongo.dsl.aggregation.stages 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/command/BulkWriteTest.kt b/dsl/src/commonTest/kotlin/command/BulkWriteTest.kt index a34226c3..b6f78271 100644 --- 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 index 7e7bfcf3..24d66d11 100644 --- 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 index 7f159404..cda10abe 100644 --- 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 index 0b255fb9..6b45432d 100644 --- 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 index 5f14cee1..41389143 100644 --- 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 index ffbbf7e6..1e0050b9 100644 --- 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 InsertTest by preparedSuite { 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 index 85fc89a0..fb642560 100644 --- 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 index edacd319..e2888e79 100644 --- 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 index d4ff070a..97eeb634 100644 --- 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 @@ package opensavvy.ktmongo.dsl.options 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 index 57f65c7d..13a0d25d 100644 --- 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 @@ package opensavvy.ktmongo.dsl.options 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 index bc493164..d5bcd480 100644 --- 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 @@ package opensavvy.ktmongo.dsl.options 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 index f8f0c5a4..52d61197 100644 --- a/dsl/src/commonTest/kotlin/path/BsonPathConversionsTest.kt +++ b/dsl/src/commonTest/kotlin/path/BsonPathConversionsTest.kt @@ -20,13 +20,13 @@ package opensavvy.ktmongo.dsl.path 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 index c8564f4a..f2cd045f 100644 --- 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 index 44363c0f..b7f8aac8 100644 --- 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 index 6731aeaa..a5b46432 100644 --- 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,12 +16,9 @@ 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 .replace("\n", "") diff --git a/dsl/src/commonTest/kotlin/query/PredicateExpressionTest.kt b/dsl/src/commonTest/kotlin/query/PredicateExpressionTest.kt index 4407202d..8de2b506 100644 --- 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/commonTest/kotlin/query/filter/ArrayFilterTest.kt b/dsl/src/commonTest/kotlin/query/filter/ArrayFilterTest.kt index 960ab24c..f9b9ba15 100644 --- 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 index 27b5e664..eb8d78cf 100644 --- 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 index 445f0592..4c69167b 100644 --- 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 index 374a6477..13eb2426 100644 --- 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 index 7eddd403..79491e55 100644 --- 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 index 52d38849..5102735c 100644 --- 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 @@ class User( @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 index eec84f2a..e144ca6d 100644 --- 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 index 352edd86..211b61d0 100644 --- 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 @@ import opensavvy.prepared.runner.testballoon.preparedSuite * 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 index b20538f4..e15ee044 100644 --- 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 index c8d24858..f4c4e02e 100644 --- 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 @@ class User( @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 "{}" } diff --git a/dsl/src/jvmTest/kotlin/query/ExpressionTestUtils.jvm.kt b/dsl/src/jvmTest/kotlin/MultiContext.jvm.kt similarity index 77% rename from dsl/src/jvmTest/kotlin/query/ExpressionTestUtils.jvm.kt rename to dsl/src/jvmTest/kotlin/MultiContext.jvm.kt index 0ac1804a..910cfdb7 100644 --- a/dsl/src/jvmTest/kotlin/query/ExpressionTestUtils.jvm.kt +++ b/dsl/src/jvmTest/kotlin/MultiContext.jvm.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2026, 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. @@ -14,26 +14,20 @@ * limitations under the License. */ -package opensavvy.ktmongo.dsl.query +package opensavvy.ktmongo.dsl -import opensavvy.ktmongo.bson.official.BsonFactory -import opensavvy.ktmongo.dsl.BsonContext +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 -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( +actual val testFactories: Map BsonFactory> = mapOf( + "JVM Official" to { + opensavvy.ktmongo.bson.official.BsonFactory( + codecRegistry = CodecRegistries.fromCodecs( AtomicBooleanCodec(), AtomicIntegerCodec(), AtomicLongCodec(), @@ -89,5 +83,5 @@ actual fun testContext(): BsonContext = BsonContext( UuidCodec(), ) ) - ) + }, ) diff --git a/dsl/src/jvmTest/kotlin/Marker.kt b/dsl/src/nativeTest/kotlin/MultiContext.native.kt similarity index 69% rename from dsl/src/jvmTest/kotlin/Marker.kt rename to dsl/src/nativeTest/kotlin/MultiContext.native.kt index 78149a84..03cbd0af 100644 --- a/dsl/src/jvmTest/kotlin/Marker.kt +++ b/dsl/src/nativeTest/kotlin/MultiContext.native.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, 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. @@ -15,3 +15,8 @@ */ 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 index 00000000..03cbd0af --- /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 index 00000000..03cbd0af --- /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()