From de87c0f3c75e2c387260cf4065f9ccb832b1796f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Suszy=C5=84ski?= Date: Mon, 28 Aug 2023 19:19:09 +0200 Subject: [PATCH] OCP 4.14+ knative service link changes --- test/ui-e2e-tests.sh | 2 -- .../cypress/code/knative/serving/showcase.js | 9 ++++++- test/ui/cypress/code/kubernetes.js | 26 +++++++++++++++++++ .../code/openshift/openshiftConsole.js | 4 +++ .../cypress/e2e/serving/cluster-local.cy.js | 1 + test/ui/cypress/e2e/serving/delete-app.cy.js | 22 ++++++++++++++++ .../e2e/serving/multiple-revisions.cy.js | 4 ++- .../cypress/e2e/serving/scale-to-zero.cy.js | 4 ++- 8 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 test/ui/cypress/code/kubernetes.js create mode 100644 test/ui/cypress/e2e/serving/delete-app.cy.js diff --git a/test/ui-e2e-tests.sh b/test/ui-e2e-tests.sh index b7f5bbfe0e..6f11942838 100755 --- a/test/ui-e2e-tests.sh +++ b/test/ui-e2e-tests.sh @@ -41,9 +41,7 @@ if [ -n "${BUILD_ID:-}" ]; then fi export OCP_VERSION OCP_USERNAME OCP_PASSWORD OCP_LOGIN_PROVIDER CYPRESS_BASE_URL -create_namespaces "${TEST_NAMESPACES[@]}" add_user "$OCP_USERNAME" "$OCP_PASSWORD" -oc adm policy add-role-to-user edit "$OCP_USERNAME" -n "$TEST_NAMESPACE" check_node archive_cypress_artifacts logger.success '🚀 Cluster prepared for testing.' diff --git a/test/ui/cypress/code/knative/serving/showcase.js b/test/ui/cypress/code/knative/serving/showcase.js index d9e3568e8d..10af818198 100644 --- a/test/ui/cypress/code/knative/serving/showcase.js +++ b/test/ui/cypress/code/knative/serving/showcase.js @@ -1,4 +1,5 @@ import Environment from '../../environment' +import Kubernetes from '../../kubernetes' import OpenshiftConsole from '../../openshift/openshiftConsole' const environment = new Environment() @@ -29,7 +30,11 @@ class ShowcaseKservice { .should('have.attr', 'value') .and('include', 'showcase') } - return cy.get('a.co-external-link') + let selector = '.co-external-link--block a' + if (environment.ocpVersion().satisfies('<=4.13')) { + selector = 'a.co-external-link' + } + return cy.get(selector) .last() .scrollIntoView() .should('have.attr', 'href') @@ -137,6 +142,8 @@ class ShowcaseKservice { } removeApp() { + const k8s = new Kubernetes() + k8s.ensureNamespaceExists(this.namespace) this.isServiceDeployed().then((deployed) => { if (deployed) { cy.log("Service is deployed. Removing it.") diff --git a/test/ui/cypress/code/kubernetes.js b/test/ui/cypress/code/kubernetes.js new file mode 100644 index 0000000000..9e507e5ec3 --- /dev/null +++ b/test/ui/cypress/code/kubernetes.js @@ -0,0 +1,26 @@ +import Environment from "./environment"; + +class Kubernetes { + ensureNamespaceExists(namespace) { + const environment = new Environment() + cy.log(`Ensure namespace ${namespace} exists`) + this.doesNamespaceExists(namespace).then((exists) => { + if (!exists) { + cy.exec(`kubectl create ns ${namespace}`) + cy.exec(`oc adm policy add-role-to-user edit "${environment.username()}" -n "${namespace}"`) + } + }) + } + + doesNamespaceExists(namespace) { + return new Cypress.Promise((resolve, _) => { + const cmd = `kubectl get ns ${namespace} -o name` + cy.exec(cmd, {failOnNonZeroExit: false}).then((result) => { + let out = result.stdout.trim() + resolve(out.length > 0) + }) + }) + } +} + +export default Kubernetes diff --git a/test/ui/cypress/code/openshift/openshiftConsole.js b/test/ui/cypress/code/openshift/openshiftConsole.js index 370a9a1a88..b029bd54e0 100644 --- a/test/ui/cypress/code/openshift/openshiftConsole.js +++ b/test/ui/cypress/code/openshift/openshiftConsole.js @@ -1,6 +1,8 @@ import Environment from '../environment' +import Kubernetes from '../kubernetes' const environment = new Environment() +const k8s = new Kubernetes() class OpenshiftConsole { login() { @@ -43,6 +45,8 @@ class OpenshiftConsole { return true }) + k8s.ensureNamespaceExists(namespace) + cy.visit(`/add/ns/${namespace}?view=graph`) cy.get('#content').contains('Add') cy.get('body').then(($body) => { diff --git a/test/ui/cypress/e2e/serving/cluster-local.cy.js b/test/ui/cypress/e2e/serving/cluster-local.cy.js index 68828160f3..6157eada80 100644 --- a/test/ui/cypress/e2e/serving/cluster-local.cy.js +++ b/test/ui/cypress/e2e/serving/cluster-local.cy.js @@ -8,6 +8,7 @@ describe('OCP UI for Serverless Serving', () => { const openshiftConsole = new OpenshiftConsole() const showcaseKsvc = new ShowcaseKservice({ clusterLocal: true, + namespace: 'test-cluster-local' }) it('can deploy a cluster-local service', () => { diff --git a/test/ui/cypress/e2e/serving/delete-app.cy.js b/test/ui/cypress/e2e/serving/delete-app.cy.js new file mode 100644 index 0000000000..62ce046849 --- /dev/null +++ b/test/ui/cypress/e2e/serving/delete-app.cy.js @@ -0,0 +1,22 @@ +import Environment from '../../code/environment' +import ShowcaseKservice from '../../code/knative/serving/showcase' +import OpenshiftConsole from '../../code/openshift/openshiftConsole' + +describe('OCP UI for Serverless Serving', () => { + const environment = new Environment() + const openshiftConsole = new OpenshiftConsole() + const showcaseKsvc = new ShowcaseKservice({ + namespace: 'test-delete-app' + }) + + it('can delete an app with Knative service', () => { + openshiftConsole.login() + showcaseKsvc.removeApp() + showcaseKsvc.deployImage() + showcaseKsvc.removeApp() + showcaseKsvc.deployImage() + showcaseKsvc.url().then((url) => { + showcaseKsvc.makeRequest(url) + }) + }) +}) diff --git a/test/ui/cypress/e2e/serving/multiple-revisions.cy.js b/test/ui/cypress/e2e/serving/multiple-revisions.cy.js index 763cfe40ae..e116dad857 100644 --- a/test/ui/cypress/e2e/serving/multiple-revisions.cy.js +++ b/test/ui/cypress/e2e/serving/multiple-revisions.cy.js @@ -5,7 +5,9 @@ import Environment from '../../code/environment' describe('OCP UI for Serverless Serving', () => { const openshiftConsole = new OpenshiftConsole() - const showcaseKsvc = new ShowcaseKservice() + const showcaseKsvc = new ShowcaseKservice({ + namespace: 'test-multiple-revisions' + }) const environment = new Environment() it('can route traffic to multiple revisions', () => { diff --git a/test/ui/cypress/e2e/serving/scale-to-zero.cy.js b/test/ui/cypress/e2e/serving/scale-to-zero.cy.js index c472f37684..93980c9c5b 100644 --- a/test/ui/cypress/e2e/serving/scale-to-zero.cy.js +++ b/test/ui/cypress/e2e/serving/scale-to-zero.cy.js @@ -4,7 +4,9 @@ import OpenshiftConsole from '../../code/openshift/openshiftConsole' describe('OCP UI for Serverless Serving', () => { const openshiftConsole = new OpenshiftConsole() - const showcaseKsvc = new ShowcaseKservice() + const showcaseKsvc = new ShowcaseKservice({ + namespace: 'test-scale-to-zero' + }) it('can deploy kservice and scale it', () => { openshiftConsole.login()