Skip to content

Commit

Permalink
rename legacy client mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Jun 30, 2020
1 parent 71a27bb commit e48f3ad
Show file tree
Hide file tree
Showing 58 changed files with 167 additions and 162 deletions.
8 changes: 4 additions & 4 deletions src/core/server/elasticsearch/elasticsearch_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ export const elasticsearchServiceMock = {
createInternalSetup: createInternalSetupContractMock,
createSetup: createSetupContractMock,
createStart: createStartContractMock,
createClusterClient: createClusterClientMock,
createCustomClusterClient: createCustomClusterClientMock,
createScopedClusterClient: createScopedClusterClientMock,
createElasticsearchClient: createElasticsearchClientMock,
createLegacyClusterClient: createClusterClientMock,
createLegacyCustomClusterClient: createCustomClusterClientMock,
createLegacyScopedClusterClient: createScopedClusterClientMock,
createLegacyElasticsearchClient: createElasticsearchClientMock,
};
4 changes: 2 additions & 2 deletions src/core/server/elasticsearch/elasticsearch_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let coreContext: CoreContext;
const logger = loggingSystemMock.create();

let mockClusterClientInstance: ReturnType<typeof elasticsearchClientMock.createCustomClusterClient>;
let mockLegacyClusterClientInstance: ReturnType<typeof elasticsearchServiceMock.createCustomClusterClient>;
let mockLegacyClusterClientInstance: ReturnType<typeof elasticsearchServiceMock.createLegacyCustomClusterClient>;

