-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 'CppDevFileAPI' E2E test #23289
Add 'CppDevFileAPI' E2E test #23289
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** ******************************************************************* | ||
* 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('Cpp devfile API test', function (): void { | ||
const devfilesRegistryHelper: DevfilesHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper); | ||
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get( | ||
CLASSES.KubernetesCommandLineToolsExecutor | ||
); | ||
const devfileID: string = 'cpp'; | ||
const containerTerminal: ContainerTerminal = e2eContainer.get(CLASSES.ContainerTerminal); | ||
let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper; | ||
let devfileContext: DevfileContext; | ||
let devfileContent: string = ''; | ||
const workDirPath: string = 'c-plus-plus/strings'; | ||
const buildCommand: string = 'rm -f bin.out && g++ -g "knuth_morris_pratt.cpp" -o bin.out && echo "Build complete"'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build command should be extracted from the devfile yaml of C++ sample. See an example in https://github.com/eclipse-che/che/blob/main/tests/e2e/specs/api/PythonDevFileAPI.spec.ts#L64 |
||
const runCommand: string = './bin.out'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Run command should be extracted from the devfile yaml of C++ sample. See an example in https://github.com/eclipse-che/che/blob/main/tests/e2e/specs/api/PythonDevFileAPI.spec.ts#L64 |
||
|
||
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; | ||
} | ||
const devWorkspaceConfigurationYamlString: string = | ||
devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext); | ||
const output: ShellString = kubernetesCommandLineToolsExecutor.applyAndWaitDevWorkspace(devWorkspaceConfigurationYamlString); | ||
expect(output.stdout).contains('condition met'); | ||
}); | ||
|
||
test('Check commands', function (): void { | ||
let runCommandInBash: string; | ||
let output: ShellString; | ||
const toolsComponent: any = YAML.parse(devfileContent).components.find((component: any): boolean => component.name === 'tools'); | ||
const containerName: string = toolsComponent ? toolsComponent.name : 'Component not found'; | ||
Logger.info(`container from components section of Devfile:: ${containerName}`); | ||
runCommandInBash = `cd ${workDirPath} && ${buildCommand}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's important to test build command extracted from C++ sample devfile together with workDir property, not hard-coded in the test itself. Example of command extraction can be found in the in the code https://github.com/eclipse-che/che/blob/main/tests/e2e/specs/api/PythonDevFileAPI.spec.ts#L63-L64 |
||
Logger.info('Check build command'); | ||
output = containerTerminal.execInContainerCommand(runCommandInBash, containerName); | ||
expect(output.code).eqls(0); | ||
expect(output.stdout.trim()).contains('Build complete'); | ||
Logger.info('Check run command'); | ||
runCommandInBash = `cd ${workDirPath} && ${runCommand}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's important to test run command extracted from C++ sample devfile together with workDir property, not hard-coded in the test itself. Example of command extraction can be found in the in the code https://github.com/eclipse-che/che/blob/main/tests/e2e/specs/api/PythonDevFileAPI.spec.ts#L63-L64 |
||
output = containerTerminal.execInContainerCommand(runCommandInBash, containerName); | ||
expect(output.code).eqls(0); | ||
expect(output.stdout.trim()).contains('Found'); | ||
}); | ||
|
||
suiteTeardown('Delete workspace', function (): void { | ||
kubernetesCommandLineToolsExecutor.deleteDevWorkspace(); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be extracted from the devfile yaml for particular command
See an example in https://github.com/eclipse-che/che/blob/main/tests/e2e/specs/api/PythonDevFileAPI.spec.ts#L63