forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Follow up on opensearch-project#9048 by updating data and utilities
Feature branch PRs: opensearch-project#9038 opensearch-project#9006 Signed-off-by: Anan <[email protected]>
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |