From 08ff13ec1a50f9010535a4d4ff9d4929a9013f0d Mon Sep 17 00:00:00 2001 From: Anan Date: Sun, 15 Dec 2024 20:19:23 -0800 Subject: [PATCH] Follow up on #9048 by updating data and utilities Feature branch PRs: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9038 https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9006 Signed-off-by: Anan --- cypress/lib/test-fixture-handler.js | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 cypress/lib/test-fixture-handler.js diff --git a/cypress/lib/test-fixture-handler.js b/cypress/lib/test-fixture-handler.js new file mode 100644 index 000000000000..e653aa6ad17b --- /dev/null +++ b/cypress/lib/test-fixture-handler.js @@ -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; + } +}