From 44966cc60c29a53400194e3238093c9dba53fc5a Mon Sep 17 00:00:00 2001 From: Daniel Villanueva Date: Tue, 11 Feb 2025 12:46:55 +0100 Subject: [PATCH] test(e2e): added deploying to crc cluster test case Signed-off-by: Daniel Villanueva --- tests/src/openshift-local-extension.spec.ts | 126 ++++++++++++++++++-- 1 file changed, 118 insertions(+), 8 deletions(-) diff --git a/tests/src/openshift-local-extension.spec.ts b/tests/src/openshift-local-extension.spec.ts index 2c563f1..8ecf5d4 100644 --- a/tests/src/openshift-local-extension.spec.ts +++ b/tests/src/openshift-local-extension.spec.ts @@ -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. @@ -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'; @@ -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 }), }); @@ -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', () => { @@ -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 () => { @@ -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(); @@ -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(); + //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(); + const tasksManager = page.getByTitle("Tasks manager") + 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 + }); + + 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); });