Skip to content

Commit

Permalink
[GEN-1918]: add CRUD tests for instr. rules (#1943)
Browse files Browse the repository at this point in the history
This pull request includes changes to improve the accessibility and
functionality of the frontend web application. The primary focus is on
ensuring CRUD operations for custom resources in the cluster.

### Cypress End-to-End Tests:
*
[`frontend/webapp/cypress/e2e/06-rules.cy.ts`](diffhunk://#diff-aba373cc082245b95ade17d84a085f3f05f6feccbc7d9ee511cb3cc6b4927dd6R1-R101):
Added tests for CRUD operations on instrumentation rules CRDs, ensuring
the cluster state is managed correctly.

These changes collectively enhance the application's accessibility,
testability, and ensure robust end-to-end testing for critical
functionalities.
  • Loading branch information
BenElferink authored Dec 9, 2024
1 parent f636461 commit f421299
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions frontend/webapp/cypress/e2e/06-rules.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { ROUTES } from '../../utils/constants/routes';

// The number of CRDs that exist in the cluster before running any tests should be 0.
// Tests will fail if you have existing CRDs in the cluster.
// If you have to run tests locally, make sure to clean up the cluster before running the tests.

describe('Instrumentation Rules CRUD', () => {
const namespace = 'odigos-system';
const crdName = 'instrumentationrules.odigos.io';
const noResourcesFound = `No resources found in ${namespace} namespace.`;

beforeEach(() => {
cy.intercept('/graphql').as('gql');
});

it('Should create a CRD in the cluster', () => {
cy.visit(ROUTES.OVERVIEW);

cy.exec(`kubectl get ${crdName} -n ${namespace} | awk 'NR>1 {print $1}'`).then((crdListBefore) => {
expect(crdListBefore.stderr).to.eq(noResourcesFound);
expect(crdListBefore.stdout).to.eq('');

const crdIdsBefore = crdListBefore.stdout.split('\n').filter((str) => !!str);
expect(crdIdsBefore.length).to.eq(0);

cy.get('[data-id=add-entity]').click();
cy.get('[data-id=add-rule]').click();
cy.get('[data-id=modal-Add-Instrumentation-Rule]').should('exist');
cy.get('button').contains('DONE').click();

cy.wait('@gql').then(() => {
cy.exec(`kubectl get ${crdName} -n ${namespace} | awk 'NR>1 {print $1}'`).then((crdListAfter) => {
expect(crdListAfter.stderr).to.eq('');
expect(crdListAfter.stdout).to.not.be.empty;

const crdIdsAfter = crdListAfter.stdout.split('\n').filter((str) => !!str);
expect(crdIdsAfter.length).to.eq(1);
});
});
});
});

it('Should update the CRD in the cluster', () => {
cy.visit(ROUTES.OVERVIEW);

const node = cy.contains('[data-id=rule-0]', 'PayloadCollection');
expect(node).to.exist;
node.click();

cy.get('[data-id=drawer]').should('exist');
cy.get('button[data-id=drawer-edit]').click();
cy.get('input[data-id=title]').clear().type('Cypress Test');
cy.get('button[data-id=drawer-save]').click();
cy.get('button[data-id=drawer-close]').click();

cy.wait('@gql').then(() => {
cy.exec(`kubectl get ${crdName} -n ${namespace} | awk 'NR>1 {print $1}'`).then((crdList) => {
expect(crdList.stderr).to.eq('');
expect(crdList.stdout).to.not.be.empty;

const crdIds = crdList.stdout.split('\n').filter((str) => !!str);
expect(crdIds.length).to.eq(1);

cy.exec(`kubectl get ${crdName} ${crdIds[0]} -n ${namespace} -o json`).then((crd) => {
expect(crd.stderr).to.eq('');
expect(crd.stdout).to.not.be.empty;

const parsed = JSON.parse(crd.stdout);
const { spec } = parsed?.items?.[0] || parsed || {};

expect(spec).to.not.be.empty;
expect(spec.ruleName).to.eq('Cypress Test');
});
});
});
});

it('Should delete the CRD from the cluster', () => {
cy.visit(ROUTES.OVERVIEW);

const node = cy.contains('[data-id=rule-0]', 'PayloadCollection');
expect(node).to.exist;
node.click();

cy.get('[data-id=drawer]').should('exist');
cy.get('button[data-id=drawer-edit]').click();
cy.get('button[data-id=drawer-delete]').click();
cy.get('[data-id=modal]').contains('Delete rule').should('exist');
cy.get('button[data-id=approve]').click();

cy.wait('@gql').then(() => {
cy.exec(`kubectl get ${crdName} -n ${namespace} | awk 'NR>1 {print $1}'`).then((crdList) => {
expect(crdList.stderr).to.eq(noResourcesFound);
expect(crdList.stdout).to.eq('');

const crdIds = crdList.stdout.split('\n').filter((str) => !!str);
expect(crdIds.length).to.eq(0);
});
});
});
});

0 comments on commit f421299

Please sign in to comment.