-
Notifications
You must be signed in to change notification settings - Fork 36
OCPNETUI-59: Add Cypress E2E tests for Service and Route endpoint health #472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lkladnit
wants to merge
4
commits into
main
Choose a base branch
from
ocpnetui-59
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1dbe5a8
OCPNETUI-59: Add Cypress E2E tests for Service and Route endpoint health
lkladnit dc3990a
fix: address CodeRabbit and lint feedback for OCPNETUI-59 tests
lkladnit 1d31732
fix: add probes and NetworkPolicy to endpoint-health fixture
lkladnit d3ad82d
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| # Deterministic health fixtures for Services / Routes list E2E. | ||
| # | ||
| # Healthy: real Deployment + Service (selector-based EndpointSlices created by the control plane) | ||
| # Degraded / Down: selector-less Services + handcrafted EndpointSlices (scale-down is flaky for Degraded) | ||
| # ExternalName: no endpoints → Unknown | ||
| # Route: points at the Healthy service for Backend health assertions | ||
| --- | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: eph-healthy-ingress | ||
| labels: | ||
| app: eph-healthy | ||
| spec: | ||
| podSelector: | ||
| matchLabels: | ||
| app: eph-healthy | ||
| policyTypes: | ||
| - Ingress | ||
| ingress: | ||
| - ports: | ||
| - protocol: TCP | ||
| port: 8080 | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: eph-healthy | ||
| labels: | ||
| app: eph-healthy | ||
| spec: | ||
| replicas: 1 | ||
| selector: | ||
| matchLabels: | ||
| app: eph-healthy | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: eph-healthy | ||
| spec: | ||
| automountServiceAccountToken: false | ||
| containers: | ||
| - name: hello | ||
| image: quay.io/openshifttest/hello-openshift:1.2.0 | ||
| ports: | ||
| - containerPort: 8080 | ||
| livenessProbe: | ||
| httpGet: | ||
| path: / | ||
| port: 8080 | ||
| initialDelaySeconds: 5 | ||
| periodSeconds: 10 | ||
| readinessProbe: | ||
| httpGet: | ||
| path: / | ||
| port: 8080 | ||
| initialDelaySeconds: 1 | ||
| periodSeconds: 5 | ||
| resources: | ||
| limits: | ||
| cpu: 50m | ||
| memory: 64Mi | ||
| requests: | ||
| cpu: 10m | ||
| memory: 32Mi | ||
| securityContext: | ||
| allowPrivilegeEscalation: false | ||
| capabilities: | ||
| drop: | ||
| - ALL | ||
| readOnlyRootFilesystem: true | ||
| runAsNonRoot: true | ||
| seccompProfile: | ||
| type: RuntimeDefault | ||
| securityContext: | ||
| runAsNonRoot: true | ||
| seccompProfile: | ||
| type: RuntimeDefault | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: eph-healthy | ||
| labels: | ||
| app: eph-healthy | ||
| spec: | ||
| selector: | ||
| app: eph-healthy | ||
| ports: | ||
| - name: http | ||
| port: 80 | ||
| targetPort: 8080 | ||
| --- | ||
| apiVersion: route.openshift.io/v1 | ||
| kind: Route | ||
| metadata: | ||
| name: eph-healthy | ||
| labels: | ||
| app: eph-healthy | ||
| spec: | ||
| to: | ||
| kind: Service | ||
| name: eph-healthy | ||
| port: | ||
| targetPort: http | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: eph-degraded | ||
| labels: | ||
| app: eph-degraded | ||
| spec: | ||
| ports: | ||
| - name: http | ||
| port: 80 | ||
| targetPort: 8080 | ||
| --- | ||
| apiVersion: discovery.k8s.io/v1 | ||
| kind: EndpointSlice | ||
| metadata: | ||
| name: eph-degraded-slice | ||
| labels: | ||
| kubernetes.io/service-name: eph-degraded | ||
| app: eph-degraded | ||
| addressType: IPv4 | ||
| ports: | ||
| - name: http | ||
| protocol: TCP | ||
| port: 8080 | ||
| endpoints: | ||
| - addresses: | ||
| - 192.0.2.1 | ||
| conditions: | ||
| ready: true | ||
| - addresses: | ||
| - 192.0.2.2 | ||
| conditions: | ||
| ready: false | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: eph-down | ||
| labels: | ||
| app: eph-down | ||
| spec: | ||
| ports: | ||
| - name: http | ||
| port: 80 | ||
| targetPort: 8080 | ||
| --- | ||
| apiVersion: discovery.k8s.io/v1 | ||
| kind: EndpointSlice | ||
| metadata: | ||
| name: eph-down-slice | ||
| labels: | ||
| kubernetes.io/service-name: eph-down | ||
| app: eph-down | ||
| addressType: IPv4 | ||
| ports: | ||
| - name: http | ||
| protocol: TCP | ||
| port: 8080 | ||
| endpoints: | ||
| - addresses: | ||
| - 192.0.2.10 | ||
| conditions: | ||
| ready: false | ||
| - addresses: | ||
| - 192.0.2.11 | ||
| conditions: | ||
| ready: false | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: eph-external | ||
| labels: | ||
| app: eph-external | ||
| spec: | ||
| type: ExternalName | ||
| externalName: example.com | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import Loggable = Cypress.Loggable; | ||
| import Shadow = Cypress.Shadow; | ||
| import Timeoutable = Cypress.Timeoutable; | ||
| import Withinable = Cypress.Withinable; | ||
|
|
||
| export const MINUTE = 60 * 1000; | ||
|
|
||
| export const itemFilter = '[data-test-id="item-filter"]'; | ||
| export const resourceRow = '[data-test-rows="resource-row"]'; | ||
|
|
||
| type EndpointHealthStatus = 'Degraded' | 'Down' | 'Healthy' | 'Unknown'; | ||
|
|
||
| const assertOcSuccess = ( | ||
| result: { | ||
| code: number; | ||
| stderr: string; | ||
| stdout: string; | ||
| }, | ||
| message: string, | ||
| ): void => { | ||
| // On some macOS/Electron setups Cypress omits `code` even for successful commands. | ||
| const code = result.code ?? 0; | ||
| expect(code, message).to.eq(0); | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| const healthAriaLabel = (status: EndpointHealthStatus, ready?: number, total?: number): string => { | ||
| if (status === 'Unknown') { | ||
| return 'Unknown: endpoint readiness not available'; | ||
| } | ||
| return `${status}: ${ready} of ${total} endpoints ready`; | ||
| }; | ||
|
|
||
| declare global { | ||
| namespace Cypress { | ||
| interface Chainable { | ||
| applyFixture(fixturePath: string, namespace: string): Chainable; | ||
| assertEndpointHealth( | ||
| name: string, | ||
| status: EndpointHealthStatus, | ||
| ready?: number, | ||
| total?: number, | ||
| ): Chainable; | ||
| byTestID( | ||
| selector: string, | ||
| options?: Partial<Loggable & Shadow & Timeoutable & Withinable>, | ||
| ): Chainable; | ||
| deleteNamespace(namespace: string): Chainable; | ||
| ensureNamespace(namespace: string): Chainable; | ||
| filterByName(name: string): Chainable; | ||
| getResourceRow(name: string): Chainable; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Cypress.Commands.add( | ||
| 'byTestID', | ||
| (selector: string, options?: Partial<Loggable & Shadow & Timeoutable & Withinable>) => | ||
| cy.get(`[data-test="${selector}"]`, options), | ||
| ); | ||
|
|
||
| Cypress.Commands.add('ensureNamespace', (namespace: string) => { | ||
| cy.exec(`oc create namespace ${namespace}`, { failOnNonZeroExit: false }).then((result) => { | ||
| const code = result.code ?? 0; | ||
| const alreadyExists = /AlreadyExists/i.test(`${result.stderr || ''}${result.stdout || ''}`); | ||
| if (code !== 0 && !alreadyExists) { | ||
| expect(code, 'failed to create namespace').to.eq(0); | ||
| } | ||
| }); | ||
| cy.exec(`oc project ${namespace}`, { failOnNonZeroExit: false }).then((result) => { | ||
| assertOcSuccess(result, 'failed to select namespace'); | ||
| }); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| Cypress.Commands.add('deleteNamespace', (namespace: string) => { | ||
| cy.exec(`oc delete namespace ${namespace} --ignore-not-found=true --wait=false`, { | ||
| failOnNonZeroExit: false, | ||
| timeout: 2 * MINUTE, | ||
| }); | ||
| }); | ||
|
|
||
| Cypress.Commands.add('applyFixture', (fixturePath: string, namespace: string) => { | ||
| cy.exec(`oc apply -n ${namespace} -f "${fixturePath}"`, { | ||
| failOnNonZeroExit: false, | ||
| timeout: 2 * MINUTE, | ||
| }).then((result) => { | ||
| assertOcSuccess(result, 'oc apply failed'); | ||
| }); | ||
| }); | ||
|
|
||
| Cypress.Commands.add('filterByName', (name: string) => { | ||
| cy.get(itemFilter, { timeout: MINUTE }).should('be.visible').clear(); | ||
| cy.get(itemFilter, { timeout: MINUTE }).type(name); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| Cypress.Commands.add('getResourceRow', (name: string) => | ||
| cy.contains(resourceRow, name, { timeout: MINUTE }).should('exist'), | ||
| ); | ||
|
|
||
| Cypress.Commands.add( | ||
| 'assertEndpointHealth', | ||
| (name: string, status: EndpointHealthStatus, ready?: number, total?: number) => { | ||
| const ariaLabel = healthAriaLabel(status, ready, total); | ||
|
|
||
| cy.getResourceRow(name).within(() => { | ||
| cy.get(`[aria-label="${ariaLabel}"]`, { timeout: MINUTE }).should('exist'); | ||
|
|
||
| if (status === 'Unknown') { | ||
| cy.contains('Unknown').should('exist'); | ||
| } else if (ready !== undefined && total !== undefined) { | ||
| cy.contains(`${ready}/${total}`).should('exist'); | ||
| } | ||
| }); | ||
| }, | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.