Skip to content

Commit 45f4fb4

Browse files
authored
Add missed attributes to the devfile content in API tests (#23478)
Signed-off-by: Dmytro Nochevnov <[email protected]>
1 parent 2338445 commit 45f4fb4

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

tests/e2e/specs/dashboard-samples/RecommendedExtensions.spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ async function findItem(extSection: ExtensionsViewSection, title: string): Promi
160160
Logger.debug(`Extension with title "${searchTitle}" not found in section "${sectionTitle}"`);
161161
return undefined;
162162
}
163+
163164
// get visible items from Extension view, transform this from array to sorted string and compares it with existed recommended extensions
164165
async function getVisibleFilteredItemsAndCompareWithRecommended(recommendations: string[]): Promise<boolean> {
165166
const extensionsView: SideBarView | undefined = await (await new ActivityBar().getViewControl('Extensions'))?.openView();
@@ -180,20 +181,23 @@ async function getVisibleFilteredItemsAndCompareWithRecommended(recommendations:
180181
}
181182
Logger.debug('marketplaceSection.getVisibleItems()');
182183
const allFoundRecommendedItems: ExtensionsViewItem[] = await marketplaceSection.getVisibleItems();
184+
183185
const allFoundRecommendedAuthors: string[] = await Promise.all(
184186
allFoundRecommendedItems.map(async (item: ExtensionsViewItem): Promise<string> => await item.getAuthor())
185187
);
186188

187189
const allFoundAuthorsAsSortedString: string = allFoundRecommendedAuthors.sort().toString();
188-
const allPublisherNamesAsSorString: string = recommendations.sort().toString();
189-
return allFoundAuthorsAsSortedString === allPublisherNamesAsSorString;
190+
const allPublisherNamesAsSortedString: string = recommendations.sort().toString();
191+
return allFoundAuthorsAsSortedString === allPublisherNamesAsSortedString;
190192
}
193+
191194
// get visible items from Extension view, transform this from array to sorted string and compares it with existed installed extensions
192195
async function getVisibleFilteredItemsAndCompareWithInstalled(recommendations: string[]): Promise<boolean> {
193196
const extensionsView: SideBarView | undefined = await (await new ActivityBar().getViewControl('Extensions'))?.openView();
194197
const [marketplaceSection]: ExtensionsViewSection[] = (await extensionsView?.getContent().getSections()) as ExtensionsViewSection[];
195198
Logger.debug('marketplaceSection.getVisibleItems()');
196199
const allFoundRecommendedItems: ExtensionsViewItem[] = await marketplaceSection.getVisibleItems();
200+
197201
const allFoundRecommendedAuthors: string[] = await Promise.all(
198202
allFoundRecommendedItems.map(async (item: ExtensionsViewItem): Promise<string> => await item.getAuthor())
199203
);
@@ -203,6 +207,7 @@ async function getVisibleFilteredItemsAndCompareWithInstalled(recommendations: s
203207
// in some cases we can have installed not only recommended extensions with some samples (for example .Net)
204208
return allFoundAuthorsAsSortedString.includes(allPublisherNamesAsSortString);
205209
}
210+
206211
for (const sample of samples) {
207212
suite(`Check if recommended extensions installed for ${sample} ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
208213
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests);
@@ -292,10 +297,29 @@ for (const sample of samples) {
292297
recommendedExtensions = JSON.parse(text.replace(/\/\*[\s\S]*?\*\/|(?<=[^:])\/\/.*|^\/\/.*/g, '').trim());
293298

294299
Logger.debug('recommendedExtensions.recommendations: Get recommendations clear names using map().');
300+
301+
// skip the test if only redhat.fabric8-analytics extension is found in Dev Spaces 3.22.0 (issue CRW-9186)
302+
if (BASE_TEST_CONSTANTS.OCP_VERSION === '3.22.0' && BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME() === 'devspaces') {
303+
const dependencyAnalyticsExtensionName: string = 'redhat.fabric8-analytics';
304+
if (
305+
recommendedExtensions.recommendations.includes(dependencyAnalyticsExtensionName) &&
306+
recommendedExtensions.recommendations.length === 1
307+
) {
308+
throw new Error(
309+
`Only '${dependencyAnalyticsExtensionName}' extension found. This extension will not be installed because of known issue https://issues.redhat.com/browse/CRW-9186`
310+
);
311+
} else {
312+
recommendedExtensions.recommendations = recommendedExtensions.recommendations.filter(
313+
(rec: string): boolean => !rec.includes(dependencyAnalyticsExtensionName)
314+
);
315+
}
316+
}
317+
295318
parsedRecommendations = recommendedExtensions.recommendations.map((rec: string): { name: string; publisher: string } => {
296319
const [publisher, name] = rec.split('.');
297320
return { publisher, name };
298321
});
322+
299323
Logger.debug(`Recommended extension for this workspace:\n${JSON.stringify(parsedRecommendations)}.`);
300324
publisherNames = parsedRecommendations.map((rec: { name: string; publisher: string }): string => rec.publisher);
301325
expect(parsedRecommendations, 'Recommendations not found').not.empty;

