Skip to content

Commit

Permalink
Add import helper function to optimize data uploading time (#43)
Browse files Browse the repository at this point in the history
* Add import doc if needed function to optimize data uploading time

Signed-off-by: Qingyang(Abby) Hu <[email protected]>

* bump version

Signed-off-by: Qingyang(Abby) Hu <[email protected]>

* fix comments

Signed-off-by: Qingyang(Abby) Hu <[email protected]>

* check string type

Signed-off-by: Qingyang(Abby) Hu <[email protected]>

---------

Signed-off-by: Qingyang(Abby) Hu <[email protected]>
  • Loading branch information
abbyhu2000 authored Oct 4, 2023
1 parent 96bb1d8 commit 200bc9d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions common-utils/network/test-fixture-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,24 @@ export class TestFixtureHandler {
})
})
}

/**
* Read docs from a file and import them to OpenSearch only when the indices do not already exist
* in order to optimize the data uploading time
* @param {string, array} index An index or a set of indices
* @param {string} indexMappingPath File path for mapping data
* @param {string} indexDataPath File path for the actual data
*/
importJSONDocIfNeeded(index, indexMappingPath, indexDataPath) {
const items = (Array.isArray(index) ? index : [index]);
if (items.some(value => typeof value !== 'string')) throw 'Invalid indices';
const queryString = items.join(',');

cy.getIndices(queryString).then((response) => {
if(response.status === 404){
this.importJSONMapping(indexMappingPath);
this.importJSONDoc(indexDataPath);
}
});
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opensearch-dashboards-test/opensearch-dashboards-test-library",
"version": "1.0.5",
"version": "1.0.6",
"description": "Provides utility functions, page object models, test fixture handling for developers to write functional tests for OpenSearch Dashboards and plugins",
"main": "index.js",
"type": "module",
Expand Down

0 comments on commit 200bc9d

Please sign in to comment.