Test

Documentation is pending since the API is still developing, for an introduction please see this post Infrastructure testing with Solidblocks

Usage

To use solidblocks-test just add the dependency to your Gradle build



plugins {
    id("org.jetbrains.kotlin.jvm") version "1.9.22"
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.junit.jupiter:junit-jupiter-api:5.11.0")
    implementation("org.junit.jupiter:junit-jupiter-engine:5.11.0")
    implementation("de.solidblocks:infra-test:0.2.9")
}

tasks.named<Test>("test") {
    useJUnitPlatform()
}

And extend your test classes with SolidblocksTest to get the SolidblocksTestContext



package solidblocks.test.gradle

import de.solidblocks.infra.test.SolidblocksTest
import de.solidblocks.infra.test.SolidblocksTestContext
import de.solidblocks.infra.test.command.shouldHaveExitCode
import de.solidblocks.infra.test.docker.DockerTestImage
import de.solidblocks.infra.test.output.outputShouldMatch
import de.solidblocks.infra.test.output.stderrShouldBeEmpty
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith

@ExtendWith(SolidblocksTest::class)
class CommandTest {

    @Test
    fun localCommand(testContext: SolidblocksTestContext) {
        val currentUserName = System.getProperty("user.name")
        val result = testContext.local().command("whoami").runResult()

        result shouldHaveExitCode 0
        result outputShouldMatch (".*$currentUserName.*")
        result.stderrShouldBeEmpty()
    }


    @Test
    fun dockerCommand(testContext: SolidblocksTestContext) {
        val result = testContext.docker(DockerTestImage.UBUNTU_22).command("whoami").runResult()

        result shouldHaveExitCode 0
        result outputShouldMatch (".*root.*")
        result.stderrShouldBeEmpty()
    }

}