Skip to content

Commit

Permalink
add sample data cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am committed Nov 11, 2024
1 parent c121643 commit fe0f9f8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ const workspaceName = `test_workspace_analytics_${Math.random()
.substring(7)}`;
let workspaceDescription = 'This is a analytics workspace description.';
let workspaceId;
let datasourceId;
let workspaceFeatures = ['use-case-all'];

const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED');

if (Cypress.env('WORKSPACE_ENABLED')) {
const createWorkspace = (datasourceId) => {
const createWorkspace = (dsId) => {
cy.createWorkspace({
name: workspaceName,
description: workspaceDescription,
Expand All @@ -26,12 +27,12 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
library_write: { users: ['%me%'] },
write: { users: ['%me%'] },
},
dataSources: [datasourceId],
dataSources: [dsId],
},
}).then((value) => {
workspaceId = value;
// load sample data
cy.loadSampleDataForWorkspace('ecommerce', value, datasourceId);
cy.loadSampleDataForWorkspace('ecommerce', value, dsId);
});
};

Expand All @@ -41,7 +42,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
if (MDSEnabled) {
cy.deleteAllDataSources();
cy.createDataSourceNoAuth().then((result) => {
const datasourceId = result[0];
datasourceId = result[0];
expect(datasourceId).to.be.a('string').that.is.not.empty;
createWorkspace(datasourceId);
});
Expand All @@ -52,8 +53,10 @@ if (Cypress.env('WORKSPACE_ENABLED')) {

after(() => {
if (workspaceId) {
cy.removeSampleDataForWorkspace('ecommerce', workspaceId, datasourceId);
cy.deleteWorkspaceById(workspaceId);
}
cy.deleteAllDataSources();
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const workspaceName = `test_workspace_${Math.random()
.substring(7)}`;
let workspaceDescription = 'This is a workspace description.';
let workspaceId;
let datasourceId;
let workspaceFeatures = ['use-case-essentials'];

const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED');
Expand Down Expand Up @@ -41,7 +42,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
if (MDSEnabled) {
cy.deleteAllDataSources();
cy.createDataSourceNoAuth().then((result) => {
const datasourceId = result[0];
datasourceId = result[0];
expect(datasourceId).to.be.a('string').that.is.not.empty;
createWorkspace(datasourceId);
});
Expand All @@ -52,8 +53,10 @@ if (Cypress.env('WORKSPACE_ENABLED')) {

after(() => {
if (workspaceId) {
cy.removeSampleDataForWorkspace('ecommerce', workspaceId, datasourceId);
cy.deleteWorkspaceById(workspaceId);
}
cy.deleteAllDataSources();
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
},
}).then((value) => {
workspaceId = value;
// load sample data
cy.loadSampleDataForWorkspace('ecommerce', value, datasourceId);
});
};

Expand All @@ -54,6 +52,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
if (workspaceId) {
cy.deleteWorkspaceById(workspaceId);
}
cy.deleteAllDataSources();
});

beforeEach(() => {
Expand Down
11 changes: 11 additions & 0 deletions cypress/utils/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,17 @@ Cypress.Commands.add(
}
);

Cypress.Commands.add(
'removeSampleDataForWorkspace',
(type, workspaceId, datasourceId) => {
cy.request({
method: 'DELETE',
headers: { 'osd-xsrf': 'opensearch-dashboards' },
url: `${BASE_PATH}/w/${workspaceId}/api/sample_data/${type}?data_source_id=${datasourceId}`,
});
}
);

Cypress.Commands.add('fleshTenantSettings', () => {
if (Cypress.env('SECURITY_ENABLED')) {
// Use xhr request is good enough to flesh tenant
Expand Down

0 comments on commit fe0f9f8

Please sign in to comment.