Skip to content

Commit

Permalink
Follow up on opensearch-project#9048 by updating data and utilities
Browse files Browse the repository at this point in the history
Feature branch PRs:
opensearch-project#9038
opensearch-project#9006

Signed-off-by: Anan <[email protected]>
  • Loading branch information
ananzh authored and AMoo-Miki committed Dec 19, 2024
1 parent 1d31898 commit 08ff13e
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions cypress/lib/test-fixture-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export class TestFixtureHandler {
constructor(inputTestRunner, openSearchUrl = 'localhost:9200') {
this.testRunner = inputTestRunner;
this.openSearchUrl = openSearchUrl;
}

// TODO: Migrate legacy methods from test library

importMapping(filename) {
return cy.readFile(filename).then((mappingData) => {
const targetIndex = this._extractIndexNameFromPath(filename);

return cy.request({
method: 'PUT',
url: `${this.openSearchUrl}/${targetIndex}`,
headers: {
'Content-Type': 'application/json',
},
body: mappingData,
failOnStatusCode: false,
});
});
}

importData(filename) {
return cy.readFile(filename, 'utf8').then((content) => {
return cy
.request({
method: 'POST',
url: `${this.openSearchUrl}/_bulk`,
headers: {
'Content-Type': 'application/x-ndjson',
},
body: content,
failOnStatusCode: false,
})
.then(() => {
return cy.request({
method: 'POST',
url: `${this.openSearchUrl}/_all/_refresh`,
});
});
});
}

_extractIndexNameFromPath(filepath) {
const filename = filepath.split('/').pop();
const indexName = filename.split('.')[0];
return indexName;
}
}

0 comments on commit 08ff13e

Please sign in to comment.