From 3374fcce1f8b0623d643a4570a14e4134796b34f Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Tue, 12 Jan 2021 15:34:10 -0800 Subject: [PATCH 01/15] Add command overwrites for 'cy.visit()' and 'cy.request()' to deal with basic auth when security enabled --- cypress/support/commands.js | 47 +++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 08a05549..ea3109e0 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -41,6 +41,45 @@ const { API, INDEX } = require('./constants'); // -- This will overwrite an existing command -- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) +Cypress.Commands.overwrite('visit', (originalFn, url, options) => { + if (Cypress.env('security_enabled')) { + const auth = { + username: 'admin', + password: 'admin', + }; + if (options) { + options.auth = auth; + } else { + options = { auth }; + } + return originalFn(url, options); + } else { + return originalFn(url, options); + } +}); + +Cypress.Commands.overwrite('request', (originalFn, ...args) => { + const defaults = { + auth: { + user: 'admin', + pass: 'admin', + }, + }; + + let options = {}; + if (typeof args[0] === 'object' && args[0] !== null) { + options = Object.assign({}, args[0]); + } else if (args.length === 1) { + [options.url] = args; + } else if (args.length === 2) { + [options.method, options.url] = args; + } else if (args.length === 3) { + [options.method, options.url, options.body] = args; + } + + return originalFn(Object.assign({}, defaults, options)); +}); + Cypress.Commands.add('deleteAllIndices', () => { cy.request('DELETE', `${Cypress.env('elasticsearch')}/*?expand_wildcards=all`); }); @@ -56,17 +95,17 @@ Cypress.Commands.add('deleteAllMonitors', () => { ); }); -Cypress.Commands.add('createMonitor', monitorJSON => { +Cypress.Commands.add('createMonitor', (monitorJSON) => { cy.request('POST', `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}`, monitorJSON); }); -Cypress.Commands.add('createDestination', destinationJSON => { +Cypress.Commands.add('createDestination', (destinationJSON) => { cy.request('POST', `${Cypress.env('elasticsearch')}${API.DESTINATION_BASE}`, destinationJSON); }); -Cypress.Commands.add('createAndExecuteMonitor', monitorJSON => { +Cypress.Commands.add('createAndExecuteMonitor', (monitorJSON) => { cy.request('POST', `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}`, monitorJSON).then( - response => { + (response) => { // response.body is automatically serialized into JSON cy.request( 'POST', From a6c54137b485645f4ac2ed8637c1e15df58871ee Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Tue, 12 Jan 2021 17:14:29 -0800 Subject: [PATCH 02/15] Add env and config parameters regarding security --- cypress.json | 3 ++- cypress/integration/monitor_spec.js | 23 +++++++++++------------ cypress/support/commands.js | 17 ++++++++++------- cypress/support/constants.js | 5 +++++ cypress/support/index.js | 8 ++++++++ 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/cypress.json b/cypress.json index cc889431..f79065ba 100644 --- a/cypress.json +++ b/cypress.json @@ -2,6 +2,7 @@ "defaultCommandTimeout": 10000, "env": { "elasticsearch": "localhost:9200", - "kibana": "localhost:5601" + "kibana": "localhost:5601", + "security_enabled": false } } diff --git a/cypress/integration/monitor_spec.js b/cypress/integration/monitor_spec.js index 9b2f12d6..bbfef54c 100644 --- a/cypress/integration/monitor_spec.js +++ b/cypress/integration/monitor_spec.js @@ -18,11 +18,13 @@ import sampleMonitor from '../fixtures/sample_monitor'; import sampleMonitorWithAlwaysTrueTrigger from '../fixtures/sample_monitor_with_always_true_trigger'; import sampleDestination from '../fixtures/sample_destination_custom_webhook.json'; -const SAMPLE_MONITOR = 'sample_monitor'; -const UPDATED_MONITOR = 'updated_monitor'; -const SAMPLE_MONITOR_WITH_ANOTHER_NAME = 'sample_monitor_with_always_true_trigger'; -const SAMPLE_TRIGGER = 'sample_trigger'; -const SAMPLE_ACTION = 'sample_action'; +const SAMPLE_MONITOR = `sample_monitor-${Cypress.config('unique_number')}`; +const UPDATED_MONITOR = `updated_monitor-${Cypress.config('unique_number')}`; +const SAMPLE_MONITOR_WITH_ANOTHER_NAME = `sample_monitor_with_always_true_trigger-${Cypress.config( + 'unique_number' +)}`; +const SAMPLE_TRIGGER = `sample_trigger-${Cypress.config('unique_number')}`; +const SAMPLE_ACTION = `sample_action-${Cypress.config('unique_number')}`; describe('Monitors', () => { beforeEach(() => { @@ -36,14 +38,10 @@ describe('Monitors', () => { cy.contains('Create monitor', { timeout: 20000 }); }); - describe('can be created', () => { - before(() => { - cy.deleteAllIndices(); - }); - + describe.only('can be created', () => { it('defining by extraction query', () => { // Confirm we loaded empty monitor list - cy.contains('There are no existing monitors'); + // cy.contains('There are no existing monitors'); // Route us to create monitor page cy.contains('Create monitor').click({ force: true }); @@ -73,7 +71,8 @@ describe('Monitors', () => { describe('can be updated', () => { before(() => { - cy.deleteAllIndices(); + //cy.deleteAllIndices(); + sampleMonitor.name = SAMPLE_MONITOR; // Modify the monitor's name to be unique cy.createMonitor(sampleMonitor); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index ea3109e0..9835aa5d 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -13,7 +13,7 @@ * permissions and limitations under the License. */ -const { API, INDEX } = require('./constants'); +const { API, INDEX, ADMIN_AUTH } = require('./constants'); // *********************************************** // This example commands.js shows you how to @@ -42,11 +42,14 @@ const { API, INDEX } = require('./constants'); // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) Cypress.Commands.overwrite('visit', (originalFn, url, options) => { + // Add the basic auth header when security enabled in the Elasticsearch cluster + // https://github.com/cypress-io/cypress/issues/1288 if (Cypress.env('security_enabled')) { const auth = { username: 'admin', password: 'admin', }; + if (options) { options.auth = auth; } else { @@ -58,13 +61,13 @@ Cypress.Commands.overwrite('visit', (originalFn, url, options) => { } }); +// Be able to add default options to cy.request(), https://github.com/cypress-io/cypress/issues/726 Cypress.Commands.overwrite('request', (originalFn, ...args) => { - const defaults = { - auth: { - user: 'admin', - pass: 'admin', - }, - }; + let defaults = {}; + // Add the basic auth header when security enabled in the Elasticsearch cluster + if (Cypress.env('security_enabled')) { + defaults.auth = ADMIN_AUTH; + } let options = {}; if (typeof args[0] === 'object' && args[0] !== null) { diff --git a/cypress/support/constants.js b/cypress/support/constants.js index 3c8f3fa7..8fc0868d 100644 --- a/cypress/support/constants.js +++ b/cypress/support/constants.js @@ -25,3 +25,8 @@ export const API = { }; export const PLUGIN_NAME = 'opendistro-alerting'; + +export const ADMIN_AUTH = { + username: 'admin', + password: 'admin', +}; diff --git a/cypress/support/index.js b/cypress/support/index.js index 65ac9482..dfd2c90c 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -42,3 +42,11 @@ Cypress.on('uncaught:exception', (err) => { return false; } }); + +// Switch the base URL of Elasticsearch when security enabled in the cluster +if (Cypress.env('security_enabled')) { + Cypress.env('elasticsearch', 'https://localhost:9200'); +} + +// Generate a unique number by getting a unix timestamp in milliseconds ('Date' is not applicable in IE 8 and older) +Cypress.config('unique_number', `${Date.now()}`); From 15bcd161b0456549b41c05cc2f53c5dd087b98bc Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Tue, 12 Jan 2021 18:33:19 -0800 Subject: [PATCH 03/15] Add a Cypress command to delete all the monitors that can be ran by admin user --- cypress/integration/monitor_spec.js | 41 ++++++++++++++++++++++++----- cypress/support/commands.js | 41 +++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/cypress/integration/monitor_spec.js b/cypress/integration/monitor_spec.js index bbfef54c..21c404b0 100644 --- a/cypress/integration/monitor_spec.js +++ b/cypress/integration/monitor_spec.js @@ -39,10 +39,11 @@ describe('Monitors', () => { }); describe.only('can be created', () => { - it('defining by extraction query', () => { - // Confirm we loaded empty monitor list - // cy.contains('There are no existing monitors'); + before(() => { + cy.deleteAllMonitors2(); + }); + it('defining by extraction query', () => { // Route us to create monitor page cy.contains('Create monitor').click({ force: true }); @@ -67,11 +68,15 @@ describe('Monitors', () => { // Confirm we can see the created monitor in the list cy.contains(SAMPLE_MONITOR); }); + + after(() => { + cy.deleteMonitorByName(SAMPLE_MONITOR); + }); }); describe('can be updated', () => { before(() => { - //cy.deleteAllIndices(); + cy.deleteAllMonitors2(); sampleMonitor.name = SAMPLE_MONITOR; // Modify the monitor's name to be unique cy.createMonitor(sampleMonitor); }); @@ -101,11 +106,15 @@ describe('Monitors', () => { // Confirm we can see the updated monitor in the list cy.contains(UPDATED_MONITOR); }); + + after(() => { + cy.deleteMonitorByName(UPDATED_MONITOR); + }); }); describe('can be deleted', () => { before(() => { - cy.deleteAllIndices(); + sampleMonitor.name = SAMPLE_MONITOR; cy.createMonitor(sampleMonitor); }); @@ -125,11 +134,17 @@ describe('Monitors', () => { // Confirm we can see an empty monitor list cy.contains('There are no existing monitors'); }); + + // after(() => { + // cy.deleteMonitorByName(SAMPLE_MONITOR); + // }) }); describe('can be searched', () => { before(() => { - cy.deleteAllIndices(); + // Modify the monitor's name to be unique + sampleMonitor.name = SAMPLE_MONITOR; + sampleMonitorWithAlwaysTrueTrigger.name = SAMPLE_MONITOR_WITH_ANOTHER_NAME; // Create 21 monitors so that a monitor will not appear in the first page for (let i = 0; i < 20; i++) { cy.createMonitor(sampleMonitor); @@ -153,11 +168,19 @@ describe('Monitors', () => { expect($tr, 'item').to.contain(SAMPLE_MONITOR_WITH_ANOTHER_NAME); }); }); + + after(() => { + for (let i = 0; i < 20; i++) { + cy.deleteMonitorByName(SAMPLE_MONITOR); + } + cy.deleteMonitorByName(SAMPLE_MONITOR_WITH_ANOTHER_NAME); + }); }); describe('can have triggers', () => { before(() => { - cy.deleteAllIndices(); + //cy.deleteAllIndices(); + sampleMonitor.name = SAMPLE_MONITOR; cy.createMonitor(sampleMonitor); }); @@ -235,5 +258,9 @@ describe('Monitors', () => { // Confirm we can see the new action cy.contains(SAMPLE_ACTION); }); + + // after(() => { + // cy.deleteMonitorByName(SAMPLE_MONITOR); + // }) }); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 9835aa5d..8d208637 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -117,3 +117,44 @@ Cypress.Commands.add('createAndExecuteMonitor', (monitorJSON) => { } ); }); + +Cypress.Commands.add('deleteMonitorByName', (monitorName) => { + const body = { + query: { + match: { + 'monitor.name': { + query: monitorName, + operator: 'and', + }, + }, + }, + }; + cy.request('GET', `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}/_search`, body).then( + (response) => { + // response.body is automatically serialized into JSON + cy.request( + 'DELETE', + `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}/${response.body.hits.hits[0]._id}` + ); + } + ); +}); + +Cypress.Commands.add('deleteAllMonitors2', (monitorName) => { + const body = { + query: { + match_all: {}, + }, + }; + cy.request('GET', `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}/_search`, body).then( + (response) => { + // response.body is automatically serialized into JSON + for (let i = 0; i < response.body.hits.total.value; i++) { + cy.request( + 'DELETE', + `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}/${response.body.hits.hits[i]._id}` + ); + } + } + ); +}); From 0ebb9cc5fb04a8c12b47ae8b62318ecb1df0ac3d Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Tue, 12 Jan 2021 23:53:27 -0800 Subject: [PATCH 04/15] Fix the tests in security enabled cluster --- cypress/integration/alert_spec.js | 75 ++++++++++++++++++++++--- cypress/integration/destination_spec.js | 20 +++++-- cypress/integration/monitor_spec.js | 64 ++++++++------------- cypress/support/commands.js | 51 ++++++++--------- cypress/support/index.js | 3 - 5 files changed, 128 insertions(+), 85 deletions(-) diff --git a/cypress/integration/alert_spec.js b/cypress/integration/alert_spec.js index 3c31b504..efece813 100644 --- a/cypress/integration/alert_spec.js +++ b/cypress/integration/alert_spec.js @@ -34,7 +34,11 @@ describe('Alerts', () => { describe("can be in 'Active' state", () => { before(() => { - cy.deleteAllIndices(); + cy.deleteAllMonitors(); + // Generate a unique number in every test by getting a unix timestamp in milliseconds + Cypress.config('unique_number', `${Date.now()}`); + // Modify the monitor's name to be unique + sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`; cy.createMonitor(sampleMonitorWithAlwaysTrueTrigger); }); @@ -45,6 +49,11 @@ describe('Alerts', () => { // Reload the page cy.reload(); + // Type in monitor name in search box to filter out the alert + cy.get(`input[type="search"]`) + .focus() + .type(`${Cypress.config('unique_number')}`); + // Confirm we can see one and only alert in Active state cy.get('tbody > tr').should(($tr) => { expect($tr, '1 row').to.have.length(1); @@ -55,16 +64,25 @@ describe('Alerts', () => { describe("can be in 'Acknowledged' state", () => { before(() => { - cy.deleteAllIndices(); + cy.deleteAllMonitors(); + Cypress.config('unique_number', `${Date.now()}`); + // Modify the monitor's name to be unique + sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`; cy.createAndExecuteMonitor(sampleMonitorWithAlwaysTrueTrigger); }); it('by clicking the button in Dashboard', () => { + // Type in monitor name in search box to filter out the alert + cy.get(`input[type="search"]`) + .focus() + .type(`${Cypress.config('unique_number')}`); + //Confirm there is an active alert cy.contains('Active'); // Select checkbox for the existing alert - cy.get('input[data-test-subj^="checkboxSelectRow-"]').click({ force: true }); + // There may be multiple alerts in the cluster, first() is used to get the active alert + cy.get('input[data-test-subj^="checkboxSelectRow-"]').first().click({ force: true }); // Click Acknowledge button cy.get('button').contains('Acknowledge').click({ force: true }); @@ -76,17 +94,26 @@ describe('Alerts', () => { describe("can be in 'Completed' state", () => { before(() => { - cy.deleteAllIndices(); + cy.deleteAllMonitors(); cy.createMonitor(sampleMonitorWithAlwaysTrueTrigger); + Cypress.config('unique_number', `${Date.now()}`); + // Modify the monitor's name to be unique + sampleMonitorWorkflow.name += `-${Cypress.config('unique_number')}`; cy.createAndExecuteMonitor(sampleMonitorWorkflow); }); it('when the trigger condition is not met after met once', () => { + // Type in monitor name in search box to filter the alerts + cy.get(`input[type="search"]`) + .focus() + .type(`${Cypress.config('unique_number')}`); + //Confirm there is an active alert cy.contains('Active'); // Select checkbox for the existing alert - cy.get('input[data-test-subj^="checkboxSelectRow-"]').click({ force: true }); + // There may be multiple alerts in the cluster, first() is used to get the active alert + cy.get('input[data-test-subj^="checkboxSelectRow-"]').first().click({ force: true }); // Click Monitors button to route to Monitors tab cy.get('button').contains('Monitors').click({ force: true }); @@ -101,6 +128,7 @@ describe('Alerts', () => { }); // Select checkbox for the existing monitor + // There are 2 monitors in the cluster, first() is used to get the first one cy.get('input[data-test-subj^="checkboxSelectRow-"]').first().click({ force: true }); // Click Actions button to open the actions menu @@ -131,27 +159,48 @@ describe('Alerts', () => { describe("can be in 'Error' state", () => { before(() => { - cy.deleteAllIndices(); + cy.deleteAllMonitors(); // modify the JSON object to make an error alert when executing the monitor sampleMonitorWithAlwaysTrueTrigger.triggers[0].actions = [ { name: '', destination_id: '', message_template: { source: '' } }, ]; + Cypress.config('unique_number', `${Date.now()}`); + // Modify the monitor's name to be unique + sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`; cy.createAndExecuteMonitor(sampleMonitorWithAlwaysTrueTrigger); }); it('by using a wrong destination', () => { + // Type in monitor name in search box to filter out the alert + cy.get(`input[type="search"]`) + .focus() + .type(`${Cypress.config('unique_number')}`); + // Confirm we can see the alert is in 'Error' state cy.contains('Error'); }); }); - describe("can be in 'Deleted' state", () => { + describe.only("can be in 'Deleted' state", () => { before(() => { - cy.deleteAllIndices(); + Cypress.config('unique_number', `${Date.now()}`); + // Modify the monitor's name to be unique + sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`; cy.createAndExecuteMonitor(sampleMonitorWithAlwaysTrueTrigger); }); it('by deleting the monitor', () => { + // Type in monitor name in search box to filter out the alert + cy.get(`input[type="search"]`) + .focus() + .type(`${Cypress.config('unique_number')}`); + + // Confirm we can see only one alert in the list + cy.get('tbody > tr').should(($tr) => { + expect($tr, '1 row').to.have.length(1); + expect($tr, 'item').to.contain(SAMPLE_MONITOR_TO_BE_DELETED); + }); + //Confirm there is an active alert cy.contains('Active'); @@ -176,8 +225,18 @@ describe('Alerts', () => { // Click Dashboard button to route to Dashboard tab cy.get('button').contains('Dashboard').click({ force: true }); + // Type in monitor name in search box to filter out the alert + cy.get(`input[type="search"]`) + .focus() + .type(`${Cypress.config('unique_number')}`); + // Confirm we can see the alert is in 'Deleted' state cy.contains('Deleted'); }); }); + + after(() => { + // Delete all existing monitors + cy.deleteAllMonitors(); + }); }); diff --git a/cypress/integration/destination_spec.js b/cypress/integration/destination_spec.js index 5e100a52..1b0a5401 100644 --- a/cypress/integration/destination_spec.js +++ b/cypress/integration/destination_spec.js @@ -14,7 +14,7 @@ */ import { PLUGIN_NAME } from '../support/constants'; -import sampleDestination from '../fixtures/sample_destination_custom_webhook.json'; +import sampleDestination from '../fixtures/sample_destination_custom_webhook'; import sampleDestinationChime from '../fixtures/sample_destination_chime'; const SAMPLE_DESTINATION = 'sample_destination'; @@ -36,7 +36,7 @@ describe('Destinations', () => { describe('can be created', () => { before(() => { - cy.deleteAllIndices(); + cy.deleteAllDestinations(); }); it('with a custom webhook', () => { @@ -65,7 +65,7 @@ describe('Destinations', () => { describe('can be updated', () => { before(() => { - cy.deleteAllIndices(); + cy.deleteAllDestinations(); cy.createDestination(sampleDestination); }); @@ -77,7 +77,10 @@ describe('Destinations', () => { cy.get('button').contains('Edit').click({ force: true }); // Wait for input to load and then type in the destination name - cy.get('input[name="name"]').focus().clear().type(UPDATED_DESTINATION, { force: true }); + cy.get('input[name="name"]') + .should('have.value', SAMPLE_DESTINATION) + .clear() + .type(UPDATED_DESTINATION, { force: true }); // Click the create button cy.get('button').contains('Update').click({ force: true }); @@ -89,7 +92,7 @@ describe('Destinations', () => { describe('can be deleted', () => { before(() => { - cy.deleteAllIndices(); + cy.deleteAllDestinations(); cy.createDestination(sampleDestination); }); @@ -110,7 +113,7 @@ describe('Destinations', () => { describe('can be searched', () => { before(() => { - cy.deleteAllIndices(); + cy.deleteAllDestinations(); // Create 21 destinations so that a monitor will not appear in the first page for (let i = 0; i < 20; i++) { cy.createDestination(sampleDestination); @@ -135,4 +138,9 @@ describe('Destinations', () => { }); }); }); + + after(() => { + // Delete all existing destinations + cy.deleteAllDestinations(); + }); }); diff --git a/cypress/integration/monitor_spec.js b/cypress/integration/monitor_spec.js index 21c404b0..aa49ef0b 100644 --- a/cypress/integration/monitor_spec.js +++ b/cypress/integration/monitor_spec.js @@ -18,13 +18,11 @@ import sampleMonitor from '../fixtures/sample_monitor'; import sampleMonitorWithAlwaysTrueTrigger from '../fixtures/sample_monitor_with_always_true_trigger'; import sampleDestination from '../fixtures/sample_destination_custom_webhook.json'; -const SAMPLE_MONITOR = `sample_monitor-${Cypress.config('unique_number')}`; -const UPDATED_MONITOR = `updated_monitor-${Cypress.config('unique_number')}`; -const SAMPLE_MONITOR_WITH_ANOTHER_NAME = `sample_monitor_with_always_true_trigger-${Cypress.config( - 'unique_number' -)}`; -const SAMPLE_TRIGGER = `sample_trigger-${Cypress.config('unique_number')}`; -const SAMPLE_ACTION = `sample_action-${Cypress.config('unique_number')}`; +const SAMPLE_MONITOR = 'sample_monitor'; +const UPDATED_MONITOR = 'updated_monitor'; +const SAMPLE_MONITOR_WITH_ANOTHER_NAME = 'sample_monitor_with_always_true_trigger'; +const SAMPLE_TRIGGER = 'sample_trigger'; +const SAMPLE_ACTION = 'sample_action'; describe('Monitors', () => { beforeEach(() => { @@ -38,12 +36,15 @@ describe('Monitors', () => { cy.contains('Create monitor', { timeout: 20000 }); }); - describe.only('can be created', () => { + describe('can be created', () => { before(() => { - cy.deleteAllMonitors2(); + cy.deleteAllMonitors(); }); it('defining by extraction query', () => { + // Confirm we loaded empty monitor list + cy.contains('There are no existing monitors'); + // Route us to create monitor page cy.contains('Create monitor').click({ force: true }); @@ -68,16 +69,11 @@ describe('Monitors', () => { // Confirm we can see the created monitor in the list cy.contains(SAMPLE_MONITOR); }); - - after(() => { - cy.deleteMonitorByName(SAMPLE_MONITOR); - }); }); describe('can be updated', () => { before(() => { - cy.deleteAllMonitors2(); - sampleMonitor.name = SAMPLE_MONITOR; // Modify the monitor's name to be unique + cy.deleteAllMonitors(); cy.createMonitor(sampleMonitor); }); @@ -92,7 +88,10 @@ describe('Monitors', () => { cy.contains('Edit').click({ force: true }); // Wait for input to load and then type in the new monitor name - cy.get('input[name="name"]').focus().clear().type(UPDATED_MONITOR, { force: true }); + cy.get('input[name="name"]') + .should('have.value', SAMPLE_MONITOR) + .clear() + .type(UPDATED_MONITOR, { force: true }); // Click Update button cy.get('button').contains('Update').last().click({ force: true }); @@ -106,15 +105,11 @@ describe('Monitors', () => { // Confirm we can see the updated monitor in the list cy.contains(UPDATED_MONITOR); }); - - after(() => { - cy.deleteMonitorByName(UPDATED_MONITOR); - }); }); describe('can be deleted', () => { before(() => { - sampleMonitor.name = SAMPLE_MONITOR; + cy.deleteAllMonitors(); cy.createMonitor(sampleMonitor); }); @@ -134,17 +129,11 @@ describe('Monitors', () => { // Confirm we can see an empty monitor list cy.contains('There are no existing monitors'); }); - - // after(() => { - // cy.deleteMonitorByName(SAMPLE_MONITOR); - // }) }); describe('can be searched', () => { before(() => { - // Modify the monitor's name to be unique - sampleMonitor.name = SAMPLE_MONITOR; - sampleMonitorWithAlwaysTrueTrigger.name = SAMPLE_MONITOR_WITH_ANOTHER_NAME; + cy.deleteAllMonitors(); // Create 21 monitors so that a monitor will not appear in the first page for (let i = 0; i < 20; i++) { cy.createMonitor(sampleMonitor); @@ -168,19 +157,12 @@ describe('Monitors', () => { expect($tr, 'item').to.contain(SAMPLE_MONITOR_WITH_ANOTHER_NAME); }); }); - - after(() => { - for (let i = 0; i < 20; i++) { - cy.deleteMonitorByName(SAMPLE_MONITOR); - } - cy.deleteMonitorByName(SAMPLE_MONITOR_WITH_ANOTHER_NAME); - }); }); describe('can have triggers', () => { before(() => { - //cy.deleteAllIndices(); - sampleMonitor.name = SAMPLE_MONITOR; + cy.deleteAllMonitors(); + cy.deleteAllDestinations(); cy.createMonitor(sampleMonitor); }); @@ -258,9 +240,11 @@ describe('Monitors', () => { // Confirm we can see the new action cy.contains(SAMPLE_ACTION); }); + }); - // after(() => { - // cy.deleteMonitorByName(SAMPLE_MONITOR); - // }) + after(() => { + // Delete all existing monitors and destinations + cy.deleteAllMonitors(); + cy.deleteAllDestinations(); }); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 8d208637..78c196a5 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -45,15 +45,10 @@ Cypress.Commands.overwrite('visit', (originalFn, url, options) => { // Add the basic auth header when security enabled in the Elasticsearch cluster // https://github.com/cypress-io/cypress/issues/1288 if (Cypress.env('security_enabled')) { - const auth = { - username: 'admin', - password: 'admin', - }; - if (options) { - options.auth = auth; + options.auth = ADMIN_AUTH; } else { - options = { auth }; + options = { auth: ADMIN_AUTH }; } return originalFn(url, options); } else { @@ -64,7 +59,7 @@ Cypress.Commands.overwrite('visit', (originalFn, url, options) => { // Be able to add default options to cy.request(), https://github.com/cypress-io/cypress/issues/726 Cypress.Commands.overwrite('request', (originalFn, ...args) => { let defaults = {}; - // Add the basic auth header when security enabled in the Elasticsearch cluster + // Add the basic authentication header when security enabled in the Elasticsearch cluster if (Cypress.env('security_enabled')) { defaults.auth = ADMIN_AUTH; } @@ -83,21 +78,6 @@ Cypress.Commands.overwrite('request', (originalFn, ...args) => { return originalFn(Object.assign({}, defaults, options)); }); -Cypress.Commands.add('deleteAllIndices', () => { - cy.request('DELETE', `${Cypress.env('elasticsearch')}/*?expand_wildcards=all`); -}); - -Cypress.Commands.add('deleteAllMonitors', () => { - const body = { - query: { exists: { field: 'monitor' } }, - }; - cy.request( - 'POST', - `${Cypress.env('elasticsearch')}/${INDEX.OPENDISTRO_ALERTING_CONFIG}/_delete_by_query`, - body - ); -}); - Cypress.Commands.add('createMonitor', (monitorJSON) => { cy.request('POST', `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}`, monitorJSON); }); @@ -109,7 +89,6 @@ Cypress.Commands.add('createDestination', (destinationJSON) => { Cypress.Commands.add('createAndExecuteMonitor', (monitorJSON) => { cy.request('POST', `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}`, monitorJSON).then( (response) => { - // response.body is automatically serialized into JSON cy.request( 'POST', `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}/${response.body._id}/_execute` @@ -131,7 +110,6 @@ Cypress.Commands.add('deleteMonitorByName', (monitorName) => { }; cy.request('GET', `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}/_search`, body).then( (response) => { - // response.body is automatically serialized into JSON cy.request( 'DELETE', `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}/${response.body.hits.hits[0]._id}` @@ -140,15 +118,17 @@ Cypress.Commands.add('deleteMonitorByName', (monitorName) => { ); }); -Cypress.Commands.add('deleteAllMonitors2', (monitorName) => { +Cypress.Commands.add('deleteAllMonitors', () => { const body = { + size: 200, query: { - match_all: {}, + exists: { + field: 'monitor', + }, }, }; cy.request('GET', `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}/_search`, body).then( (response) => { - // response.body is automatically serialized into JSON for (let i = 0; i < response.body.hits.total.value; i++) { cy.request( 'DELETE', @@ -158,3 +138,18 @@ Cypress.Commands.add('deleteAllMonitors2', (monitorName) => { } ); }); + +Cypress.Commands.add('deleteAllDestinations', () => { + cy.request('GET', `${Cypress.env('elasticsearch')}${API.DESTINATION_BASE}?size=200`).then( + (response) => { + for (let i = 0; i < response.body.totalDestinations; i++) { + cy.request( + 'DELETE', + `${Cypress.env('elasticsearch')}${API.DESTINATION_BASE}/${ + response.body.destinations[i].id + }` + ); + } + } + ); +}); diff --git a/cypress/support/index.js b/cypress/support/index.js index dfd2c90c..6bb32158 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -47,6 +47,3 @@ Cypress.on('uncaught:exception', (err) => { if (Cypress.env('security_enabled')) { Cypress.env('elasticsearch', 'https://localhost:9200'); } - -// Generate a unique number by getting a unix timestamp in milliseconds ('Date' is not applicable in IE 8 and older) -Cypress.config('unique_number', `${Date.now()}`); From 9c00c3cba3a59201d16587fd10a41acf4399d136 Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Wed, 13 Jan 2021 00:03:16 -0800 Subject: [PATCH 05/15] Add a cleanup before a test for alerts --- cypress/integration/alert_spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cypress/integration/alert_spec.js b/cypress/integration/alert_spec.js index efece813..ce3a47b0 100644 --- a/cypress/integration/alert_spec.js +++ b/cypress/integration/alert_spec.js @@ -183,6 +183,7 @@ describe('Alerts', () => { describe.only("can be in 'Deleted' state", () => { before(() => { + cy.deleteAllMonitors(); Cypress.config('unique_number', `${Date.now()}`); // Modify the monitor's name to be unique sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`; From 3a4b8fb4d0cbfdfafccaee2a45cfbf7e0ec80870 Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Wed, 13 Jan 2021 00:10:43 -0800 Subject: [PATCH 06/15] Remove 'only' added during developing --- cypress/integration/alert_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/alert_spec.js b/cypress/integration/alert_spec.js index ce3a47b0..0170181e 100644 --- a/cypress/integration/alert_spec.js +++ b/cypress/integration/alert_spec.js @@ -181,7 +181,7 @@ describe('Alerts', () => { }); }); - describe.only("can be in 'Deleted' state", () => { + describe("can be in 'Deleted' state", () => { before(() => { cy.deleteAllMonitors(); Cypress.config('unique_number', `${Date.now()}`); From b4da3970ca3694383f89d60d75438ae982293f2f Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Wed, 13 Jan 2021 13:11:54 -0800 Subject: [PATCH 07/15] Fix the tests in security enabled cluster --- ..._7.1.json => sample_monitor_workflow.json} | 6 +- cypress/integration/alert_spec.js | 67 ++++++------------- cypress/support/commands.js | 16 +++++ 3 files changed, 41 insertions(+), 48 deletions(-) rename cypress/fixtures/{sample_monitor_workflow_7.1.json => sample_monitor_workflow.json} (77%) diff --git a/cypress/fixtures/sample_monitor_workflow_7.1.json b/cypress/fixtures/sample_monitor_workflow.json similarity index 77% rename from cypress/fixtures/sample_monitor_workflow_7.1.json rename to cypress/fixtures/sample_monitor_workflow.json index f67840b0..a00ed04e 100644 --- a/cypress/fixtures/sample_monitor_workflow_7.1.json +++ b/cypress/fixtures/sample_monitor_workflow.json @@ -10,10 +10,10 @@ "inputs": [ { "search": { - "indices": [".*"], + "indices": ["test*"], "query": { "query": { - "term": { "monitor.type": "monitor" } + "match_all": {} } } } @@ -25,7 +25,7 @@ "severity": "3", "condition": { "script": { - "source": "ctx.results[0].hits.total.value > 1", + "source": "ctx.results[0].hits.total.value < 1", "lang": "painless" } }, diff --git a/cypress/integration/alert_spec.js b/cypress/integration/alert_spec.js index 0170181e..d669233a 100644 --- a/cypress/integration/alert_spec.js +++ b/cypress/integration/alert_spec.js @@ -15,10 +15,9 @@ import { PLUGIN_NAME } from '../support/constants'; import sampleMonitorWithAlwaysTrueTrigger from '../fixtures/sample_monitor_with_always_true_trigger'; -import sampleMonitorWorkflow from '../fixtures/sample_monitor_workflow_7.1.json'; +import sampleMonitorWorkflow from '../fixtures/sample_monitor_workflow'; const SAMPLE_MONITOR_TO_BE_DELETED = 'sample_monitor_with_always_true_trigger'; -const SAMPLE_MONITOR_WORKFLOW = 'sample_monitor_workflow'; describe('Alerts', () => { beforeEach(() => { @@ -37,7 +36,7 @@ describe('Alerts', () => { cy.deleteAllMonitors(); // Generate a unique number in every test by getting a unix timestamp in milliseconds Cypress.config('unique_number', `${Date.now()}`); - // Modify the monitor's name to be unique + // Modify the monitor name to be unique sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`; cy.createMonitor(sampleMonitorWithAlwaysTrueTrigger); }); @@ -66,7 +65,7 @@ describe('Alerts', () => { before(() => { cy.deleteAllMonitors(); Cypress.config('unique_number', `${Date.now()}`); - // Modify the monitor's name to be unique + // Modify the monitor name to be unique sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`; cy.createAndExecuteMonitor(sampleMonitorWithAlwaysTrueTrigger); }); @@ -95,66 +94,44 @@ describe('Alerts', () => { describe("can be in 'Completed' state", () => { before(() => { cy.deleteAllMonitors(); - cy.createMonitor(sampleMonitorWithAlwaysTrueTrigger); + // Delete the indices for testing + cy.deleteIndexByName('test*'); Cypress.config('unique_number', `${Date.now()}`); - // Modify the monitor's name to be unique + // Modify the monitor name to be unique sampleMonitorWorkflow.name += `-${Cypress.config('unique_number')}`; cy.createAndExecuteMonitor(sampleMonitorWorkflow); }); it('when the trigger condition is not met after met once', () => { - // Type in monitor name in search box to filter the alerts + // Type in monitor name in search box to filter out the alert cy.get(`input[type="search"]`) .focus() .type(`${Cypress.config('unique_number')}`); - //Confirm there is an active alert + // Confirm there is an active alert cy.contains('Active'); - // Select checkbox for the existing alert - // There may be multiple alerts in the cluster, first() is used to get the active alert - cy.get('input[data-test-subj^="checkboxSelectRow-"]').first().click({ force: true }); - - // Click Monitors button to route to Monitors tab - cy.get('button').contains('Monitors').click({ force: true }); - - // Type in monitor name in search box - cy.get(`input[type="search"]`).focus().type(SAMPLE_MONITOR_TO_BE_DELETED); - - // Confirm we filtered down to our one and only monitor - cy.get('tbody > tr').should(($tr) => { - expect($tr, '1 row').to.have.length(1); - expect($tr, 'item').to.contain(SAMPLE_MONITOR_TO_BE_DELETED); - }); - - // Select checkbox for the existing monitor - // There are 2 monitors in the cluster, first() is used to get the first one - cy.get('input[data-test-subj^="checkboxSelectRow-"]').first().click({ force: true }); - - // Click Actions button to open the actions menu - cy.contains('Actions').click({ force: true }); + // The trigger condition is: there is no documents in the indices 'test*', so create one to complete the alert + // Create an index + cy.createIndexByName('test'); - // Click the Delete button - cy.contains('Delete').click({ force: true }); - - // Clear the text in the search box - cy.get(`input[type="search"]`).focus().clear(); - - // Confirm we can see only one monitor in the list - cy.get('tbody > tr').should(($tr) => { - expect($tr, '1 row').to.have.length(1); - expect($tr, 'item').to.contain(SAMPLE_MONITOR_WORKFLOW); - }); + // Insert a document + cy.insertDocumentToIndex('test', 1, {}); // Wait for 1 minute cy.wait(60000); - // Click Dashboard button to route to Dashboard tab - cy.get('button').contains('Dashboard').click({ force: true }); + // Reload the page + cy.reload(); // Confirm we can see the alert is in 'Completed' state cy.contains('Completed'); }); + + after(() => { + // Delete the indices for testing + cy.deleteIndexByName('test*'); + }); }); describe("can be in 'Error' state", () => { @@ -165,7 +142,7 @@ describe('Alerts', () => { { name: '', destination_id: '', message_template: { source: '' } }, ]; Cypress.config('unique_number', `${Date.now()}`); - // Modify the monitor's name to be unique + // Modify the monitor name to be unique sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`; cy.createAndExecuteMonitor(sampleMonitorWithAlwaysTrueTrigger); }); @@ -185,7 +162,7 @@ describe('Alerts', () => { before(() => { cy.deleteAllMonitors(); Cypress.config('unique_number', `${Date.now()}`); - // Modify the monitor's name to be unique + // Modify the monitor name to be unique sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`; cy.createAndExecuteMonitor(sampleMonitorWithAlwaysTrueTrigger); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 78c196a5..b78b4921 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -153,3 +153,19 @@ Cypress.Commands.add('deleteAllDestinations', () => { } ); }); + +Cypress.Commands.add('createIndexByName', (indexName) => { + cy.request('PUT', `${Cypress.env('elasticsearch')}/${indexName}`); +}); + +Cypress.Commands.add('deleteIndexByName', (indexName) => { + cy.request('DELETE', `${Cypress.env('elasticsearch')}/${indexName}`); +}); + +Cypress.Commands.add('insertDocumentToIndex', (indexName, documentId, documentBody) => { + cy.request( + 'PUT', + `${Cypress.env('elasticsearch')}/${indexName}/_doc/${documentId}`, + documentBody + ); +}); From 8dfe388c7c1d40c603fae424a7b4d04d8cbbb320 Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Wed, 13 Jan 2021 15:59:30 -0800 Subject: [PATCH 08/15] Fix the tests in alert spec --- cypress/integration/alert_spec.js | 38 +++++++------------------ cypress/integration/destination_spec.js | 1 + 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/cypress/integration/alert_spec.js b/cypress/integration/alert_spec.js index d669233a..a6fe3d75 100644 --- a/cypress/integration/alert_spec.js +++ b/cypress/integration/alert_spec.js @@ -94,7 +94,7 @@ describe('Alerts', () => { describe("can be in 'Completed' state", () => { before(() => { cy.deleteAllMonitors(); - // Delete the indices for testing + // Delete the testing indices cy.deleteIndexByName('test*'); Cypress.config('unique_number', `${Date.now()}`); // Modify the monitor name to be unique @@ -124,12 +124,17 @@ describe('Alerts', () => { // Reload the page cy.reload(); + // Type in monitor name in search box to filter out the alert + cy.get(`input[type="search"]`) + .focus() + .type(`${Cypress.config('unique_number')}`); + // Confirm we can see the alert is in 'Completed' state cy.contains('Completed'); }); after(() => { - // Delete the indices for testing + // Delete the testing indices cy.deleteIndexByName('test*'); }); }); @@ -173,35 +178,14 @@ describe('Alerts', () => { .focus() .type(`${Cypress.config('unique_number')}`); - // Confirm we can see only one alert in the list - cy.get('tbody > tr').should(($tr) => { - expect($tr, '1 row').to.have.length(1); - expect($tr, 'item').to.contain(SAMPLE_MONITOR_TO_BE_DELETED); - }); - //Confirm there is an active alert cy.contains('Active'); - // Click Monitors button to route to Monitors tab - cy.get('button').contains('Monitors').click({ force: true }); - - // Confirm we can see a monitor in the list - cy.contains(SAMPLE_MONITOR_TO_BE_DELETED); - - // Select checkbox for the existing monitor - cy.get('input[data-test-subj^="checkboxSelectRow-"]').click({ force: true }); - - // Click Actions button to open the actions menu - cy.contains('Actions').click({ force: true }); - - // Click the Delete button - cy.contains('Delete').click({ force: true }); - - // Confirm we can see an empty monitor list - cy.contains('There are no existing monitors'); + // Delete all existing monitors + cy.deleteAllMonitors(); - // Click Dashboard button to route to Dashboard tab - cy.get('button').contains('Dashboard').click({ force: true }); + // Reload the page + cy.reload(); // Type in monitor name in search box to filter out the alert cy.get(`input[type="search"]`) diff --git a/cypress/integration/destination_spec.js b/cypress/integration/destination_spec.js index 1b0a5401..ef1b9775 100644 --- a/cypress/integration/destination_spec.js +++ b/cypress/integration/destination_spec.js @@ -77,6 +77,7 @@ describe('Destinations', () => { cy.get('button').contains('Edit').click({ force: true }); // Wait for input to load and then type in the destination name + // should() is used to wait for input loading before clearing cy.get('input[name="name"]') .should('have.value', SAMPLE_DESTINATION) .clear() From 77b2333c0ea10b1cfa8e4a42df91f6b25e121dd3 Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Wed, 13 Jan 2021 16:06:26 -0800 Subject: [PATCH 09/15] temp: test github workflow --- .github/workflows/cypress-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index 7c60262b..cd4fbd98 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -1,6 +1,6 @@ name: E2E Cypress tests on: - push: + pull_request: branches: - master From 7561a821f40ae35e09e73fb4c52b3e72e92ad947 Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Wed, 13 Jan 2021 16:51:19 -0800 Subject: [PATCH 10/15] ignore 4o4 status code in reqeusts of deleting monitors or destinations --- cypress/support/commands.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index b78b4921..9a239642 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -13,7 +13,7 @@ * permissions and limitations under the License. */ -const { API, INDEX, ADMIN_AUTH } = require('./constants'); +const { API, ADMIN_AUTH } = require('./constants'); // *********************************************** // This example commands.js shows you how to @@ -127,21 +127,32 @@ Cypress.Commands.add('deleteAllMonitors', () => { }, }, }; - cy.request('GET', `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}/_search`, body).then( - (response) => { + cy.request({ + method: 'GET', + url: `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}/_search`, + failOnStatusCode: false, // In case there is no alerting config index in cluster, where the status code is 404 + body, + }).then((response) => { + if (response.status === 200) { for (let i = 0; i < response.body.hits.total.value; i++) { cy.request( 'DELETE', `${Cypress.env('elasticsearch')}${API.MONITOR_BASE}/${response.body.hits.hits[i]._id}` ); } + } else { + cy.log('Failed to get all monitors.', response); } - ); + }); }); Cypress.Commands.add('deleteAllDestinations', () => { - cy.request('GET', `${Cypress.env('elasticsearch')}${API.DESTINATION_BASE}?size=200`).then( - (response) => { + cy.request({ + method: 'GET', + url: `${Cypress.env('elasticsearch')}${API.DESTINATION_BASE}?size=200`, + failOnStatusCode: false, // In case there is no alerting config index in cluster, where the status code is 404 + }).then((response) => { + if (response.status === 200) { for (let i = 0; i < response.body.totalDestinations; i++) { cy.request( 'DELETE', @@ -150,8 +161,10 @@ Cypress.Commands.add('deleteAllDestinations', () => { }` ); } + } else { + cy.log('Failed to get all destinations.', response); } - ); + }); }); Cypress.Commands.add('createIndexByName', (indexName) => { From 83e432b813ae45dd0245b248689e9010fd3174d0 Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Wed, 13 Jan 2021 17:07:32 -0800 Subject: [PATCH 11/15] modify a comment --- cypress/integration/alert_spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cypress/integration/alert_spec.js b/cypress/integration/alert_spec.js index a6fe3d75..a95651df 100644 --- a/cypress/integration/alert_spec.js +++ b/cypress/integration/alert_spec.js @@ -111,7 +111,8 @@ describe('Alerts', () => { // Confirm there is an active alert cy.contains('Active'); - // The trigger condition is: there is no documents in the indices 'test*', so create one to complete the alert + // The trigger condition is: there is no document in the indices 'test*' + // The following commands create a document in the index to complete the alert // Create an index cy.createIndexByName('test'); From 0ed962ff045e69cb505524ac66d4b5c5691896f3 Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Wed, 13 Jan 2021 17:11:08 -0800 Subject: [PATCH 12/15] Change the trigger of the workflow back --- .github/workflows/cypress-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index cd4fbd98..7c60262b 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -1,6 +1,6 @@ name: E2E Cypress tests on: - pull_request: + push: branches: - master From 6b29b71ed38fb09da4cf9eb8a391468d51860ab9 Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Wed, 13 Jan 2021 17:31:28 -0800 Subject: [PATCH 13/15] Change the name of testing index --- cypress/fixtures/sample_monitor_workflow.json | 2 +- cypress/integration/alert_spec.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cypress/fixtures/sample_monitor_workflow.json b/cypress/fixtures/sample_monitor_workflow.json index a00ed04e..dbbaf62f 100644 --- a/cypress/fixtures/sample_monitor_workflow.json +++ b/cypress/fixtures/sample_monitor_workflow.json @@ -10,7 +10,7 @@ "inputs": [ { "search": { - "indices": ["test*"], + "indices": ["alerting*"], "query": { "query": { "match_all": {} diff --git a/cypress/integration/alert_spec.js b/cypress/integration/alert_spec.js index a95651df..e31ecbf9 100644 --- a/cypress/integration/alert_spec.js +++ b/cypress/integration/alert_spec.js @@ -17,7 +17,7 @@ import { PLUGIN_NAME } from '../support/constants'; import sampleMonitorWithAlwaysTrueTrigger from '../fixtures/sample_monitor_with_always_true_trigger'; import sampleMonitorWorkflow from '../fixtures/sample_monitor_workflow'; -const SAMPLE_MONITOR_TO_BE_DELETED = 'sample_monitor_with_always_true_trigger'; +const TESTING_INDEX = 'alerting_test'; describe('Alerts', () => { beforeEach(() => { @@ -94,8 +94,8 @@ describe('Alerts', () => { describe("can be in 'Completed' state", () => { before(() => { cy.deleteAllMonitors(); - // Delete the testing indices - cy.deleteIndexByName('test*'); + // Delete the target indices defined in 'sample_monitor_workflow.json' + cy.deleteIndexByName('alerting*'); Cypress.config('unique_number', `${Date.now()}`); // Modify the monitor name to be unique sampleMonitorWorkflow.name += `-${Cypress.config('unique_number')}`; @@ -111,10 +111,10 @@ describe('Alerts', () => { // Confirm there is an active alert cy.contains('Active'); - // The trigger condition is: there is no document in the indices 'test*' + // The trigger condition is: there is no document in the indices 'alerting*' // The following commands create a document in the index to complete the alert // Create an index - cy.createIndexByName('test'); + cy.createIndexByName(TESTING_INDEX); // Insert a document cy.insertDocumentToIndex('test', 1, {}); @@ -135,8 +135,8 @@ describe('Alerts', () => { }); after(() => { - // Delete the testing indices - cy.deleteIndexByName('test*'); + // Delete the testing index + cy.deleteIndexByName(TESTING_INDEX); }); }); From 0e8c9e181ad966013ab29312cfdf347e81399e93 Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Wed, 13 Jan 2021 17:32:00 -0800 Subject: [PATCH 14/15] test github workflow --- .github/workflows/cypress-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index 7c60262b..cd4fbd98 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -1,6 +1,6 @@ name: E2E Cypress tests on: - push: + pull_request: branches: - master From ee78315a5653e9a6a454c2bfd10c397b20f28deb Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Wed, 13 Jan 2021 17:32:26 -0800 Subject: [PATCH 15/15] change the cypress workflow back --- .github/workflows/cypress-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index cd4fbd98..7c60262b 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -1,6 +1,6 @@ name: E2E Cypress tests on: - pull_request: + push: branches: - master