diff --git a/tests/e2e/constants/API_TEST_CONSTANTS.ts b/tests/e2e/constants/API_TEST_CONSTANTS.ts index b2e295bfdf6..7e0cf53e727 100644 --- a/tests/e2e/constants/API_TEST_CONSTANTS.ts +++ b/tests/e2e/constants/API_TEST_CONSTANTS.ts @@ -18,9 +18,14 @@ export enum KubernetesCommandLineTool { export const SUPPORTED_DEVFILE_REGISTRIES: { INBUILT_APPLICATION_DEVFILE_REGISTRY_URL: () => string; GIT_HUB_CHE_DEVFILE_REGISTRY_URL: string; + TS_GIT_API_AUTH_TOKEN: string; } = { INBUILT_APPLICATION_DEVFILE_REGISTRY_URL: (): string => `${BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL}/devfile-registry/devfiles/`, - GIT_HUB_CHE_DEVFILE_REGISTRY_URL: 'https://api.github.com/repos/eclipse-che/che-devfile-registry/contents/devfiles/' + GIT_HUB_CHE_DEVFILE_REGISTRY_URL: 'https://api.github.com/repos/eclipse-che/che-devfile-registry/contents/devfiles/', + /** + * gitHub has a rate limit for unauthorized requests to GitHub API. We can prevent this problems using authorization token + */ + TS_GIT_API_AUTH_TOKEN: process.env.TS_GIT_API_AUTH_TOKEN || '' }; export const API_TEST_CONSTANTS: { TS_API_TEST_DEV_WORKSPACE_LIST: string | undefined; diff --git a/tests/e2e/constants/BASE_TEST_CONSTANTS.ts b/tests/e2e/constants/BASE_TEST_CONSTANTS.ts index 585fd80b7da..60065fb133b 100644 --- a/tests/e2e/constants/BASE_TEST_CONSTANTS.ts +++ b/tests/e2e/constants/BASE_TEST_CONSTANTS.ts @@ -32,6 +32,7 @@ export const BASE_TEST_CONSTANTS: { TS_SELENIUM_REQUEST_INTERCEPTOR: boolean; TS_SELENIUM_RESPONSE_INTERCEPTOR: boolean; TESTING_APPLICATION_NAME: () => string; + TEST_NAMESPACE: string; } = { /** * base URL of the application which should be checked @@ -53,15 +54,24 @@ export const BASE_TEST_CONSTANTS: { */ TEST_ENVIRONMENT: process.env.TEST_ENVIRONMENT || '', + /** + * openshift project or k8s namespace which is used by test + */ + TEST_NAMESPACE: process.env.TEST_NAMESPACE || '', + /** * application name (DevSpaces or Che) */ TESTING_APPLICATION_NAME: (): string => { - return BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL.includes('devspaces') - ? 'devspaces' - : BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL.includes('che') - ? 'che' - : 'default'; + if (BASE_TEST_CONSTANTS.TEST_NAMESPACE.length > 0) { + return BASE_TEST_CONSTANTS.TEST_NAMESPACE; + } else if (BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL.includes('devspaces')) { + return 'admin-devspaces'; + } else if (BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL.includes('che')) { + return 'che'; + } else { + return 'admin-che'; + } }, /** diff --git a/tests/e2e/utils/DevfilesRegistryHelper.ts b/tests/e2e/utils/DevfilesRegistryHelper.ts index ba912bba4c1..74834be0c1d 100644 --- a/tests/e2e/utils/DevfilesRegistryHelper.ts +++ b/tests/e2e/utils/DevfilesRegistryHelper.ts @@ -12,7 +12,7 @@ import { Logger } from './Logger'; import YAML from 'yaml'; import { API_TEST_CONSTANTS, SUPPORTED_DEVFILE_REGISTRIES } from '../constants/API_TEST_CONSTANTS'; import { injectable } from 'inversify'; -import { BASE_TEST_CONSTANTS } from '../constants/BASE_TEST_CONSTANTS'; +import { BASE_TEST_CONSTANTS, Platform } from '../constants/BASE_TEST_CONSTANTS'; @injectable() export class DevfilesRegistryHelper { @@ -64,11 +64,12 @@ export class DevfilesRegistryHelper { } else if (isInbuilt) { { const content: any[any] = await this.getInbuiltDevfilesRegistryContent(sampleNamePatterns); + const devfileRegistryPrefix: string = + BASE_TEST_CONSTANTS.TS_PLATFORM === Platform.OPENSHIFT + ? BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL + '/devfile-registry' + : ''; for (const sample of content) { - const linkToDevWorkspaceYaml: any = - BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL + - '/devfile-registry' + - sample.links.devWorkspaces['che-incubator/che-code/latest']; + const linkToDevWorkspaceYaml: any = `${devfileRegistryPrefix}${sample.links.devWorkspaces['che-incubator/che-code/latest']}`; devfileSamples.push({ name: sample.displayName, devWorkspaceConfigurationString: await this.getContent(linkToDevWorkspaceYaml) @@ -97,9 +98,19 @@ export class DevfilesRegistryHelper { return content; } + // eslint-disable-next-line @typescript-eslint/no-unused-vars private async getContent(url: string, headers?: object): Promise { Logger.trace(`${url}`); - + if (SUPPORTED_DEVFILE_REGISTRIES.TS_GIT_API_AUTH_TOKEN.length !== 0) { + /** + * if we use - https://api.github.com/repos/eclipse-che/che-devfile-registry/contents/devfiles/ URL + * for generating devfiles we can get a problem with rate limits to GitHub API, + * but we can pass auth. token for increase the limit and avoiding problems + */ + headers = { + headers: { Authorization: SUPPORTED_DEVFILE_REGISTRIES.TS_GIT_API_AUTH_TOKEN } + }; + } let response: AxiosResponse | undefined; try { response = await axios.get(url, headers); diff --git a/tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts b/tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts index 49046af21bc..03a73ef41d8 100644 --- a/tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts +++ b/tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts @@ -51,7 +51,7 @@ export class KubernetesCommandLineToolsExecutor implements IKubernetesCommandLin if (applicationName === 'default') { this._namespace = applicationName; } else { - this._namespace = OAUTH_CONSTANTS.TS_SELENIUM_OCP_USERNAME + '-' + applicationName; + this._namespace = OAUTH_CONSTANTS.TS_SELENIUM_OCP_USERNAME + applicationName; } } return this._namespace;