Skip to content

Commit

Permalink
Validation succeed as long as status code in response is 200 (#6399) (#…
Browse files Browse the repository at this point in the history
…6447)

Signed-off-by: cliu123 <lc12251109@gmail.com>
(cherry picked from commit 476cffc)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: ZilongX <99905560+ZilongX@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 4, 2024
1 parent c0cada0 commit 1d3b040
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,20 @@ describe('DataSourceManagement: data_source_connection_validator.ts', () => {
expect(validateDataSourcesResponse.statusCode).toBe(200);
});

test('failure: opensearch client response code is 200 and response body is empty', async () => {
try {
const opensearchClient = opensearchServiceMock.createOpenSearchClient();
opensearchClient.cat.indices.mockResolvedValue(opensearchServiceMock.createApiResponse());
const dataSourceValidator = new DataSourceConnectionValidator(opensearchClient, {
auth: {
statusCode: 200,
body: '',
credentials: {
service: SigV4ServiceName.OpenSearchServerless,
},
test('Success: opensearch client response code is 200 and response body is empty', async () => {
const opensearchClient = opensearchServiceMock.createOpenSearchClient();
opensearchClient.cat.indices.mockResolvedValue(opensearchServiceMock.createApiResponse());
const dataSourceValidator = new DataSourceConnectionValidator(opensearchClient, {
auth: {
statusCode: 200,
body: '',
credentials: {
service: SigV4ServiceName.OpenSearchServerless,
},
});
const validateDataSourcesResponse = await dataSourceValidator.validate();
expect(validateDataSourcesResponse.statusCode).toBe(200);
} catch (e) {
expect(e).toBeTruthy();
}
},
});
const validateDataSourcesResponse = await dataSourceValidator.validate();
expect(validateDataSourcesResponse.statusCode).toBe(200);
});

test('failure: opensearch client response code is other than 200', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class DataSourceConnectionValidator {
this.dataSourceAttr.auth?.credentials?.service === SigV4ServiceName.OpenSearchServerless
) {
validationResponse = await this.callDataCluster.cat.indices();
if (validationResponse?.statusCode === 200 && validationResponse?.body) {
if (validationResponse?.statusCode === 200) {
return validationResponse;
}
} else {
Expand Down

0 comments on commit 1d3b040

Please sign in to comment.