LiberatorContainerExtension

class LiberatorContainerExtension(containerConfig: LiberatorContainerExtension.ContainerConfig = DefaultContainerConfig(), objectMapper: ObjectMapper = jacksonObjectMapper()) : MountableExtension<LiberatorContainerExtension.Config, LiberatorContainerExtension.Liberator> , AfterProjectListener, TestListener(source)

A Kotest MountableExtension that runs a Caplin Liberator inside a Testcontainers container for the duration of a test project.

Mount it on a spec to obtain a Liberator handle, which exposes the mapped ports and a factory for opening authenticated StreamLink connections. The container is started lazily on first mount and stopped once via afterProject when the project completes.

class MySpec : FunSpec({
val liberator = install(LiberatorContainerExtension())
test("...") {
val connection = liberator.connect("alice")
autoClose(connection)
// ...
}
})

Parameters

containerConfig

how the container is built and how clients authenticate against it. Defaults to a DefaultContainerConfig that builds a Liberator image with a generated KeyMaster key pair. Supply a CustomContainerConfig to run against a pre-built container.

objectMapper

Jackson mapper used when (de)serialising messages over the connection.

Constructors

Link copied to clipboard
constructor(containerConfig: LiberatorContainerExtension.ContainerConfig = DefaultContainerConfig(), objectMapper: ObjectMapper = jacksonObjectMapper())

Types

Link copied to clipboard
class Config

Configuration receiver passed to mount; currently exposes no options.

Link copied to clipboard
sealed interface ContainerConfig

Describes the container to run and how StreamLink clients authenticate against it.

Link copied to clipboard
class CustomContainerConfig(val keymasterConfiguration: IKeyMasterConfiguration, val httpPort: Int, val dataSourcePort: Int, val container: GenericContainer<*>) : LiberatorContainerExtension.ContainerConfig

A ContainerConfig for running against a container and KeyMaster configuration you supply yourself, rather than the one built by DefaultContainerConfig.

Link copied to clipboard
class DefaultContainerConfig(val adapterConfig: InputStream? = null, val beforeScript: InputStream? = null, val extraFiles: Map<String, InputStream> = mutableMapOf(), val baseImage: String = DEFAULT_BASE_IMAGE) : LiberatorContainerExtension.ContainerConfig

A ContainerConfig that builds a Liberator image from the bundled Dockerfile and generates a fresh RSA KeyMaster key pair, deploying the public key into the container.

Link copied to clipboard
class Liberator(val streamLinkConnectionFactory: StreamLinkConnectionFactory, val dataSourcePort: Int, val httpPort: Int, val containerState: ContainerState)

A handle to a running Liberator container, returned when the extension is mounted.

Functions

Link copied to clipboard
open suspend fun afterAny(testCase: TestCase, result: TestResult)
Link copied to clipboard
open suspend fun afterContainer(testCase: TestCase, result: TestResult)
Link copied to clipboard
open suspend fun afterEach(testCase: TestCase, result: TestResult)
Link copied to clipboard
open suspend fun afterInvocation(testCase: TestCase, iteration: Int)
Link copied to clipboard
open suspend override fun afterProject()

Stops the container once the test project has finished.

Link copied to clipboard
open suspend fun afterSpec(spec: Spec)
Link copied to clipboard
open suspend fun afterTest(testCase: TestCase, result: TestResult)
Link copied to clipboard
open suspend fun beforeAny(testCase: TestCase)
Link copied to clipboard
open suspend fun beforeContainer(testCase: TestCase)
Link copied to clipboard
open suspend fun beforeEach(testCase: TestCase)
Link copied to clipboard
open suspend fun beforeInvocation(testCase: TestCase, iteration: Int)
Link copied to clipboard
open suspend fun beforeSpec(spec: Spec)
Link copied to clipboard
open suspend fun beforeTest(testCase: TestCase)
Link copied to clipboard
open suspend fun finalizeSpec(kclass: KClass<out Spec>, results: Map<TestCase, TestResult>)
Link copied to clipboard

Starts the container (if not already running) and returns a Liberator handle.

Link copied to clipboard
open suspend fun prepareSpec(kclass: KClass<out Spec>)