Skip to content

Commit

Permalink
[Snapshot & Restore] Move repo types tests into on-prem describe block
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliacech committed Feb 16, 2022
1 parent bb46473 commit ec6c256
Showing 1 changed file with 51 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,56 +257,59 @@ describe('[Snapshot and Restore API Routes] Repositories', () => {
path: addBasePath('repository_types'),
};

it('returns module types and on-prem types if no repository plugins returned from ES', async () => {
nodesInfoFn.mockResolvedValue({ nodes: { testNodeId: { plugins: [] } } });

const expectedResponse = [...MODULE_REPOSITORY_TYPES, ...ON_PREM_REPOSITORY_TYPES];
await expect(router.runRequest(mockRequest)).resolves.toEqual({ body: expectedResponse });
});

it('returns module types and on-prem types with any repository plugins returned from ES', async () => {
const pluginNames = Object.keys(REPOSITORY_PLUGINS_MAP);
const pluginTypes = Object.entries(REPOSITORY_PLUGINS_MAP).map(([key, value]) => value);

const mockEsResponse = {
nodes: { testNodeId: { plugins: [...pluginNames.map((key) => ({ name: key }))] } },
};
nodesInfoFn.mockResolvedValue(mockEsResponse);

const expectedResponse = [
...MODULE_REPOSITORY_TYPES,
...ON_PREM_REPOSITORY_TYPES,
...pluginTypes,
];
await expect(router.runRequest(mockRequest)).resolves.toEqual({ body: expectedResponse });
});

it(`doesn't return non-repository plugins returned from ES`, async () => {
const pluginNames = ['foo-plugin', 'bar-plugin'];
const mockEsResponse = {
nodes: { testNodeId: { plugins: [...pluginNames.map((key) => ({ name: key }))] } },
};
nodesInfoFn.mockResolvedValue(mockEsResponse);

const expectedResponse = [...MODULE_REPOSITORY_TYPES, ...ON_PREM_REPOSITORY_TYPES];

await expect(router.runRequest(mockRequest)).resolves.toEqual({ body: expectedResponse });
});

it(`doesn't return repository plugins that are not installed on all nodes`, async () => {
const dataNodePlugins = ['repository-hdfs'];
const masterNodePlugins: string[] = [];
const mockEsResponse = {
nodes: {
dataNode: { plugins: [...dataNodePlugins.map((key) => ({ name: key }))] },
masterNode: { plugins: [...masterNodePlugins.map((key) => ({ name: key }))] },
},
};
nodesInfoFn.mockResolvedValue(mockEsResponse);
// TODO add Cloud specific tests for repo types
describe('on prem', () => {
it('returns module types and on-prem types if no repository plugins returned from ES', async () => {
nodesInfoFn.mockResolvedValue({ nodes: { testNodeId: { plugins: [] } } });

const expectedResponse = [...MODULE_REPOSITORY_TYPES, ...ON_PREM_REPOSITORY_TYPES];
await expect(router.runRequest(mockRequest)).resolves.toEqual({ body: expectedResponse });
});

it('returns module types and on-prem types with any repository plugins returned from ES', async () => {
const pluginNames = Object.keys(REPOSITORY_PLUGINS_MAP);
const pluginTypes = Object.entries(REPOSITORY_PLUGINS_MAP).map(([key, value]) => value);

const mockEsResponse = {
nodes: { testNodeId: { plugins: [...pluginNames.map((key) => ({ name: key }))] } },
};
nodesInfoFn.mockResolvedValue(mockEsResponse);

const expectedResponse = [
...MODULE_REPOSITORY_TYPES,
...ON_PREM_REPOSITORY_TYPES,
...pluginTypes,
];
await expect(router.runRequest(mockRequest)).resolves.toEqual({ body: expectedResponse });
});

it(`doesn't return non-repository plugins returned from ES`, async () => {
const pluginNames = ['foo-plugin', 'bar-plugin'];
const mockEsResponse = {
nodes: { testNodeId: { plugins: [...pluginNames.map((key) => ({ name: key }))] } },
};
nodesInfoFn.mockResolvedValue(mockEsResponse);

const expectedResponse = [...MODULE_REPOSITORY_TYPES, ...ON_PREM_REPOSITORY_TYPES];

await expect(router.runRequest(mockRequest)).resolves.toEqual({ body: expectedResponse });
});

it(`doesn't return repository plugins that are not installed on all nodes`, async () => {
const dataNodePlugins = ['repository-hdfs'];
const masterNodePlugins: string[] = [];
const mockEsResponse = {
nodes: {
dataNode: { plugins: [...dataNodePlugins.map((key) => ({ name: key }))] },
masterNode: { plugins: [...masterNodePlugins.map((key) => ({ name: key }))] },
},
};
nodesInfoFn.mockResolvedValue(mockEsResponse);

const expectedResponse = [...MODULE_REPOSITORY_TYPES, ...ON_PREM_REPOSITORY_TYPES];
const expectedResponse = [...MODULE_REPOSITORY_TYPES, ...ON_PREM_REPOSITORY_TYPES];

await expect(router.runRequest(mockRequest)).resolves.toEqual({ body: expectedResponse });
await expect(router.runRequest(mockRequest)).resolves.toEqual({ body: expectedResponse });
});
});

it('should throw if ES error', async () => {
Expand Down

0 comments on commit ec6c256

Please sign in to comment.