Skip to content

Commit

Permalink
test(e2e): added deploying to crc cluster test case
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Villanueva <[email protected]>
  • Loading branch information
danivilla9 committed Feb 11, 2025
1 parent 85a2f92 commit 38743d0
Showing 1 changed file with 118 additions and 8 deletions.
126 changes: 118 additions & 8 deletions tests/src/openshift-local-extension.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (C) 2024 Red Hat, Inc.
* Copyright (C) 2025 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,8 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type { NavigationBar } from '@podman-desktop/tests-playwright';
import { expect as playExpect, ExtensionCardPage, RunnerOptions, test, ResourceConnectionCardPage, PreferencesPage } from '@podman-desktop/tests-playwright';
import type { ContainerInteractiveParams, NavigationBar } from '@podman-desktop/tests-playwright';
import { expect as playExpect, ExtensionCardPage, RunnerOptions, test, ResourceConnectionCardPage, PreferencesPage, ContainerState, ContainerDetailsPage, deleteContainer, deleteImage, deletePod } from '@podman-desktop/tests-playwright';

import { OpenShiftLocalExtensionPage } from './model/pages/openshift-local-extension-page';

Expand All @@ -35,6 +35,17 @@ const disabledExtensionStatus = 'DISABLED';
const notInstalledExtensionStatus = 'NOT-INSTALLED';
const skipInstallation = process.env.SKIP_INSTALLATION ? process.env.SKIP_INSTALLATION : false;

const kubernetesContext = 'microshift';
const imageName1 = 'quay.io/sclorg/httpd-24-micro-c9s';
const imageName2 = 'ghcr.io/linuxcontainers/alpine';
const containerName1 = 'container-to-deploy-1';
const containerName2 = 'container-to-deploy-2';
const deployedPodName1 = 'container-1-pod';
const deployedPodName2 = 'container-2-pod';
const containerStartParams: ContainerInteractiveParams = {
attachTerminal: false,
};

test.use({
runnerOptions: new RunnerOptions({ customFolder: 'crc-tests-pd', autoUpdate: false, autoCheckUpdates: false }),
});
Expand All @@ -46,8 +57,18 @@ test.beforeAll(async ({ runner, page, welcomePage }) => {
preferencesPage = new PreferencesPage(page);
});

