Skip to content

Commit

Permalink
Add preprocessor test
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed Dec 23, 2024
1 parent 70a5719 commit 4f259ee
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up Linux
run: |
sudo apt-get -y install buildah
- name: Set up JDK
uses: actions/setup-java@v4
with:
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@
<version>3.26.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-jupiter</artifactId>
<version>2.1.7</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 4f259ee

Please sign in to comment.