Skip to content

Commit

Permalink
Added updateCommandEnvsToShStyle() method to make visible envs in "oc…
Browse files Browse the repository at this point in the history
… exec"

Signed-off-by: mdolhalo <mdolhalo@redhat.com>
  • Loading branch information
mdolhalo authored and nallikaea committed Jun 1, 2023
1 parent 0185643 commit e7cb474
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test-docker": "npm run cleanup-docker && docker run -it --shm-size=2g -p 5920:5920 --name selenium-e2e -e TS_SELENIUM_BASE_URL=$TS_SELENIUM_BASE_URL eclipse/che-e2e:nightly",
"test-docker-mount-e2e": "npm run cleanup-docker && docker run -it --shm-size=2g -p 5920:5920 --name selenium-e2e -e TS_SELENIUM_BASE_URL=$TS_SELENIUM_BASE_URL -v $(pwd):/tmp/e2e:Z eclipse/che-e2e:nightly",
"test-all-devfiles": " ./configs/sh-scripts/initDefaultValues.sh && ./configs/sh-scripts/initDevfileTests.sh",
"run-devfile-acceptance-test-suite": "./configs/sh-scripts/initDefaultValues.sh npm run lint && npm run tsc && export TS_USE_WEB_DRIVER_FOR_TEST=false && mocha 'dist/specs/api/*.js' --config dist/configs/mocharc.js --delay --grep 'Devfile acceptance test suite'"
"devfile-acceptance-test-suite": "./configs/sh-scripts/initDefaultValues.sh npm run lint && npm run tsc && export TS_USE_WEB_DRIVER_FOR_TEST=false && mocha 'dist/specs/api/*.js' --config dist/configs/mocharc.js --delay --grep 'Devfile acceptance test suite'"
},
"author": "Ihor Okhrimenko (iokhrime@redhat.com)",
"license": "ISC",
Expand Down
10 changes: 3 additions & 7 deletions tests/e2e/specs/api/DevfileAcceptanceTestAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { Logger } from '../../utils/Logger';
Logger.info(`Devfile does not contains any commands.`);
} else {
devfileContext.devfile.commands.forEach((command: any) => {
if (command.exec.group.kind === 'build') {
if (command.exec?.group?.kind === 'build') {
Logger.debug(`Build command found: ${command.exec.commandLine}`);
devfilesBuildCommands.push(command);
}
Expand Down Expand Up @@ -84,14 +84,10 @@ import { Logger } from '../../utils/Logger';
if (devfilesBuildCommands.length === 0) {
Logger.info(`Devfile does not contains build commands.`);
} else {
let workingDir: string;
devfilesBuildCommands.forEach((command) => {
Logger.info(`command.exec.commandLine: ${command.exec.commandLine}`);
Logger.info(`command.exec.component: ${command.exec.component}`);
Logger.info(`command.exec.workingDir: ${command.exec.workingDir}`);
Logger.info(`command.exec: ${JSON.stringify(command.exec)}`);

workingDir = StringUtil.getFullWorkingDirPathExplicit(command.exec.workingDir, containerTerminal);
const commandString: string = `cd ${workingDir} && ${command.exec.commandLine}`;
const commandString: string = StringUtil.updateCommandEnvsToShStyle(`cd ${command.exec.workingDir} && ${command.exec.commandLine}`);
Logger.info(`Full build command to be executed: ${commandString}`);

const output: ShellString = containerTerminal.executeCommand(commandString, command.exec.component);
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class KubernetesCommandLineToolsExecutor extends ShellExecutor {

executeCommand(commandToExecute: string, container: string = KubernetesCommandLineToolsExecutor.container): ShellString {
Logger.debug(`${this.getLoggingName(this.executeCommand.name)}:`);
return ShellExecutor.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} exec -i ${KubernetesCommandLineToolsExecutor.pod} -n ${this.namespace} -c ${container} -- sh -c "${commandToExecute}"`);
return ShellExecutor.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} exec -i ${KubernetesCommandLineToolsExecutor.pod} -n ${this.namespace} -c ${container} -- sh -c '${commandToExecute}'`);
}

applyYamlConfigurationAsStringOutput(yamlConfiguration: string): ShellString {
Expand Down
32 changes: 9 additions & 23 deletions tests/e2e/utils/StringUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,17 @@ export class StringUtil {
return projectName;
}

static sanitizeTitle(arg: string): string {
return arg.replace(/\//g, '+').replace(/,/g, '.').replace(/:/g, '-').replace(/['"]/g, '').replace(/[^a-z0-9+\-.()\[\]_]/gi, '_');
}

/**
* Uses in DevfileAcceptanceTestAPI.spec.ts to get full path to execute build command without unknown environmental variable
* @param pathWithUnknownEnvVariable command.exec.workingDir from devfileContext.devfile
* @param containerTerminal instance of KubernetesCommandLineToolsExecutor.ContainerTerminal
* @return full path of imported project working dir in workspace
* Replaces ${ENV}, $ENV to "$ENV"
* @param command string command with environmental variables in unsupported format
* @return updated command with environmental variables in supported format
*/
static getFullWorkingDirPathExplicit(pathWithUnknownEnvVariable: string, containerTerminal: KubernetesCommandLineToolsExecutor.ContainerTerminal): string {
const envVariable: { name: string; value: string } = {
name: '',
value: ''
};

envVariable.name = pathWithUnknownEnvVariable.substring(
pathWithUnknownEnvVariable.indexOf('{') + 1,
pathWithUnknownEnvVariable.lastIndexOf('}'));

if (pathWithUnknownEnvVariable.includes('/')) {
pathWithUnknownEnvVariable = pathWithUnknownEnvVariable.substring(pathWithUnknownEnvVariable.indexOf('/'));
}

envVariable.value = containerTerminal.getEnvValue(envVariable.name);
return envVariable.value + pathWithUnknownEnvVariable;
}

static sanitizeTitle(arg: string): string {
return arg.replace(/\//g, '+').replace(/,/g, '.').replace(/:/g, '-').replace(/['"]/g, '').replace(/[^a-z0-9+\-.()\[\]_]/gi, '_');
static updateCommandEnvsToShStyle(command: string): string {
return command.replace(/[{}]/g, '').replace(/(?<!")\${?[a-zA-Z0-9_+\-\s]+\b}?/gm, `"\$&"`);
}
}

0 comments on commit e7cb474

Please sign in to comment.