Skip to content

Commit

Permalink
Update to overload 'deleteDevWorkspace' method
Browse files Browse the repository at this point in the history
  • Loading branch information
artaleks9 committed Dec 24, 2024
1 parent d289a1d commit d2aa3d6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
6 changes: 4 additions & 2 deletions tests/e2e/specs/api/GoDevFileAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ suite('Go devfile API test', function (): void {
let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper;
let devfileContext: DevfileContext;
let devfileContent: string = '';
let dwtName: string = '';

suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp();
Expand All @@ -42,6 +43,7 @@ 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;

Expand Down Expand Up @@ -84,7 +86,7 @@ suite('Go devfile API test', function (): void {
expect(logOutput.stdout.trim()).contains('Web server running on port 8080');
});

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

suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp();
Expand All @@ -41,6 +42,7 @@ 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;

Expand Down Expand Up @@ -70,7 +72,7 @@ suite('PHP devfile API test', function (): void {
expect(output.stdout.trim()).contains('Hello, world!');
});

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

suiteSetup(`Prepare login ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp();
Expand All @@ -42,6 +43,7 @@ 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;

Expand Down Expand Up @@ -71,7 +73,7 @@ suite('Python devfile API test', function (): void {
expect(output.stdout.trim()).contains('Hello, world!');
});

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

deleteDevWorkspace(): void {
Logger.debug(`${this.kubernetesCommandLineTool} - delete '${this.workspaceName}' workspace`);
// 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 {
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`);
this.shellExecutor.executeCommand(
`${this.kubernetesCommandLineTool} delete dwt ${BASE_TEST_CONSTANTS.TS_SELENIUM_EDITOR}-${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`
);
} 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`

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input Medium test

This string concatenation which depends on
library input
is later used in a
shell command
.
);
}
}

applyAndWaitDevWorkspace(yamlConfiguration: string): ShellString {
Expand Down

0 comments on commit d2aa3d6

Please sign in to comment.