Skip to content
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

Improve and fix problems for running DevFile API tests #22677

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion tests/e2e/constants/API_TEST_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 15 additions & 5 deletions tests/e2e/constants/BASE_TEST_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
}
},

/**
Expand Down
23 changes: 17 additions & 6 deletions tests/e2e/utils/DevfilesRegistryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<AxiosResponse> {
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);
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading