diff --git a/pom.xml b/pom.xml index 075f5c8..f3a8346 100644 --- a/pom.xml +++ b/pom.xml @@ -138,6 +138,12 @@ 3.26.3 test + + uk.org.webcompere + system-stubs-jupiter + 2.1.7 + test + diff --git a/src/test/java/org/jboss/pnc/konfluxtooling/prebuild/PreprocessorTest.java b/src/test/java/org/jboss/pnc/konfluxtooling/prebuild/PreprocessorTest.java new file mode 100644 index 0000000..5fce9aa --- /dev/null +++ b/src/test/java/org/jboss/pnc/konfluxtooling/prebuild/PreprocessorTest.java @@ -0,0 +1,53 @@ +package org.jboss.pnc.konfluxtooling.prebuild; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; + +import io.quarkus.test.junit.QuarkusTest; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; + +@ExtendWith(SystemStubsExtension.class) +@QuarkusTest +public class PreprocessorTest { + + { + System.setProperty("org.slf4j.simpleLogger.log.com.github.dockerjava.api.command.BuildImageResultCallback", "debug"); + } + + @SystemStub + private EnvironmentVariables variables = new EnvironmentVariables("BUILD_SCRIPT", """ + echo 'BUILDING!'"""); + + @Test + public void testGenerate(@TempDir Path tempDir) throws IOException, InterruptedException { + + Preprocessor preprocessor = new Preprocessor(); + preprocessor.type = Preprocessor.ToolType.ANT; + preprocessor.recipeImage = "quay.io/redhat-user-workloads/konflux-jbs-pnc-tenant/jvm-build-service-builder-images/ubi7:latest"; + preprocessor.buildRequestProcessorImage = "quay.io/redhat-user-workloads/konflux-jbs-pnc-tenant/konflux-tooling:latest"; + preprocessor.buildRoot = tempDir; + preprocessor.javaVersion = "7"; + preprocessor.buildToolVersion = "1.9.16"; + + preprocessor.run(); + + Process process = new ProcessBuilder("buildah", "build", "-f", tempDir.toString() + "/.jbs/Containerfile", ".") + .directory(tempDir.toFile()).redirectErrorStream(true).start(); + + String text = new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8); + + assertTrue(text.contains("BUILDING!")); + assertTrue(text.contains("Listening on: http://0.0.0.0:8084")); + assertEquals(0, process.waitFor()); + } +}