Skip to content

Commit

Permalink
manual backport opensearch-project#251
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <[email protected]>
  • Loading branch information
wanglam committed Feb 28, 2024
1 parent 4eb3548 commit 1feace2
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/plugins/workspace/server/integration_tests/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const testWorkspace: WorkspaceAttribute = {
describe('workspace service', () => {
let root: ReturnType<typeof osdTestServer.createRoot>;
let opensearchServer: osdTestServer.TestOpenSearchUtils;
let osd: osdTestServer.TestOpenSearchDashboardsUtils;
beforeAll(async () => {
const { startOpenSearch, startOpenSearchDashboards } = osdTestServer.createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
Expand All @@ -37,8 +38,8 @@ describe('workspace service', () => {
},
});
opensearchServer = await startOpenSearch();
const startOSDResp = await startOpenSearchDashboards();
root = startOSDResp.root;
osd = await startOpenSearchDashboards();
root = osd.root;
}, 30000);
afterAll(async () => {
await root.shutdown();
Expand All @@ -52,15 +53,17 @@ describe('workspace service', () => {
page: 1,
})
.expect(200);
await Promise.all(
listResult.body.result.workspaces.map((item: WorkspaceAttribute) =>
// workspace delete API will not able to delete reserved workspace
// to clean up the test data, change it saved objects delete API
osdTestServer.request
.delete(root, `/api/saved_objects/${WORKSPACE_TYPE}/${item.id}`)
.expect(200)
const savedObjectsRepository = osd.coreStart.savedObjects.createInternalRepository([
WORKSPACE_TYPE,
]);
await expect(
Promise.all(
listResult.body.result.workspaces.map((item: WorkspaceAttribute) =>
// this will delete reserved workspace
savedObjectsRepository.delete(WORKSPACE_TYPE, item.id)
)
)
);
).resolves.toBeInstanceOf(Array);
});
it('create', async () => {
await osdTestServer.request
Expand Down Expand Up @@ -229,7 +232,8 @@ describe('workspace service', () => {
page: 1,
})
.expect(200);
expect(listResult.body.result.total).toEqual(2);
// Global and Management workspace will be created by default after workspace list API called.
expect(listResult.body.result.total).toEqual(4);
});
it('unable to perform operations on workspace by calling saved objects APIs', async () => {
const result = await osdTestServer.request
Expand Down Expand Up @@ -291,7 +295,8 @@ describe('workspace service', () => {
})
.expect(200);
expect(findResult.body.total).toEqual(0);
expect(listResult.body.result.total).toEqual(1);
// Global and Management workspace will be created by default after workspace list API called.
expect(listResult.body.result.total).toEqual(3);
});
});
});

0 comments on commit 1feace2

Please sign in to comment.