Skip to content

Commit

Permalink
OCP 4.14+ knative service link changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Aug 29, 2023
1 parent 020c674 commit de87c0f
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 5 deletions.
2 changes: 0 additions & 2 deletions test/ui-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
9 changes: 8 additions & 1 deletion test/ui/cypress/code/knative/serving/showcase.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Environment from '../../environment'
import Kubernetes from '../../kubernetes'
import OpenshiftConsole from '../../openshift/openshiftConsole'

const environment = new Environment()
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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.")
Expand Down
26 changes: 26 additions & 0 deletions test/ui/cypress/code/kubernetes.js
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions test/ui/cypress/code/openshift/openshiftConsole.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Environment from '../environment'
import Kubernetes from '../kubernetes'

const environment = new Environment()
const k8s = new Kubernetes()

class OpenshiftConsole {
login() {
Expand Down Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions test/ui/cypress/e2e/serving/cluster-local.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
22 changes: 22 additions & 0 deletions test/ui/cypress/e2e/serving/delete-app.cy.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
4 changes: 3 additions & 1 deletion test/ui/cypress/e2e/serving/multiple-revisions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 3 additions & 1 deletion test/ui/cypress/e2e/serving/scale-to-zero.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit de87c0f

Please sign in to comment.