From ebc8d010bf3e406a3f0d1ca425ec6ff8e96dfe43 Mon Sep 17 00:00:00 2001 From: superaleks <47592680+superaleks@users.noreply.github.com> Date: Fri, 6 May 2022 10:19:20 +0200 Subject: [PATCH] [bitnami/grafana] Improve Grafana Helm Chart test code to use fixtures (#10013) * Added antiflake pipeline Signed-off-by: alukic * Diversified the pipeline Signed-off-by: alukic * Make a change to trigger TKG Signed-off-by: alukic * Replaced FIPS with normal AKS Signed-off-by: alukic * Refactoring Signed-off-by: alukic * Change the workflow Signed-off-by: alukic * Increased timeout due to some flakiness noticed Signed-off-by: alukic --- .vib/grafana/cypress/cypress.json | 6 +- .../cypress/cypress/fixtures/apikeys.json | 5 + .../cypress/cypress/fixtures/dashboards.json | 6 ++ .../cypress/cypress/fixtures/datasources.json | 5 + .../cypress/cypress/fixtures/panels.json | 6 ++ .../cypress/cypress/fixtures/smtps.json | 7 ++ .../cypress/cypress/fixtures/users.json | 6 ++ .../cypress/integration/grafana_spec.js | 95 ++++++++++--------- 8 files changed, 90 insertions(+), 46 deletions(-) create mode 100644 .vib/grafana/cypress/cypress/fixtures/apikeys.json create mode 100644 .vib/grafana/cypress/cypress/fixtures/dashboards.json create mode 100644 .vib/grafana/cypress/cypress/fixtures/datasources.json create mode 100644 .vib/grafana/cypress/cypress/fixtures/panels.json create mode 100644 .vib/grafana/cypress/cypress/fixtures/smtps.json create mode 100644 .vib/grafana/cypress/cypress/fixtures/users.json diff --git a/.vib/grafana/cypress/cypress.json b/.vib/grafana/cypress/cypress.json index 490d35112..43c90a38b 100644 --- a/.vib/grafana/cypress/cypress.json +++ b/.vib/grafana/cypress/cypress.json @@ -1,7 +1,7 @@ -{ +{ "baseUrl": "http://localhost/", - "pageLoadTimeout": 120000, - "defaultCommandTimeout":40000, + "pageLoadTimeout": 150000, + "defaultCommandTimeout": 50000, "env": { "username": "test_admin", "password": "ComplicatedPassword123!4" diff --git a/.vib/grafana/cypress/cypress/fixtures/apikeys.json b/.vib/grafana/cypress/cypress/fixtures/apikeys.json new file mode 100644 index 000000000..0266be1c5 --- /dev/null +++ b/.vib/grafana/cypress/cypress/fixtures/apikeys.json @@ -0,0 +1,5 @@ +{ + "newAPIKey": { + "name": "test_api_key" + } +} diff --git a/.vib/grafana/cypress/cypress/fixtures/dashboards.json b/.vib/grafana/cypress/cypress/fixtures/dashboards.json new file mode 100644 index 000000000..8f7dcc2d0 --- /dev/null +++ b/.vib/grafana/cypress/cypress/fixtures/dashboards.json @@ -0,0 +1,6 @@ +{ + "newDashboard": { + "title": "Test Dashboard title", + "uploadedTitle": "New Uploaded Dashboard" + } +} diff --git a/.vib/grafana/cypress/cypress/fixtures/datasources.json b/.vib/grafana/cypress/cypress/fixtures/datasources.json new file mode 100644 index 000000000..29e30a702 --- /dev/null +++ b/.vib/grafana/cypress/cypress/fixtures/datasources.json @@ -0,0 +1,5 @@ +{ + "newDatasource": { + "name": "Prometheus" + } +} diff --git a/.vib/grafana/cypress/cypress/fixtures/panels.json b/.vib/grafana/cypress/cypress/fixtures/panels.json new file mode 100644 index 000000000..b858a0eae --- /dev/null +++ b/.vib/grafana/cypress/cypress/fixtures/panels.json @@ -0,0 +1,6 @@ +{ + "newPanel": { + "title": "Test panel title", + "description": "Test panel description" + } +} diff --git a/.vib/grafana/cypress/cypress/fixtures/smtps.json b/.vib/grafana/cypress/cypress/fixtures/smtps.json new file mode 100644 index 000000000..8942806dc --- /dev/null +++ b/.vib/grafana/cypress/cypress/fixtures/smtps.json @@ -0,0 +1,7 @@ +{ + "newSMTPConfig": { + "email": "test@smtp.com", + "name": "test_smtp", + "user": "smtp_user" + } +} diff --git a/.vib/grafana/cypress/cypress/fixtures/users.json b/.vib/grafana/cypress/cypress/fixtures/users.json new file mode 100644 index 000000000..9b23642f9 --- /dev/null +++ b/.vib/grafana/cypress/cypress/fixtures/users.json @@ -0,0 +1,6 @@ +{ + "newUser": { + "userName": "Invited test user", + "email": "test@email.com" + } +} diff --git a/.vib/grafana/cypress/cypress/integration/grafana_spec.js b/.vib/grafana/cypress/cypress/integration/grafana_spec.js index 7435fa68c..c1e02847d 100644 --- a/.vib/grafana/cypress/cypress/integration/grafana_spec.js +++ b/.vib/grafana/cypress/cypress/integration/grafana_spec.js @@ -9,31 +9,33 @@ it('allows user to log in and log out', () => { }); it('allows creating a dashboard with a panel', () => { - const PANEL_TITLE = 'Test panel title'; - const PANEL_DESCRIPTION = 'Test panel description'; - const DASHBOARD_TITLE = 'Dashboard title'; - cy.login(); cy.visit('dashboard/new'); cy.contains('button', 'Add a new panel').click(); - cy.get('[value*="Panel Title"]').clear().type(`${PANEL_TITLE}.${random}`); - cy.get('textarea#description-text-area').type( - `${PANEL_DESCRIPTION}.${random}` - ); - cy.contains('button', 'Apply').click(); + cy.fixture('panels').then((panel) => { + cy.get('[value*="Panel Title"]') + .clear() + .type(`${panel.newPanel.title} ${random}`); + cy.get('textarea#description-text-area').type( + `${panel.newPanel.description} ${random}` + ); + cy.contains('button', 'Apply').click(); + cy.contains('.panel-title', `${panel.newPanel.title} ${random}`); + }); - cy.contains('.panel-title', PANEL_TITLE); cy.get('[aria-label*="Save dashboard"]').click(); cy.get('button[aria-label*="Close dialogue"]'); - cy.get('[name*="title"]').clear().type(`${DASHBOARD_TITLE}.${random}`); + cy.fixture('dashboards').then((dashboard) => { + cy.get('[name*="title"]') + .clear() + .type(`${dashboard.newDashboard.title} ${random}`); + }); cy.get('[type*="submit"]').click(); verifySuccesOfAction(); }); it('checks if it is possible to upload a dashboard as JSON file', () => { - const DASHBOARD_TITLE = 'New Test dashboard'; - cy.login(); cy.visit('dashboard/import'); cy.contains('label', 'Upload JSON').click(); @@ -41,39 +43,40 @@ it('checks if it is possible to upload a dashboard as JSON file', () => { 'cypress/fixtures/test-dashboard.json', { force: true } ); - cy.get('[data-testid*="data-testid-import-dashboard-title"]') - .clear() - .type(`${DASHBOARD_TITLE}.${random}`); - cy.get('[data-testid*="data-testid-import-dashboard-submit"]').click(); - cy.visit('dashboards'); - cy.contains('div', DASHBOARD_TITLE); + + cy.fixture('dashboards').then((dashboard) => { + cy.get('[data-testid*="data-testid-import-dashboard-title"]') + .clear() + .type(`${dashboard.newDashboard.uploadedTitle} ${random}`); + cy.get('[data-testid*="data-testid-import-dashboard-submit"]').click(); + cy.visit('dashboards'); + cy.contains('div', `${dashboard.newDashboard.uploadedTitle} ${random}`); + }); }); it('allows inviting a user', () => { - const TEST_EMAIL_ADDRESS = 'test@email.com'; - const INVITE_USER_NAME = 'Invited test user'; - cy.login(); cy.visit('/org/users/invite'); - cy.get('[name*="loginOrEmail"]') - .clear() - .type(`${TEST_EMAIL_ADDRESS}.${random}`); - cy.get('[name*="name"]').clear().type(`${INVITE_USER_NAME}.${random}`); + cy.fixture('users').then((user) => { + cy.get('[name*="loginOrEmail"]') + .clear() + .type(`${user.newUser.email}.${random}`); + cy.get('[name*="name"]').clear().type(`${user.newUser.userName}.${random}`); + }); + cy.get('[name*="sendEmail"]').click({ force: true }); cy.get('[type*="submit"]').click(); verifySuccesOfAction(); }); it('checks if smtp is configured', () => { - const SMTP_ADDRESS = 'test@smtp.com'; - const SMTP_NAME = 'test_smtp'; - const SMTP_USER = 'smtp_user'; - cy.login(); cy.visit('admin/settings'); - cy.contains('td', SMTP_ADDRESS); - cy.contains('td', SMTP_NAME); - cy.contains('td', SMTP_USER); + cy.fixture('smtps').then((smtp) => { + cy.contains('td', smtp.newSMTPConfig.email); + cy.contains('td', smtp.newSMTPConfig.name); + cy.contains('td', smtp.newSMTPConfig.user); + }); }); it('checks if plugin page is showing plugins', () => { @@ -83,15 +86,19 @@ it('checks if plugin page is showing plugins', () => { }); it('checks if it is possible to create and delete a data source', () => { - const DATASOURCE = 'Prometheus'; - cy.login(); cy.visit('/datasources/new'); - cy.get('input[placeholder*="Filter by name or type"]').type(DATASOURCE); - cy.get(`button[aria-label*="Add data source ${DATASOURCE}"]`).click(); - cy.contains('div', 'Datasource added'); - cy.visit('/datasources'); - cy.contains('a', DATASOURCE).click({ force: true }); + cy.fixture('datasources').then((datasource) => { + cy.get('input[placeholder*="Filter by name or type"]').type( + datasource.newDatasource.name + ); + cy.get( + `button[aria-label*="Add data source ${datasource.newDatasource.name}"]` + ).click(); + cy.contains('div', 'Datasource added'); + cy.visit('/datasources'); + cy.contains('a', datasource.newDatasource.name).click({ force: true }); + }); cy.contains('button', 'Delete').click(); cy.contains('div', 'Are you sure you want to delete'); cy.get('button[aria-label*="Confirm Modal Danger Button"]').click(); @@ -99,14 +106,16 @@ it('checks if it is possible to create and delete a data source', () => { }); it('checks if an API key can be added and deleted', () => { - const API_KEY_NAME = 'test_api_key'; - cy.login(); cy.visit('org/apikeys'); cy.get( '[data-testid*="data-testid Call to action button New API key"]' ).click(); - cy.get('input[placeholder*="Name"]').type(`${API_KEY_NAME}.${random}`); + cy.fixture('apikeys').then((apikey) => { + cy.get('input[placeholder*="Name"]').type( + `${apikey.newAPIKey.name}.${random}` + ); + }); cy.contains('button', 'Add').click({ force: true }); cy.contains('h2', 'API Key Created'); cy.get('button[aria-label*="Close dialogue"]').click();