Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QuarkusDevFileAPI and LombokDevFileAPI tests #23295

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
12 changes: 6 additions & 6 deletions tests/e2e/specs/api/CppDevFileAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ suite('Cpp devfile API test', function (): void {
let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper;
let devfileContext: DevfileContext;
let devfileContent: string = '';
let dwtName: string = '';
let devfileName: string = '';
const workDirPath: string = 'c-plus-plus/strings';
const fileName: string = 'knuth_morris_pratt.cpp';
const tasksJsonPath: string = 'c-plus-plus/.vscode/tasks.json';
Expand All @@ -46,17 +46,17 @@ suite('Cpp devfile API test', function (): void {
kubernetesCommandLineToolsExecutor.namespace = API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE || 'admin-devspaces';
devfileContent = devfilesRegistryHelper.getDevfileContent(devfileID);
const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditorFromCheConfigMap('editors-definitions');
dwtName = YAML.parse(devfileContent).metadata.name;
const uniqName: string = YAML.parse(devfileContent).metadata.name + randomPref;
kubernetesCommandLineToolsExecutor.workspaceName = uniqName;
devfileName = YAML.parse(devfileContent).metadata.name;
const uniqueName: string = YAML.parse(devfileContent).metadata.name + randomPref;
kubernetesCommandLineToolsExecutor.workspaceName = uniqueName;

devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({
editorContent: editorDevfileContent,
devfileContent: devfileContent
});
devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext();
if (devfileContext.devWorkspace.metadata) {
devfileContext.devWorkspace.metadata.name = uniqName;
devfileContext.devWorkspace.metadata.name = uniqueName;
}
const devWorkspaceConfigurationYamlString: string =
devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext);
Expand Down Expand Up @@ -92,6 +92,6 @@ suite('Cpp devfile API test', function (): void {
});

suiteTeardown('Delete workspace', function (): void {
kubernetesCommandLineToolsExecutor.deleteDevWorkspace(dwtName);
kubernetesCommandLineToolsExecutor.deleteDevWorkspace(devfileName);
});
});
12 changes: 6 additions & 6 deletions tests/e2e/specs/api/DotnetDevFileAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ suite('Dotnet devfile API test', function (): void {
let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper;
let devfileContext: DevfileContext;
let devfileContent: string = '';
let dwtName: string = '';
let devfileName: string = '';

suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp();
Expand All @@ -42,17 +42,17 @@ suite('Dotnet devfile API test', function (): void {
kubernetesCommandLineToolsExecutor.namespace = API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE || 'admin-devspaces';
devfileContent = devfilesRegistryHelper.getDevfileContent(devfileID);
const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditorFromCheConfigMap('editors-definitions');
dwtName = YAML.parse(devfileContent).metadata.name;
const uniqName: string = YAML.parse(devfileContent).metadata.name + randomPref;
kubernetesCommandLineToolsExecutor.workspaceName = uniqName;
devfileName = YAML.parse(devfileContent).metadata.name;
const uniqueName: string = YAML.parse(devfileContent).metadata.name + randomPref;
kubernetesCommandLineToolsExecutor.workspaceName = uniqueName;

devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({
editorContent: editorDevfileContent,
devfileContent: devfileContent
});
devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext();
if (devfileContext.devWorkspace.metadata) {
devfileContext.devWorkspace.metadata.name = uniqName;
devfileContext.devWorkspace.metadata.name = uniqueName;
}
const devWorkspaceConfigurationYamlString: string =
devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext);
Expand Down Expand Up @@ -94,6 +94,6 @@ suite('Dotnet devfile API test', function (): void {
});

suiteTeardown('Delete DevWorkspace', function (): void {
kubernetesCommandLineToolsExecutor.deleteDevWorkspace(dwtName);
kubernetesCommandLineToolsExecutor.deleteDevWorkspace(devfileName);
});
});
12 changes: 6 additions & 6 deletions tests/e2e/specs/api/GoDevFileAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ suite('Go devfile API test', function (): void {
let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper;
let devfileContext: DevfileContext;
let devfileContent: string = '';
let dwtName: string = '';
let devfileName: string = '';

suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp();
Expand All @@ -43,17 +43,17 @@ suite('Go devfile API test', function (): void {
kubernetesCommandLineToolsExecutor.namespace = API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE || 'admin-devspaces';
devfileContent = devfilesRegistryHelper.getDevfileContent(devfileID);
const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditorFromCheConfigMap('editors-definitions');
dwtName = YAML.parse(devfileContent).metadata.name;
const uniqName: string = YAML.parse(devfileContent).metadata.name + randomPref;
kubernetesCommandLineToolsExecutor.workspaceName = uniqName;
devfileName = YAML.parse(devfileContent).metadata.name;
const uniqueName: string = YAML.parse(devfileContent).metadata.name + randomPref;
kubernetesCommandLineToolsExecutor.workspaceName = uniqueName;

devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({
editorContent: editorDevfileContent,
devfileContent: devfileContent
});
devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext();
if (devfileContext.devWorkspace.metadata) {
devfileContext.devWorkspace.metadata.name = uniqName;
devfileContext.devWorkspace.metadata.name = uniqueName;
}
const devWorkspaceConfigurationYamlString: string =
devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext);
Expand Down Expand Up @@ -87,6 +87,6 @@ suite('Go devfile API test', function (): void {
});

suiteTeardown('Delete DevWorkspace', function (): void {
kubernetesCommandLineToolsExecutor.deleteDevWorkspace(dwtName);
kubernetesCommandLineToolsExecutor.deleteDevWorkspace(devfileName);
});
});
12 changes: 6 additions & 6 deletions tests/e2e/specs/api/PhpDevFileAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ suite('PHP devfile API test', function (): void {
let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper;
let devfileContext: DevfileContext;
let devfileContent: string = '';
let dwtName: string = '';
let devfileName: string = '';

suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp();
Expand All @@ -42,17 +42,17 @@ suite('PHP devfile API test', function (): void {
kubernetesCommandLineToolsExecutor.namespace = API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE || 'admin-devspaces';
devfileContent = devfilesRegistryHelper.getDevfileContent(devfileID);
const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditorFromCheConfigMap('editors-definitions');
dwtName = YAML.parse(devfileContent).metadata.name;
const uniqName: string = YAML.parse(devfileContent).metadata.name + randomPref;
kubernetesCommandLineToolsExecutor.workspaceName = uniqName;
devfileName = YAML.parse(devfileContent).metadata.name;
const uniqueName: string = YAML.parse(devfileContent).metadata.name + randomPref;
kubernetesCommandLineToolsExecutor.workspaceName = uniqueName;

devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({
editorContent: editorDevfileContent,
devfileContent: devfileContent
});
devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext();
if (devfileContext.devWorkspace.metadata) {
devfileContext.devWorkspace.metadata.name = uniqName;
devfileContext.devWorkspace.metadata.name = uniqueName;
}
const devWorkspaceConfigurationYamlString: string =
devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext);
Expand All @@ -73,6 +73,6 @@ suite('PHP devfile API test', function (): void {
});

suiteTeardown('Delete DevWorkspace', function (): void {
kubernetesCommandLineToolsExecutor.deleteDevWorkspace(dwtName);
kubernetesCommandLineToolsExecutor.deleteDevWorkspace(devfileName);
});
});
12 changes: 6 additions & 6 deletions tests/e2e/specs/api/PythonDevFileAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ suite('Python devfile API test', function (): void {
let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper;
let devfileContext: DevfileContext;
let devfileContent: string = '';
let dwtName: string = '';
let devfileName: string = '';

suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp();
Expand All @@ -43,17 +43,17 @@ suite('Python devfile API test', function (): void {
kubernetesCommandLineToolsExecutor.namespace = API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE || 'admin-devspaces';
devfileContent = devfilesRegistryHelper.getDevfileContent(devfileID);
const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditorFromCheConfigMap('editors-definitions');
dwtName = YAML.parse(devfileContent).metadata.name;
const uniqName: string = YAML.parse(devfileContent).metadata.name + randomPref;
kubernetesCommandLineToolsExecutor.workspaceName = uniqName;
devfileName = YAML.parse(devfileContent).metadata.name;
const uniqueName: string = YAML.parse(devfileContent).metadata.name + randomPref;
kubernetesCommandLineToolsExecutor.workspaceName = uniqueName;

devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({
editorContent: editorDevfileContent,
devfileContent: devfileContent
});
devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext();
if (devfileContext.devWorkspace.metadata) {
devfileContext.devWorkspace.metadata.name = uniqName;
devfileContext.devWorkspace.metadata.name = uniqueName;
}
const devWorkspaceConfigurationYamlString: string =
devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext);
Expand All @@ -74,6 +74,6 @@ suite('Python devfile API test', function (): void {
});

suiteTeardown('Delete DevWorkspace', function (): void {
kubernetesCommandLineToolsExecutor.deleteDevWorkspace(dwtName);
kubernetesCommandLineToolsExecutor.deleteDevWorkspace(devfileName);
});
});
111 changes: 111 additions & 0 deletions tests/e2e/specs/api/QuarkusDevFileAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/** *******************************************************************
* copyright (c) 2024 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS';
import { e2eContainer } from '../../configs/inversify.config';
import { CLASSES } from '../../configs/inversify.types';
import { DevfilesHelper } from '../../utils/DevfilesHelper';
import { ContainerTerminal, KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor';
import { DevWorkspaceConfigurationHelper } from '../../utils/DevWorkspaceConfigurationHelper';
import { DevfileContext } from '@eclipse-che/che-devworkspace-generator/lib/api/devfile-context';
import { ShellString } from 'shelljs';
import { expect } from 'chai';
import { API_TEST_CONSTANTS } from '../../constants/API_TEST_CONSTANTS';
import YAML from 'yaml';
import { Logger } from '../../utils/Logger';
import crypto from 'crypto';

suite('Quarkus devfile API test', function (): void {
const devfilesRegistryHelper: DevfilesHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper);
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(
CLASSES.KubernetesCommandLineToolsExecutor
);
const devfileID: string = 'quarkus';
const containerTerminal: ContainerTerminal = e2eContainer.get(CLASSES.ContainerTerminal);
let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper;
let devfileContext: DevfileContext;
let devfileContent: string = '';

suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp();
});

test(`Create ${devfileID} workspace`, async function (): Promise<void> {
const randomPref: string = crypto.randomBytes(4).toString('hex');
kubernetesCommandLineToolsExecutor.namespace = API_TEST_CONSTANTS.TS_API_TEST_NAMESPACE || 'admin-devspaces';
devfileContent = devfilesRegistryHelper.getDevfileContent(devfileID);
const editorDevfileContent: string = devfilesRegistryHelper.obtainCheDevFileEditorFromCheConfigMap('editors-definitions');
const uniqueName: string = YAML.parse(devfileContent).metadata.name + randomPref;
kubernetesCommandLineToolsExecutor.workspaceName = uniqueName;

devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({
editorContent: editorDevfileContent,
devfileContent: devfileContent
});
devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext();
if (devfileContext.devWorkspace.metadata) {
devfileContext.devWorkspace.metadata.name = uniqueName;

if (
devfileContext.devWorkspaceTemplates &&
devfileContext.devWorkspaceTemplates.length > 0 &&
devfileContext.devWorkspaceTemplates[0].metadata
) {
devfileContext.devWorkspaceTemplates[0].metadata.name = uniqueName;
}
}

const devWorkspaceConfigurationYamlString: string =
devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext);
const output: ShellString = kubernetesCommandLineToolsExecutor.applyAndWaitDevWorkspace(devWorkspaceConfigurationYamlString);
expect(output.stdout).contains('condition met');
});

test('Check packaging application', function (): void {
const workdir: string = YAML.parse(devfileContent).commands[0].exec.workingDir;
const commandLine: string = YAML.parse(devfileContent).commands[0].exec.commandLine;
const containerName: string = YAML.parse(devfileContent).commands[0].exec.component;
Logger.info(`workdir from exec section of DevWorkspace file: ${workdir}`);
Logger.info(`commandLine from exec section of DevWorkspace file: ${commandLine}`);

let runCommandInBash: string = '"${commandLine}"'.replaceAll('$', '\\$');

if (workdir !== undefined && workdir !== '') {
runCommandInBash = 'cd ${workdir} && ' + runCommandInBash;
}

const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName);
expect(output.code).eqls(0);
expect(output.stdout.trim()).contains('BUILD SUCCESS');
});

test('Check running application', function (): void {
const workdir: string = YAML.parse(devfileContent).commands[1].exec.workingDir;
const commandLine: string = YAML.parse(devfileContent).commands[1].exec.commandLine;
const containerName: string = YAML.parse(devfileContent).commands[1].exec.component;
Logger.info(`workdir from exec section of DevWorkspace file: ${workdir}`);
Logger.info(`commandLine from exec section of DevWorkspace file: ${commandLine}`);

let runCommandInBash: string = '"${commandLine}"'.replaceAll('$', '\\$');

if (workdir !== undefined && workdir !== '') {
runCommandInBash = 'cd ${workdir} && ' + runCommandInBash;
}

runCommandInBash.replaceAll('$', '\\$'); // don't wipe out env. vars like "${PROJECTS_ROOT}"

const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName);
expect(output.code).eqls(0);
expect(output.stdout.trim()).contains('Listening for transport dt_socket at address: 5005');
});

suiteTeardown('Delete workspace', function (): void {
kubernetesCommandLineToolsExecutor.deleteDevWorkspace();
});
});
27 changes: 9 additions & 18 deletions tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,33 +94,24 @@
return output.stderr ? output.stderr : output.stdout.replace('\n', '');
}

// used to delete when devWorkspace and devWorkspaceTemplate have the same names
deleteDevWorkspace(): void;

// used to delete when devWorkspace and devWorkspaceTemplate have different names
deleteDevWorkspace(dwTemplateName: string): void;

deleteDevWorkspace(dwTemplateName?: string): void {
deleteDevWorkspace(devfileName?: string): void {
Logger.debug(`${this.kubernetesCommandLineTool} - delete '${this.workspaceName}' devWorkspace`);

this.shellExecutor.executeCommand(
`${this.kubernetesCommandLineTool} patch dw ${this.workspaceName} -n ${this.namespace} -p '{ "metadata": { "finalizers": null }}' --type merge || true`
);
this.shellExecutor.executeCommand(`${this.kubernetesCommandLineTool} delete dw ${this.workspaceName} -n ${this.namespace} || true`);

if (dwTemplateName === undefined) {
Logger.debug(`${this.kubernetesCommandLineTool} - delete '${this.workspaceName}' devWorkspaceTemplate`);

this.shellExecutor.executeCommand(
`${this.kubernetesCommandLineTool} delete dwt ${BASE_TEST_CONSTANTS.TS_SELENIUM_EDITOR}-${this.workspaceName} -n ${this.namespace} || true`
);
let dwtName: string;
if (devfileName === undefined) {
dwtName = `${BASE_TEST_CONSTANTS.TS_SELENIUM_EDITOR}-${this.workspaceName}`;
} else {
Logger.debug(`${this.kubernetesCommandLineTool} - delete '${dwTemplateName}' devWorkspaceTemplate`);

this.shellExecutor.executeCommand(
`${this.kubernetesCommandLineTool} delete dwt ${BASE_TEST_CONSTANTS.TS_SELENIUM_EDITOR}-${dwTemplateName} -n ${this.namespace} || true`
);
dwtName = `${BASE_TEST_CONSTANTS.TS_SELENIUM_EDITOR}-${devfileName}`;
Dismissed Show dismissed Hide dismissed
}

Logger.debug(`${this.kubernetesCommandLineTool} - delete '${dwtName}' devWorkspaceTemplate`);

this.shellExecutor.executeCommand(`${this.kubernetesCommandLineTool} delete dwt ${dwtName} -n ${this.namespace} || true`);
Dismissed Show dismissed Hide dismissed
}

applyAndWaitDevWorkspace(yamlConfiguration: string): ShellString {
Expand Down
Loading