test.afterAll(async ({ runner }) => {
await runner.close();
test.afterAll(async ({ runner, page }) => {
try {
await deletePod(page, deployedPodName1);
await deletePod(page, deployedPodName2);
await deleteContainer(page, containerName1);
await deleteContainer(page, containerName2);
await deleteImage(page, imageName1);
await deleteImage(page, imageName2);
} finally {
await runner.close();
console.log('Runner closed');
}
});

test.describe.serial('Red Hat OpenShift Local extension verification', () => {
Expand Down Expand Up @@ -123,10 +144,10 @@ test.describe.serial('Red Hat OpenShift Local extension verification', () => {
await playExpect(extensionCard.status).toHaveText(disabledExtensionStatus);
//checking dashboard assets
const dashboard = await navigationBar.openDashboard();
await playExpect(dashboard.openshiftLocalProvider).toHaveCount(0);
await playExpect(dashboard.openshiftLocalProvider).toHaveCount(0, {timeout: 3_000});
//checking settings/resources assets
await navigationBar.openSettings();
await playExpect(resourcesPage.card).toHaveCount(0);
await playExpect(resourcesPage.card).toHaveCount(0, {timeout: 3_000});
});

test.fail('Extension can be disabled -- Settings/Preferences navbar value should be removed after extension removal, but isn\'t, BUG #393', async () => {
Expand All @@ -146,7 +167,7 @@ test.describe.serial('Red Hat OpenShift Local extension verification', () => {
//checking dashboard assets
const dashboard = await navigationBar.openDashboard();
await playExpect(dashboard.openshiftLocalProvider).toBeVisible();
await playExpect(dashboard.openshiftLocalStatusLabel).toHaveText(notInstalledExtensionStatus); // if locally, delete binary
await playExpect(dashboard.openshiftLocalStatusLabel).toHaveText(notInstalledExtensionStatus); // if locally, delete binary or comment this
//checking settings/resources assets
const settingsBar = await navigationBar.openSettings();
await playExpect(resourcesPage.card).toBeVisible();
Expand All @@ -158,6 +179,95 @@ test.describe.serial('Red Hat OpenShift Local extension verification', () => {
});
});

test.describe.serial('Deploy a container to a CRC cluster by pushing the image from Podman Desktop', () => {
test('Pull image 1 and start the container', async ({ navigationBar }) => {
const imagesPage = await navigationBar.openImages();
await playExpect(imagesPage.heading).toBeVisible();

const pullImagePage = await imagesPage.openPullImage();
const updatedImages = await pullImagePage.pullImage(imageName1);

const exists = await updatedImages.waitForImageExists(imageName1);
playExpect(exists, `${imageName1} image not present in the list of images`).toBeTruthy();
playExpect(await updatedImages.getCurrentStatusOfImage(imageName1)).toBe('UNUSED');

const containersPage = await imagesPage.startContainerWithImage(
imageName1,
containerName1,
containerStartParams,
);
await playExpect.poll(async () => containersPage.containerExists(containerName1)).toBeTruthy();
const containerDetails = await containersPage.openContainersDetails(containerName1);
await playExpect(containerDetails.heading).toBeVisible();
await playExpect.poll(async () => containerDetails.getState()).toBe(ContainerState.Running);
});

test.fail('Push the image to the cluster', async ({ navigationBar, statusBar, page }) => {
const imagesPage = await navigationBar.openImages();
const pulledImage = await imagesPage.getImageRowByName(imageName1);
if (pulledImage === undefined) {
throw Error(`Image: '${name}' does not exist`);
}
const kebabMenuButton = pulledImage.getByRole('button', { name: 'kebab menu' });
await playExpect(kebabMenuButton).toBeVisible();
kebabMenuButton.click();

Check failure on line 213 in tests/src/openshift-local-extension.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests

Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler
//This step will fail => [BUG] option to push the image to OpenShift not shown #372
const pushToClusterButton = imagesPage.getPage().getByTitle('Drop Down Menu Items').getByTitle('Push image to OpenShift Local cluster');
await playExpect(pushToClusterButton).toBeVisible();
//This step will fail => [BUG] Can't push images to OpenShift Local clusters (ssh key name issue) #495
await pushToClusterButton.click();
statusBar.tasksButton.click();

Check failure on line 219 in tests/src/openshift-local-extension.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests

Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler
const tasksManager = page.getByTitle("Tasks manager")

Check warning on line 220 in tests/src/openshift-local-extension.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests

Strings must use singlequote

Check failure on line 220 in tests/src/openshift-local-extension.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests

Missing semicolon
await playExpect(tasksManager.getByTitle("/^Image ${imageName1} was successfully pushed to the OpenShift Local cluster /")).toBeVisible(); //not the actual message; locally this appears only if the crc cluster is started

Check warning on line 221 in tests/src/openshift-local-extension.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests

Strings must use singlequote
});

test.skip('Deploy the container to the crc cluster -- previous step expected to fail', async ({ page, navigationBar }) => {
await navigationBar.openContainers();
const containerDetailsPage = new ContainerDetailsPage(page, containerName1);
await playExpect(containerDetailsPage.heading).toBeVisible();
const deployToKubernetesPage = await containerDetailsPage.openDeployToKubernetesPage();
await deployToKubernetesPage.deployPod(deployedPodName1, { useKubernetesServices: true, isOpenShiftCluster: true, useOpenShiftRoutes: true }, kubernetesContext);

const podsPage = await navigationBar.openPods();
await playExpect.poll(async () => podsPage.deployedPodExists(deployedPodName1, 'kubernetes')).toBeTruthy();
});

});

test.describe.serial('Deploy a container to a CRC cluster by pulling the image directly from the cluster', () => {
test('Pull image 2 and start a container', async ({ navigationBar }) => {
const imagesPage = await navigationBar.openImages();
await playExpect(imagesPage.heading).toBeVisible();

const pullImagePage = await imagesPage.openPullImage();
const updatedImages = await pullImagePage.pullImage(imageName2);

const exists = await updatedImages.waitForImageExists(imageName2);
playExpect(exists, `${imageName2} image not present in the list of images`).toBeTruthy();
playExpect(await updatedImages.getCurrentStatusOfImage(imageName2)).toBe('UNUSED');

const containersPage = await imagesPage.startContainerWithImage(
imageName2,
containerName2,
containerStartParams,
);
await playExpect.poll(async () => containersPage.containerExists(containerName2)).toBeTruthy();
const containerDetails = await containersPage.openContainersDetails(containerName2);
await playExpect(containerDetails.heading).toBeVisible();
await playExpect.poll(async () => containerDetails.getState()).toBe(ContainerState.Running);
});

test('Deploy the container to the crc cluster', async ({ page, navigationBar }) => {
const containerDetailsPage = new ContainerDetailsPage(page, containerName2);
await playExpect(containerDetailsPage.heading).toBeVisible();
const deployToKubernetesPage = await containerDetailsPage.openDeployToKubernetesPage();
await deployToKubernetesPage.deployPod(deployedPodName2, { useKubernetesServices: true, isOpenShiftCluster: true, useOpenShiftRoutes: true }, kubernetesContext);

const podsPage = await navigationBar.openPods();
await playExpect.poll(async () => podsPage.deployedPodExists(deployedPodName2, 'kubernetes')).toBeTruthy();
});
});

test('OpenShift Local extension can be removed', async ({ navigationBar }) => {
await removeExtension(navigationBar);
});
Expand Down

0 comments on commit 38743d0

Please sign in to comment.