Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
*/
public abstract class KubernetesBaseCommand extends CamelCommand {

static final String RUN_PLATFORM_DIR = ".camel-jbang-run";

@CommandLine.Option(names = { "--kube-config" },
description = "Path to the kube config file to initialize Kubernetes client")
String kubeConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,12 @@ public Integer doCall() throws Exception {
return 0;
}

String getRunPlatformDir() {
return ".camel-jbang-run";
}

private String getIndexedWorkingDir(String projectName) {
var workingDir = RUN_PLATFORM_DIR + File.separator + projectName;
var workingDir = getRunPlatformDir() + File.separator + projectName;
if (devModeReloadCount > 0) {
workingDir += "-%03d".formatted(devModeReloadCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.camel.dsl.jbang.core.commands.kubernetes;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
Expand All @@ -32,6 +33,7 @@
import org.apache.camel.dsl.jbang.core.common.PluginType;
import org.apache.camel.dsl.jbang.core.common.StringPrinter;
import org.apache.camel.test.infra.common.services.ContainerEnvironmentUtil;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.StringHelper;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -41,6 +43,8 @@
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class KubernetesBaseTestSupport {

protected final String runPlatformDir = "target/tests/" + getClass().getSimpleName();

private KubernetesMockServer k8sServer;
protected KubernetesClient kubernetesClient;
protected StringPrinter printer;
Expand Down Expand Up @@ -70,6 +74,7 @@ public void setup() {
@AfterAll
public void cleanup() {
k8sServer.destroy();
FileUtil.removeDir(new File(runPlatformDir));
}

protected static InputStream getKubernetesManifestAsStream(String printerOutput) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.ContainerTrait;
import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
import org.apache.camel.dsl.jbang.core.common.StringPrinter;
import org.apache.camel.dsl.jbang.core.common.VersionHelper;
import org.apache.camel.util.FileUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -64,12 +67,20 @@
@EnableKubernetesMockClient
class KubernetesRunCustomTest {

final String runPlatformDir = "target/tests/" + getClass().getSimpleName();

protected KubernetesMockServer server;
protected KubernetesClient client;
protected StringPrinter printer;

@AfterEach
void cleanupWorkDirs() {
FileUtil.removeDir(new File(runPlatformDir));
}

@BeforeEach
public void setup() {
CommandLineHelper.useHomeDir("target");
// Set Camel version with system property value, usually set via Maven surefire plugin
// In case you run this test via local Java IDE you need to provide the system property or a default value here
VersionHelper.setCamelVersion(System.getProperty("camel.version", ""));
Expand Down Expand Up @@ -125,7 +136,7 @@ public void runWithProperties() throws Exception {
Assertions.assertEquals(0, exit, printer.getOutput());

Properties materializedProps = new Properties();
String propsFilepath = ".camel-jbang-run/my-route-props/src/main/resources/application.properties";
String propsFilepath = runPlatformDir + "/my-route-props/src/main/resources/application.properties";
Assertions.assertTrue(new File(propsFilepath).exists());
try (FileInputStream input = new FileInputStream(new File(propsFilepath))) {
materializedProps.load(input);
Expand Down Expand Up @@ -291,7 +302,12 @@ private KubernetesRun createCommand(List<String> files, String... args) {
var argsArr = Optional.ofNullable(args).orElse(new String[0]);
var argsLst = new ArrayList<>(Arrays.asList(argsArr));
var jbangMain = new CamelJBangMain().withPrinter(printer);
KubernetesRun command = new KubernetesRun(jbangMain, files);
KubernetesRun command = new KubernetesRun(jbangMain, files) {
@Override
String getRunPlatformDir() {
return runPlatformDir;
}
};
CommandLine.populateCommand(command, argsLst.toArray(new String[0]));
command.imageBuild = false;
command.imagePush = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void verifyProperties() throws Exception {
Assertions.assertEquals(0, exit);

Properties materializedProps = new Properties();
String propsFilepath = ".camel-jbang-run/my-route-props/src/main/resources/application.properties";
String propsFilepath = runPlatformDir + "/my-route-props/src/main/resources/application.properties";
try (FileInputStream input = new FileInputStream(new File(propsFilepath))) {
materializedProps.load(input);
}
Expand Down Expand Up @@ -240,7 +240,12 @@ private KubernetesRun createCommand(List<String> files, String... args) {
var argsArr = Optional.ofNullable(args).orElse(new String[0]);
var argsLst = new ArrayList<>(Arrays.asList(argsArr));
var jbangMain = new CamelJBangMain().withPrinter(printer);
KubernetesRun command = new KubernetesRun(jbangMain, files);
KubernetesRun command = new KubernetesRun(jbangMain, files) {
@Override
String getRunPlatformDir() {
return runPlatformDir;
}
};
CommandLine.populateCommand(command, argsLst.toArray(new String[0]));
command.imageBuild = false;
command.imagePush = false;
Expand Down
Loading