beforeEach(() => {
env = Env.createDefault(getEnvOptions());
Expand All @@ -70,7 +70,7 @@ beforeEach(() => {
MockLegacyClusterClient.mockClear();
MockClusterClient.mockClear();

mockLegacyClusterClientInstance = elasticsearchServiceMock.createCustomClusterClient();
mockLegacyClusterClientInstance = elasticsearchServiceMock.createLegacyCustomClusterClient();
MockLegacyClusterClient.mockImplementation(() => mockLegacyClusterClientInstance);
mockClusterClientInstance = elasticsearchClientMock.createCustomClusterClient();
MockClusterClient.mockImplementation(() => mockClusterClientInstance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { elasticsearchServiceMock } from '../../elasticsearch/elasticsearch_serv
export const clusterClientMock = jest.fn();
jest.doMock('../../elasticsearch/legacy/scoped_cluster_client', () => ({
LegacyScopedClusterClient: clusterClientMock.mockImplementation(function () {
return elasticsearchServiceMock.createScopedClusterClient();
return elasticsearchServiceMock.createLegacyScopedClusterClient();
}),
}));

Expand All @@ -31,7 +31,7 @@ jest.doMock('elasticsearch', () => {
...realES,
// eslint-disable-next-line object-shorthand
Client: function () {
return elasticsearchServiceMock.createElasticsearchClient();
return elasticsearchServiceMock.createLegacyElasticsearchClient();
},
};
});
2 changes: 1 addition & 1 deletion src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function createCoreRequestHandlerContextMock() {
},
elasticsearch: {
legacy: {
client: elasticsearchServiceMock.createScopedClusterClient(),
client: elasticsearchServiceMock.createLegacyScopedClusterClient(),
},
},
uiSettings: {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/actions/server/actions_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { KibanaRequest } from 'kibana/server';

const defaultKibanaIndex = '.kibana';
const savedObjectsClient = savedObjectsClientMock.create();
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
const scopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
const actionExecutor = actionExecutorMock.create();
const executionEnqueuer = jest.fn();
const request = {} as KibanaRequest;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/actions/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const createServicesMock = () => {
savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>;
}
> = {
callCluster: elasticsearchServiceMock.createScopedClusterClient().callAsCurrentUser,
callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser,
getScopedCallCluster: jest.fn(),
savedObjectsClient: savedObjectsClientMock.create(),
};
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerts/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const createAlertServicesMock = () => {
alertInstanceFactory: jest
.fn<jest.Mocked<AlertInstance>, [string]>()
.mockReturnValue(alertInstanceFactoryMock),
callCluster: elasticsearchServiceMock.createScopedClusterClient().callAsCurrentUser,
callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser,
getScopedCallCluster: jest.fn(),
savedObjectsClient: savedObjectsClientMock.create(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function mockHandlerArguments(
{
alertsClient = alertsClientMock.create(),
listTypes: listTypesRes = [],
esClient = elasticsearchServiceMock.createClusterClient(),
esClient = elasticsearchServiceMock.createLegacyClusterClient(),
}: {
alertsClient?: AlertsClientMock;
listTypes?: AlertType[];
Expand Down
14 changes: 7 additions & 7 deletions x-pack/plugins/alerts/server/routes/health.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0];

const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue(Promise.resolve({}));

const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']);
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0];

const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue(Promise.resolve({}));

const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']);
Expand All @@ -96,7 +96,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0];

const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue(Promise.resolve({}));

const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']);
Expand All @@ -120,7 +120,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0];

const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue(Promise.resolve({ security: {} }));

const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']);
Expand All @@ -144,7 +144,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0];

const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue(Promise.resolve({ security: { enabled: true } }));

const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']);
Expand All @@ -168,7 +168,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0];

const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue(
Promise.resolve({ security: { enabled: true, ssl: {} } })
);
Expand All @@ -194,7 +194,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0];

const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue(
Promise.resolve({ security: { enabled: true, ssl: { http: { enabled: true } } } })
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {

const mockRouteContext = ({
core: {
elasticsearch: { legacy: { client: elasticsearchServiceMock.createScopedClusterClient() } },
elasticsearch: {
legacy: { client: elasticsearchServiceMock.createLegacyScopedClusterClient() },
},
},
} as unknown) as RequestHandlerContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let clusterClientAdapter: IClusterClientAdapter;

beforeEach(() => {
logger = loggingSystemMock.createLogger();
clusterClient = elasticsearchServiceMock.createClusterClient();
clusterClient = elasticsearchServiceMock.createLegacyClusterClient();
clusterClientAdapter = new ClusterClientAdapter({
logger,
clusterClientPromise: Promise.resolve(clusterClient),
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/event_log/server/es/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let clusterClient: EsClusterClient;

beforeEach(() => {
logger = loggingSystemMock.createLogger();
clusterClient = elasticsearchServiceMock.createClusterClient();
clusterClient = elasticsearchServiceMock.createLegacyClusterClient();
});

describe('createEsContext', () => {
Expand Down
33 changes: 18 additions & 15 deletions x-pack/plugins/licensing/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ const flushPromises = (ms = 50) => new Promise((res) => setTimeout(res, ms));

function createCoreSetupWith(esClient: ILegacyClusterClient) {
const coreSetup = coreMock.createSetup();

const coreStart = coreMock.createStart();
coreSetup.getStartServices.mockResolvedValue([
{
...coreMock.createStart(),
elasticsearch: { legacy: { client: esClient, createClient: jest.fn() } },
...coreStart,
elasticsearch: {
...coreStart.elasticsearch,
legacy: { client: esClient, createClient: jest.fn() },
},
},
{},
{},
Expand All @@ -61,7 +64,7 @@ describe('licensing plugin', () => {
});

it('returns license', async () => {
const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense(),
features: {},
Expand All @@ -77,7 +80,7 @@ describe('licensing plugin', () => {
it('observable receives updated licenses', async () => {
const types: LicenseType[] = ['basic', 'gold', 'platinum'];

const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockImplementation(() =>
Promise.resolve({
license: buildRawLicense({ type: types.shift() }),
Expand All @@ -96,7 +99,7 @@ describe('licensing plugin', () => {
});

it('returns a license with error when request fails', async () => {
const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockRejectedValue(new Error('test'));

const coreSetup = createCoreSetupWith(esClient);
Expand All @@ -109,7 +112,7 @@ describe('licensing plugin', () => {
});

it('generate error message when x-pack plugin was not installed', async () => {
const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
const error: ElasticsearchError = new Error('reason');
error.status = 400;
esClient.callAsInternalUser.mockRejectedValue(error);
Expand All @@ -127,7 +130,7 @@ describe('licensing plugin', () => {
const error1 = new Error('reason-1');
const error2 = new Error('reason-2');

const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();

esClient.callAsInternalUser
.mockRejectedValueOnce(error1)
Expand All @@ -145,7 +148,7 @@ describe('licensing plugin', () => {
});

it('fetch license immediately without subscriptions', async () => {
const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense(),
features: {},
Expand All @@ -161,7 +164,7 @@ describe('licensing plugin', () => {
});

it('logs license details without subscriptions', async () => {
const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense(),
features: {},
Expand All @@ -187,7 +190,7 @@ describe('licensing plugin', () => {
it('generates signature based on fetched license content', async () => {
const types: LicenseType[] = ['basic', 'gold', 'basic'];

const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockImplementation(() =>
Promise.resolve({
license: buildRawLicense({ type: types.shift() }),
Expand Down Expand Up @@ -218,7 +221,7 @@ describe('licensing plugin', () => {
api_polling_frequency: moment.duration(50000),
})
);
const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense(),
features: {},
Expand Down Expand Up @@ -253,7 +256,7 @@ describe('licensing plugin', () => {
})
);

const esClient = elasticsearchServiceMock.createClusterClient();
const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense(),
features: {},
Expand All @@ -262,7 +265,7 @@ describe('licensing plugin', () => {
await plugin.setup(coreSetup);
const { createLicensePoller, license$ } = await plugin.start();

const customClient = elasticsearchServiceMock.createClusterClient();
const customClient = elasticsearchServiceMock.createLegacyClusterClient();
customClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense({ type: 'gold' }),
features: {},
Expand Down Expand Up @@ -297,7 +300,7 @@ describe('licensing plugin', () => {
await plugin.setup(coreSetup);
const { createLicensePoller } = await plugin.start();

const customClient = elasticsearchServiceMock.createClusterClient();
const customClient = elasticsearchServiceMock.createLegacyClusterClient();
customClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense({ type: 'gold' }),
features: {},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/oss_telemetry/server/test_utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const defaultMockTaskDocs = [getMockTaskInstance()];
export const getMockEs = async (
mockCallWithInternal: LegacyAPICaller = getMockCallWithInternal()
) => {
const client = elasticsearchServiceMock.createClusterClient();
const client = elasticsearchServiceMock.createLegacyClusterClient();
(client.callAsInternalUser as any) = mockCallWithInternal;
return client;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('ADD remote clusters', () => {
{ licenseCheckResult = { valid: true }, apiResponses = [], asserts, payload }: TestOptions
) => {
test(description, async () => {
const elasticsearchMock = elasticsearchServiceMock.createClusterClient();
const elasticsearchMock = elasticsearchServiceMock.createLegacyClusterClient();

const mockRouteDependencies = {
router: httpServiceMock.createRouter(),
Expand All @@ -40,10 +40,10 @@ describe('ADD remote clusters', () => {
},
};

const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();

elasticsearchServiceMock
.createClusterClient()
.createLegacyClusterClient()
.asScoped.mockReturnValue(mockScopedClusterClient);

for (const apiResponse of apiResponses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('DELETE remote clusters', () => {
{ licenseCheckResult = { valid: true }, apiResponses = [], asserts, params }: TestOptions
) => {
test(description, async () => {
const elasticsearchMock = elasticsearchServiceMock.createClusterClient();
const elasticsearchMock = elasticsearchServiceMock.createLegacyClusterClient();

const mockRouteDependencies = {
router: httpServiceMock.createRouter(),
Expand All @@ -42,10 +42,10 @@ describe('DELETE remote clusters', () => {
},
};

const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();

elasticsearchServiceMock
.createClusterClient()
.createLegacyClusterClient()
.asScoped.mockReturnValue(mockScopedClusterClient);

for (const apiResponse of apiResponses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('GET remote clusters', () => {
{ licenseCheckResult = { valid: true }, apiResponses = [], asserts }: TestOptions
) => {
test(description, async () => {
const elasticsearchMock = elasticsearchServiceMock.createClusterClient();
const elasticsearchMock = elasticsearchServiceMock.createLegacyClusterClient();

const mockRouteDependencies = {
router: httpServiceMock.createRouter(),
Expand All @@ -41,10 +41,10 @@ describe('GET remote clusters', () => {
},
};

const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();

elasticsearchServiceMock
.createClusterClient()
.createLegacyClusterClient()
.asScoped.mockReturnValue(mockScopedClusterClient);

for (const apiResponse of apiResponses) {
Expand Down
Loading

0 comments on commit e48f3ad

Please sign in to comment.