Skip to content

Commit

Permalink
Use named arguments in migrationsv2 actions
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers committed May 29, 2021
1 parent 418a3d3 commit 5bc0a9b
Show file tree
Hide file tree
Showing 5 changed files with 779 additions and 472 deletions.
96 changes: 70 additions & 26 deletions src/core/server/saved_objects/migrationsv2/actions/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('actions', () => {

describe('fetchIndices', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.fetchIndices(client, ['my_index']);
const task = Actions.fetchIndices({ client, indicesToFetch: ['my_index'] });
try {
await task();
} catch (e) {
Expand All @@ -49,7 +49,7 @@ describe('actions', () => {

describe('setWriteBlock', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.setWriteBlock(client, 'my_index');
const task = Actions.setWriteBlock({ client, index: 'my_index' });
try {
await task();
} catch (e) {
Expand All @@ -58,15 +58,22 @@ describe('actions', () => {
expect(catchRetryableEsClientErrors).toHaveBeenCalledWith(retryableError);
});
it('re-throws non retry-able errors', async () => {
const task = Actions.setWriteBlock(clientWithNonRetryableError, 'my_index');
const task = Actions.setWriteBlock({
client: clientWithNonRetryableError,
index: 'my_index',
});
await task();
expect(catchRetryableEsClientErrors).toHaveBeenCalledWith(nonRetryableError);
});
});

describe('cloneIndex', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.cloneIndex(client, 'my_source_index', 'my_target_index');
const task = Actions.cloneIndex({
client,
source: 'my_source_index',
target: 'my_target_index',
});
try {
await task();
} catch (e) {
Expand All @@ -75,7 +82,10 @@ describe('actions', () => {
expect(catchRetryableEsClientErrors).toHaveBeenCalledWith(retryableError);
});
it('re-throws non retry-able errors', async () => {
const task = Actions.setWriteBlock(clientWithNonRetryableError, 'my_index');
const task = Actions.setWriteBlock({
client: clientWithNonRetryableError,
index: 'my_index',
});
await task();
expect(catchRetryableEsClientErrors).toHaveBeenCalledWith(nonRetryableError);
});
Expand All @@ -95,7 +105,7 @@ describe('actions', () => {

describe('openPit', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.openPit(client, 'my_index');
const task = Actions.openPit({ client, index: 'my_index' });
try {
await task();
} catch (e) {
Expand All @@ -107,7 +117,12 @@ describe('actions', () => {

describe('readWithPit', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.readWithPit(client, 'pitId', { match_all: {} }, 10_000);
const task = Actions.readWithPit({
client,
pitId: 'pitId',
query: { match_all: {} },
batchSize: 10_000,
});
try {
await task();
} catch (e) {
Expand All @@ -119,7 +134,7 @@ describe('actions', () => {

describe('closePit', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.closePit(client, 'pitId');
const task = Actions.closePit({ client, pitId: 'pitId' });
try {
await task();
} catch (e) {
Expand All @@ -131,14 +146,14 @@ describe('actions', () => {

describe('reindex', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.reindex(
const task = Actions.reindex({
client,
'my_source_index',
'my_target_index',
Option.none,
false,
{}
);
sourceIndex: 'my_source_index',
targetIndex: 'my_target_index',
reindexScript: Option.none,
requireAlias: false,
unusedTypesQuery: {},
});
try {
await task();
} catch (e) {
Expand All @@ -150,7 +165,7 @@ describe('actions', () => {

describe('waitForReindexTask', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.waitForReindexTask(client, 'my task id', '60s');
const task = Actions.waitForReindexTask({ client, taskId: 'my task id', timeout: '60s' });
try {
await task();
} catch (e) {
Expand All @@ -160,15 +175,22 @@ describe('actions', () => {
expect(catchRetryableEsClientErrors).toHaveBeenCalledWith(retryableError);
});
it('re-throws non retry-able errors', async () => {
const task = Actions.setWriteBlock(clientWithNonRetryableError, 'my_index');
const task = Actions.setWriteBlock({
client: clientWithNonRetryableError,
index: 'my_index',
});
await task();
expect(catchRetryableEsClientErrors).toHaveBeenCalledWith(nonRetryableError);
});
});

describe('waitForPickupUpdatedMappingsTask', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.waitForPickupUpdatedMappingsTask(client, 'my task id', '60s');
const task = Actions.waitForPickupUpdatedMappingsTask({
client,
taskId: 'my task id',
timeout: '60s',
});
try {
await task();
} catch (e) {
Expand All @@ -178,15 +200,18 @@ describe('actions', () => {
expect(catchRetryableEsClientErrors).toHaveBeenCalledWith(retryableError);
});
it('re-throws non retry-able errors', async () => {
const task = Actions.setWriteBlock(clientWithNonRetryableError, 'my_index');
const task = Actions.setWriteBlock({
client: clientWithNonRetryableError,
index: 'my_index',
});
await task();
expect(catchRetryableEsClientErrors).toHaveBeenCalledWith(nonRetryableError);
});
});

describe('updateAliases', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.updateAliases(client, []);
const task = Actions.updateAliases({ client, aliasActions: [] });
try {
await task();
} catch (e) {
Expand All @@ -196,15 +221,22 @@ describe('actions', () => {
expect(catchRetryableEsClientErrors).toHaveBeenCalledWith(retryableError);
});
it('re-throws non retry-able errors', async () => {
const task = Actions.setWriteBlock(clientWithNonRetryableError, 'my_index');
const task = Actions.setWriteBlock({
client: clientWithNonRetryableError,
index: 'my_index',
});
await task();
expect(catchRetryableEsClientErrors).toHaveBeenCalledWith(nonRetryableError);
});
});

describe('createIndex', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.createIndex(client, 'new_index', { properties: {} });
const task = Actions.createIndex({
client,
indexName: 'new_index',
mappings: { properties: {} },
});
try {
await task();
} catch (e) {
Expand All @@ -214,15 +246,22 @@ describe('actions', () => {
expect(catchRetryableEsClientErrors).toHaveBeenCalledWith(retryableError);
});
it('re-throws non retry-able errors', async () => {
const task = Actions.setWriteBlock(clientWithNonRetryableError, 'my_index');
const task = Actions.setWriteBlock({
client: clientWithNonRetryableError,
index: 'my_index',
});
await task();
expect(catchRetryableEsClientErrors).toHaveBeenCalledWith(nonRetryableError);
});
});

describe('updateAndPickupMappings', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.updateAndPickupMappings(client, 'new_index', { properties: {} });
const task = Actions.updateAndPickupMappings({
client,
index: 'new_index',
mappings: { properties: {} },
});
try {
await task();
} catch (e) {
Expand Down Expand Up @@ -276,7 +315,12 @@ describe('actions', () => {

describe('bulkOverwriteTransformedDocuments', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.bulkOverwriteTransformedDocuments(client, 'new_index', [], 'wait_for');
const task = Actions.bulkOverwriteTransformedDocuments({
client,
index: 'new_index',
transformedDocs: [],
refresh: 'wait_for',
});
try {
await task();
} catch (e) {
Expand All @@ -289,7 +333,7 @@ describe('actions', () => {

describe('refreshIndex', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.refreshIndex(client, 'target_index');
const task = Actions.refreshIndex({ client, targetIndex: 'target_index' });
try {
await task();
} catch (e) {
Expand Down
Loading

0 comments on commit 5bc0a9b

Please sign in to comment.