Skip to content

Commit

Permalink
Refactoring CloneGitRepoAPI.spec.ts to work with DevWorkspace generat…
Browse files Browse the repository at this point in the history
…or tool eclipse-che#22223

Signed-off-by: mdolhalo <mdolhalo@redhat.com>
  • Loading branch information
mdolhalo committed May 19, 2023
1 parent 96b686f commit 1da9e70
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 78 deletions.
12 changes: 10 additions & 2 deletions tests/e2e/constants/TestConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,17 @@ export const TestConstants: any = {

TS_API_TEST_KUBERNETES_COMMAND_LINE_TOOL: process.env.TS_API_TEST_KUBERNETES_COMMAND_LINE_TOOL || KubernetesCommandLineTool.OC,

TS_API_TEST_UDI_IMAGE: process.env.TS_API_TEST_UDI_IMAGE || 'quay.io/devfile/universal-developer-image:latest',
// 'quay.io/devfile/universal-developer-image:latest'
// is default assigned by DevWorkspaceConfigurationHelper.generateDevfileContext() using @eclipse-che/che-devworkspace-generator
TS_API_TEST_UDI_IMAGE: process.env.TS_API_TEST_UDI_IMAGE || undefined,

TS_API_TEST_CHE_CODE_EDITOR_DEVFILE_URI: process.env.TS_API_TEST_CHE_CODE_EDITOR_DEVFILE_URI || `https://eclipse-che.github.io/che-plugin-registry/main/v3/plugins/che-incubator/che-code/latest/devfile.yaml`,
// https://eclipse-che.github.io/che-plugin-registry/main/v3/plugins/che-incubator/che-code/latest/devfile.yaml
// is default assigned by DevWorkspaceConfigurationHelper.generateDevfileContext() using @eclipse-che/che-devworkspace-generator
TS_API_TEST_CHE_CODE_EDITOR_DEVFILE_URI: process.env.TS_API_TEST_CHE_CODE_EDITOR_DEVFILE_URI || undefined,

// https://eclipse-che.github.io/che-plugin-registry/main/v3
// is default assigned by DevWorkspaceConfigurationHelper.generateDevfileContext() using @eclipse-che/che-devworkspace-generator
TS_API_TEST_PLUGIN_REGISTRY_URL: process.env.TS_API_TEST_PLUGIN_REGISTRY_URL || undefined,

TS_API_TEST_NAMESPACE: process.env.TS_API_TEST_NAMESPACE || undefined,

Expand Down
73 changes: 0 additions & 73 deletions tests/e2e/specs/api/CloneGitRepoAPI.spec.ts

This file was deleted.

1 change: 0 additions & 1 deletion tests/e2e/specs/api/DevfileAcceptanceTestAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ suite(`Devfile acceptance test`, async function (): Promise<void> {

devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({
devfileUrl,
projects: []
});
devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext();
devWorkspaceName = devfileContext?.devWorkspace?.metadata?.name;
Expand Down
71 changes: 71 additions & 0 deletions tests/e2e/specs/api/EmptyWorkspaceAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor';
import { expect } from 'chai';
import { ShellString } from 'shelljs';
import { GitUtil } from '../../utils/vsc/GitUtil';
import { TestConstants } from '../../constants/TestConstants';
import { DevWorkspaceConfigurationHelper } from '../../utils/DevWorkspaceConfigurationHelper';
import { DevfileContext } from '@eclipse-che/che-devworkspace-generator/lib/api/devfile-context';

suite(`Empty workspace API test`, async function (): Promise<void> {
// works only for root user
const namespace: string = TestConstants.TS_API_TEST_NAMESPACE ? TestConstants.TS_API_TEST_NAMESPACE : undefined;
let clonedProjectName: string;
let containerWorkDir: string;
let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper;
let kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor;
let devfileContext: DevfileContext;
let devWorkspaceName: string | undefined;
let containerTerminal: KubernetesCommandLineToolsExecutor.ContainerTerminal;

const gitRepository: string = 'https://github.com/crw-qe/web-nodejs-sample';

suiteSetup('Create empty workspace with OC client', async function (): Promise<void> {
const workspaceName: string = 'empty-' + Math.floor(Math.random() * 1000);
const devfileContent: string =
'schemaVersion: 2.2.0\n' +
'metadata:\n' +
` name: ${workspaceName}\n`;

devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({
devfileContent,
});
devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext();
devWorkspaceName = devfileContext?.devWorkspace?.metadata?.name;
kubernetesCommandLineToolsExecutor = new KubernetesCommandLineToolsExecutor(devWorkspaceName, namespace);
containerTerminal = new KubernetesCommandLineToolsExecutor.ContainerTerminal(kubernetesCommandLineToolsExecutor);
});

test('Create empty workspace', async function (): Promise<void> {
kubernetesCommandLineToolsExecutor.loginToOcp();
const devWorkspaceConfigurationYamlString: string = await devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext);
const output: ShellString = kubernetesCommandLineToolsExecutor.applyAndWaitDevWorkspace(devWorkspaceConfigurationYamlString);
expect(output.stdout).contains('condition met');
});

suiteTeardown('Delete workspace', function (): void {
kubernetesCommandLineToolsExecutor.deleteDevWorkspace();
});

suite('Clone public repo without previous setup', function (): void {
suiteTeardown('Delete cloned project', function (): void {
containerTerminal.removeFolder(`${clonedProjectName}`);
});

test('Check if public repo can be cloned', function (): void {
containerWorkDir = containerTerminal.pwd().stdout.replace('\n', '');
const cloneOutput: ShellString = containerTerminal.gitClone(gitRepository);
expect(cloneOutput.stdout + cloneOutput.stderr).includes('Cloning');
});

test('Check if project was created', function (): void {
clonedProjectName = GitUtil.getProjectNameFromGitUrl(gitRepository);
expect(containerTerminal.ls().stdout).includes(clonedProjectName);
});

test('Check if files were imported ', function (): void {
expect(containerTerminal.ls(`${containerWorkDir}/${clonedProjectName}`).stdout).includes(TestConstants.TS_SELENIUM_PROJECT_ROOT_FILE_NAME);
});
});
});


25 changes: 23 additions & 2 deletions tests/e2e/utils/DevWorkspaceConfigurationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { V1alpha2DevWorkspaceTemplate } from '@devfile/api';
import YAML from 'yaml';
import * as axios from 'axios';
import { Logger } from './Logger';
import { TestConstants } from '../constants/TestConstants';
import { ShellExecutor } from './ShellExecutor';

interface IContextParams {
devfilePath?: string | undefined;
Expand All @@ -14,7 +16,7 @@ interface IContextParams {
editorContent?: string | undefined;
editorEntry?: string | undefined;
pluginRegistryUrl?: string | undefined;
projects: {
projects?: {
name: string;
location: string;
}[];
Expand All @@ -31,14 +33,33 @@ export class DevWorkspaceConfigurationHelper {
if (!(params.editorPath || params.editorEntry || params.editorContent)) {
params.editorEntry = 'che-incubator/che-code/latest';
}
// check if one or both has value
if (TestConstants.TS_API_TEST_UDI_IMAGE || params.defaultComponentImage) {
params.injectDefaultComponent = 'true';
// check if not explicitly passed than assign value from the constants
if (!params.defaultComponentImage) {
params.defaultComponentImage = TestConstants.TS_API_TEST_UDI_IMAGE;
}
}
// assign value from the constants if not explicitly passed
if (TestConstants.TS_API_TEST_PLUGIN_REGISTRY_URL && !params.pluginRegistryUrl) {
params.pluginRegistryUrl = TestConstants.TS_API_TEST_PLUGIN_REGISTRY_URL;
}
if (TestConstants.TS_API_TEST_CHE_CODE_EDITOR_DEVFILE_URI && !params.editorContent) {
params.editorContent = ShellExecutor.curl(TestConstants.TS_API_TEST_CHE_CODE_EDITOR_DEVFILE_URI).stdout;
}
this.params = params;
}

async generateDevfileContext(): Promise<DevfileContext> {
Logger.debug(`${this.constructor.name}.${this.generateDevfileContext.name}`);
if (!this.params.projects) {
this.params.projects = [];
}
return await this.generator.generateDevfileContext(
{
...this.params
...this.params,
projects: this.params.projects
},
axios.default as any
);
Expand Down

0 comments on commit 1da9e70

Please sign in to comment.