tests/e2e/utils/DevWorkspaceConfigurationHelper.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as axios from 'axios';
1515
import { Logger } from './Logger';
1616
import { ShellExecutor } from './ShellExecutor';
1717
import { API_TEST_CONSTANTS } from '../constants/API_TEST_CONSTANTS';
18+
import { BASE_TEST_CONSTANTS } from '../constants/BASE_TEST_CONSTANTS';
1819
import { injectable } from 'inversify';
1920
import { IContextParams } from './IContextParams';
2021
import { e2eContainer } from '../configs/inversify.config';
@@ -69,7 +70,9 @@ export class DevWorkspaceConfigurationHelper {
6970
axios.default as any
7071
);
7172

72-
this.patchDevWorkspaceConfigWithStorageTypeAttribute(devfileContext);
73+
if (BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME() === 'devspaces') {
74+
this.addMissedDevWorkspaceConfigAttributes(devfileContext);
75+
}
7376

7477
return devfileContext;
7578
}
@@ -104,26 +107,20 @@ export class DevWorkspaceConfigurationHelper {
104107
return content;
105108
}
106109

107-
patchDevWorkspaceConfigWithBuildContainerAttribute(devfileContextDevWorkspace: any): void {
108-
Logger.debug();
109-
devfileContextDevWorkspace.spec.template.attributes = YAML.parse(`
110-
controller.devfile.io/devworkspace-config:
111-
name: devworkspace-config
112-
namespace: openshift-devspaces
113-
controller.devfile.io/scc: container-build
114-
controller.devfile.io/storage-type: per-user`);
115-
}
116-
117110
/**
118-
* add storage type attribute to fix issue CRW-8922.
111+
* add missed attributes to fix issues CRW-8922, CRW-9187.
119112
*/
120-
patchDevWorkspaceConfigWithStorageTypeAttribute(
113+
addMissedDevWorkspaceConfigAttributes(
121114
devfileContextDevWorkspace: DevfileContext,
122-
storageType: string = API_TEST_CONSTANTS.TS_API_TEST_STORAGE_TYPE
115+
storageType: string | undefined = API_TEST_CONSTANTS.TS_API_TEST_STORAGE_TYPE
123116
): void {
124117
Logger.debug();
125118
devfileContextDevWorkspace.devWorkspace?.spec?.template &&
126119
(devfileContextDevWorkspace.devWorkspace.spec.template.attributes = YAML.parse(`
127-
controller.devfile.io/storage-type: ${storageType}`));
120+
controller.devfile.io/devworkspace-config:
121+
name: devworkspace-config
122+
namespace: openshift-devspaces
123+
controller.devfile.io/scc: container-build
124+
controller.devfile.io/storage-type: ${storageType}`));
128125
}
129126
}

0 commit comments

Comments
 (0)