Skip to content

Commit

Permalink
Add QuarkusDevFileAPI test
Browse files Browse the repository at this point in the history
Signed-off-by: Dmytro Nochevnov <[email protected]>
  • Loading branch information
dmytro-ndp committed Dec 20, 2024
1 parent 76b99e7 commit 58836b9
Showing 1 changed file with 111 additions and 0 deletions.
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 uniqName: string = YAML.parse(devfileContent).metadata.name + randomPref;
kubernetesCommandLineToolsExecutor.workspaceName = uniqName;

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

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

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 = '\"${commandLine}\"'.replaceAll('$', '\\$');

Check failure on line 77 in tests/e2e/specs/api/QuarkusDevFileAPI.spec.ts

View workflow job for this annotation

GitHub Actions / pr-check

Expected runCommandInBash to have a type annotation

if (workdir != undefined && workdir !== '') {

Check failure on line 79 in tests/e2e/specs/api/QuarkusDevFileAPI.spec.ts

View workflow job for this annotation

GitHub Actions / pr-check

Expected '!==' and instead saw '!='
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 = '\"${commandLine}\"'.replaceAll('$', '\\$');

Check failure on line 95 in tests/e2e/specs/api/QuarkusDevFileAPI.spec.ts

View workflow job for this annotation

GitHub Actions / pr-check

Expected runCommandInBash to have a type annotation

if (workdir != undefined && workdir !== '') {

Check failure on line 97 in tests/e2e/specs/api/QuarkusDevFileAPI.spec.ts

View workflow job for this annotation

GitHub Actions / pr-check

Expected '!==' and instead saw '!='
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();
});
});

0 comments on commit 58836b9

Please sign in to comment.