Skip to content

Commit

Permalink
[nodejs client] fix hookup issues in src/core/server/opensearch
Browse files Browse the repository at this point in the history
1. import Client from '@opensearch-project/opensearch/api/new' to hook
up the new types
2. remove asynSearch
3. apply type assertion
4. fix undefined and mismatched types

Remove retry_call_cluster.test.ts due to removing all asyncSearch api

Issue Resolved: opensearch-project#1193
Partical Resolved: opensearch-project#837
Signed-off-by: Anan Zhuang <ananzh@amazon.com>
  • Loading branch information
ananzh committed Feb 7, 2022
1 parent decd7c1 commit 9e9f2b6
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 326 deletions.
2 changes: 1 addition & 1 deletion src/core/server/opensearch/client/cluster_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/

import { Client } from '@opensearch-project/opensearch';
import { Client } from '@opensearch-project/opensearch/api/new';
import { Logger } from '../../logging';
import { GetAuthHeaders, Headers, isOpenSearchDashboardsRequest, isRealRequest } from '../../http';
import { ensureRawRequest, filterHeaders } from '../../http/router';
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/opensearch/client/configure_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
import { Buffer } from 'buffer';
import { stringify } from 'querystring';
import { Client } from '@opensearch-project/opensearch';
import { Client } from '@opensearch-project/opensearch/api/new';
import { RequestBody } from '@opensearch-project/opensearch/lib/Transport';

import { Logger } from '../../logging';
Expand Down
1 change: 0 additions & 1 deletion src/core/server/opensearch/client/mocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe('Mocked client', () => {
});

it('nested level API methods should be mocked', () => {
expectMocked(client.asyncSearch.get);
expectMocked(client.nodes.info);
});

Expand Down
6 changes: 3 additions & 3 deletions src/core/server/opensearch/client/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
import { Client, ApiResponse } from '@opensearch-project/opensearch';
import { Client, ApiResponse } from '@opensearch-project/opensearch/api/new';
import { TransportRequestPromise } from '@opensearch-project/opensearch/lib/Transport';
import { OpenSearchClient } from './types';
import { ICustomClusterClient } from './cluster_client';
Expand Down Expand Up @@ -176,9 +176,9 @@ const createErrorTransportRequestPromise = (err: any): MockedTransportRequestPro
return promise as MockedTransportRequestPromise<never>;
};

function createApiResponse(opts: Partial<ApiResponse> = {}): ApiResponse {
function createApiResponse<TResponse = Record<string, any>>(opts: Partial<ApiResponse> = {}): ApiResponse<TResponse> {
return {
body: {},
body: {} as any,
statusCode: 200,
headers: {},
warnings: [],
Expand Down
313 changes: 0 additions & 313 deletions src/core/server/opensearch/client/retry_call_cluster.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('pollOpenSearchNodesVersion', () => {
internalClient.nodes.info.mockImplementationOnce(() => createOpenSearchError(error));
};

it('returns iscCompatible=false and keeps polling when a poll request throws', (done) => {
it('returns isCompatible=false and keeps polling when a poll request throws', (done) => {
expect.assertions(3);
const expectedCompatibilityResults = [false, false, true];
jest.clearAllMocks();
Expand Down
Loading

0 comments on commit 9e9f2b6

Please sign in to comment.