KMongoTestServer

MongoDB server shared by all the tests of a JVM - the KMongo DSL replacement of kmongo-flapdoodle.

  • if the kmongo.test.mongodb.uri system property (or the KMONGO_TEST_MONGODB_URI environment variable) is set, this server is used

  • else a MongoDB container (a single node replica set: transactions and change streams are available) is started with Testcontainers at the first use, and stopped at the JVM shutdown. The image can be set with the kmongo.test.mongodb.image system property (default DEFAULT_IMAGE).

Sample:

val client = KMongo.createClient(KMongoTestServer.connectionString)
val database = client.getDatabase(KMongoTestServer.newDatabaseName())

Properties

Link copied to clipboard

The connection string of the test server (the container is started at the first call).

Link copied to clipboard

The default MongoDB image.

Link copied to clipboard

The system property of the MongoDB image.

Link copied to clipboard
const val URI_ENV: String

The environment variable of the external MongoDB server uri.

Link copied to clipboard
const val URI_PROPERTY: String

The system property of the external MongoDB server uri.

Functions

Link copied to clipboard
fun newDatabaseName(prefix: String = "test"): String

Returns a new database name (test_1, test_2...), to isolate the tests sharing the same server.