Skip to content

Commit

Permalink
Merge branch 'main' into update-k8s-templates-20220812091605
Browse files Browse the repository at this point in the history
  • Loading branch information
gizas authored Aug 18, 2022
2 parents 0b924f8 + 9969513 commit 3304bbf
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 85 deletions.
9 changes: 9 additions & 0 deletions test/functional/page_objects/discover_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,15 @@ export class DiscoverPageObject extends FtrService {
await this.header.waitUntilLoadingHasFinished();
}

public async getIndexPatterns() {
await this.testSubjects.click('discover-dataView-switch-link');
const indexPatternSwitcher = await this.testSubjects.find('indexPattern-switcher');
const li = await indexPatternSwitcher.findAllByTagName('li');
const items = await Promise.all(li.map((lis) => lis.getVisibleText()));
await this.testSubjects.click('discover-dataView-switch-link');
return items;
}

public async selectTextBaseLang(lang: 'SQL') {
await this.testSubjects.click('discover-dataView-switch-link');
await this.find.clickByCssSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ describe('addConnector lib function', () => {
asInternalUser: {},
};

const createConnectorsIndexExistsFn =
(connectorsIndexExists: boolean, defaultValue: boolean) =>
({ index }: { index: string }) =>
index === CONNECTORS_INDEX ? connectorsIndexExists : defaultValue;

beforeEach(() => {
jest.clearAllMocks();
});

it('should add connector', async () => {
mockClient.asCurrentUser.index.mockImplementation(() => ({ _id: 'fakeId' }));
mockClient.asCurrentUser.indices.exists.mockImplementation(() => false);
mockClient.asCurrentUser.indices.exists.mockImplementation(
createConnectorsIndexExistsFn(true, false)
);
(fetchConnectorByIndexName as jest.Mock).mockImplementation(() => undefined);
(fetchCrawlerByIndexName as jest.Mock).mockImplementation(() => undefined);

Expand Down Expand Up @@ -82,7 +89,9 @@ describe('addConnector lib function', () => {

it('should reject if index already exists', async () => {
mockClient.asCurrentUser.index.mockImplementation(() => ({ _id: 'fakeId' }));
mockClient.asCurrentUser.indices.exists.mockImplementation(() => true);
mockClient.asCurrentUser.indices.exists.mockImplementation(
createConnectorsIndexExistsFn(true, true)
);
(fetchConnectorByIndexName as jest.Mock).mockImplementation(() => undefined);
(fetchCrawlerByIndexName as jest.Mock).mockImplementation(() => undefined);

Expand All @@ -97,7 +106,9 @@ describe('addConnector lib function', () => {

it('should reject if connector already exists', async () => {
mockClient.asCurrentUser.index.mockImplementation(() => ({ _id: 'fakeId' }));
mockClient.asCurrentUser.indices.exists.mockImplementation(() => false);
mockClient.asCurrentUser.indices.exists.mockImplementation(
createConnectorsIndexExistsFn(true, false)
);
(fetchConnectorByIndexName as jest.Mock).mockImplementation(() => true);
(fetchCrawlerByIndexName as jest.Mock).mockImplementation(() => undefined);

Expand All @@ -110,9 +121,28 @@ describe('addConnector lib function', () => {
expect(mockClient.asCurrentUser.indices.create).not.toHaveBeenCalled();
});

it('should reject if crawler already exists', async () => {
mockClient.asCurrentUser.index.mockImplementation(() => ({ _id: 'fakeId' }));
mockClient.asCurrentUser.indices.exists.mockImplementation(
createConnectorsIndexExistsFn(true, false)
);
(fetchConnectorByIndexName as jest.Mock).mockImplementation(() => undefined);
(fetchCrawlerByIndexName as jest.Mock).mockImplementation(() => true);

await expect(
addConnector(mockClient as unknown as IScopedClusterClient, {
index_name: 'index_name',
language: 'en',
})
).rejects.toEqual(new Error(ErrorCode.CRAWLER_ALREADY_EXISTS));
expect(mockClient.asCurrentUser.indices.create).not.toHaveBeenCalled();
});

it('should reject with index already exists if connector and index already exist', async () => {
mockClient.asCurrentUser.index.mockImplementation(() => ({ _id: 'fakeId' }));
mockClient.asCurrentUser.indices.exists.mockImplementation(() => true);
mockClient.asCurrentUser.indices.exists.mockImplementation(
createConnectorsIndexExistsFn(true, true)
);
(fetchConnectorByIndexName as jest.Mock).mockImplementation(() => true);
(fetchCrawlerByIndexName as jest.Mock).mockImplementation(() => undefined);

Expand All @@ -127,7 +157,9 @@ describe('addConnector lib function', () => {

it('should replace connector if deleteExistingConnector flag is true', async () => {
mockClient.asCurrentUser.index.mockImplementation(() => ({ _id: 'fakeId' }));
mockClient.asCurrentUser.indices.exists.mockImplementation(() => false);
mockClient.asCurrentUser.indices.exists.mockImplementation(
createConnectorsIndexExistsFn(true, false)
);
(fetchConnectorByIndexName as jest.Mock).mockImplementation(() => ({ id: 'connectorId' }));
(fetchCrawlerByIndexName as jest.Mock).mockImplementation(() => undefined);

Expand Down Expand Up @@ -167,13 +199,9 @@ describe('addConnector lib function', () => {
});

it('should create index if no connectors index exists', async () => {
mockClient.asCurrentUser.index.mockImplementationOnce(() => {
return Promise.reject({
meta: { body: { error: { type: 'index_not_found_exception' } } },
statusCode: 404,
});
});
mockClient.asCurrentUser.indices.exists.mockImplementation(() => false);
mockClient.asCurrentUser.indices.exists.mockImplementation(
createConnectorsIndexExistsFn(false, false)
);
(fetchConnectorByIndexName as jest.Mock).mockImplementation(() => false);
(fetchCrawlerByIndexName as jest.Mock).mockImplementation(() => undefined);
await expect(
Expand Down Expand Up @@ -206,36 +234,4 @@ describe('addConnector lib function', () => {
settings: textAnalysisSettings('en'),
});
});
it('should not create index if status code is not 404', async () => {
mockClient.asCurrentUser.index.mockImplementationOnce(() => {
return Promise.reject({ statusCode: 500 });
});
mockClient.asCurrentUser.indices.exists.mockImplementation(() => false);
(fetchConnectorByIndexName as jest.Mock).mockImplementation(() => false);
(fetchCrawlerByIndexName as jest.Mock).mockImplementation(() => undefined);
await expect(
addConnector(mockClient as unknown as IScopedClusterClient, {
index_name: 'index_name',
language: 'en',
})
).rejects.toEqual({ statusCode: 500 });
expect(setupConnectorsIndices).not.toHaveBeenCalled();
expect(mockClient.asCurrentUser.index).toHaveBeenCalledTimes(1);
});
it('should not create index if crawler exists', async () => {
mockClient.asCurrentUser.index.mockImplementationOnce(() => {
return 'connector ';
});
mockClient.asCurrentUser.indices.exists.mockImplementation(() => false);
(fetchConnectorByIndexName as jest.Mock).mockImplementation(() => false);
(fetchCrawlerByIndexName as jest.Mock).mockImplementation(() => 'crawler');
await expect(
addConnector(mockClient as unknown as IScopedClusterClient, {
index_name: 'index_name',
language: 'en',
})
).rejects.toEqual(new Error(ErrorCode.CRAWLER_ALREADY_EXISTS));
expect(setupConnectorsIndices).not.toHaveBeenCalled();
expect(mockClient.asCurrentUser.index).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { CONNECTORS_INDEX } from '../..';
import { ConnectorDocument, ConnectorStatus } from '../../../common/types/connectors';
import { ErrorCode } from '../../../common/types/error_codes';
import { setupConnectorsIndices } from '../../index_management/setup_indices';
import { isIndexNotFoundException } from '../../utils/identify_exceptions';

import { fetchCrawlerByIndexName } from '../crawler/fetch_crawlers';
import { textAnalysisSettings } from '../indices/text_analysis';
Expand Down Expand Up @@ -80,21 +79,11 @@ export const addConnector = async (
status: ConnectorStatus.CREATED,
sync_now: false,
};
try {
return await createConnector(
document,
client,
input.language,
!!input.delete_existing_connector
);
} catch (error) {
if (isIndexNotFoundException(error)) {
// This means .ent-search-connectors index doesn't exist yet
// So we first have to create it, and then try inserting the document again
await setupConnectorsIndices(client.asCurrentUser);
return await createConnector(document, client, input.language, false);
} else {
throw error;
}
const connectorsIndexExists = await client.asCurrentUser.indices.exists({
index: CONNECTORS_INDEX,
});
if (!connectorsIndexExists) {
await setupConnectorsIndices(client.asCurrentUser);
}
return await createConnector(document, client, input.language, !!input.delete_existing_connector);
};
2 changes: 0 additions & 2 deletions x-pack/test/functional/apps/maps/group1/layer_visibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import expect from '@kbn/expect';
export default function ({ getPageObjects, getService }) {
const PageObjects = getPageObjects(['maps']);
const inspector = getService('inspector');
const testSubjects = getService('testSubjects');
const security = getService('security');

describe('layer visibility', () => {
Expand All @@ -32,7 +31,6 @@ export default function ({ getPageObjects, getService }) {

it('should fetch layer data when layer is made visible', async () => {
await PageObjects.maps.toggleLayerVisibility('logstash');
await testSubjects.click('mapLayerTOC'); // Tooltip blocks clicks otherwise
const hits = await PageObjects.maps.getHits();
expect(hits).to.equal('5');
});
Expand Down
20 changes: 19 additions & 1 deletion x-pack/test/functional/page_objects/gis_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,28 @@ export class GisPageObject extends FtrService {
};
}

// This method is also used by upgrade testing which is not part of PR testing
// Please keep in mind when udpating, removing or adding to this method
// upgrade needs to be tested too
async clearLegendTooltip() {
const isTooltipOpen = await this.testSubjects.exists(`layerTocTooltip`, { timeout: 5000 });
if (isTooltipOpen) {
await this.testSubjects.click(`layerTocTooltip`);
// Wait for tooltip to go away
await this.common.sleep(1000);
}
}

// This method is also used by upgrade testing which is not part of PR testing
// Please keep in mind when udpating, removing or adding to this method
// upgrade needs to be tested too
async toggleLayerVisibility(layerName: string) {
this.log.debug(`Toggle layer visibility, layer: ${layerName}`);
this.log.debug('Inside toggleLayerVisibility');
await this.clearLegendTooltip();
await this.openLayerTocActionsPanel(layerName);
await this.testSubjects.click('layerVisibilityToggleButton');
await this.waitForLayersToLoad();
await this.clearLegendTooltip();
}

// In 8.4, EMS basemap layers no longer use EMS tile service name, instead using "Basemap"
Expand Down
10 changes: 5 additions & 5 deletions x-pack/test/upgrade/apps/canvas/canvas_smoke_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
];

const canvasTests = [
{ name: 'flights', page: 1, numElements: 35 },
{ name: 'logs', page: 1, numElements: 57 },
{ name: 'ecommerce', page: 1, numElements: 16 },
{ name: 'ecommerce', page: 2, numElements: 9 },
{ name: 'flights', page: 1, numElements: 33 },
{ name: 'logs', page: 1, numElements: 56 },
{ name: 'ecommerce', page: 1, numElements: 15 },
{ name: 'ecommerce', page: 2, numElements: 8 },
];

spaces.forEach(({ space, basePath }) => {
Expand Down Expand Up @@ -56,7 +56,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const elements = await testSubjects.findAll(
'canvasWorkpadPage > canvasWorkpadPageElementContent'
);
expect(elements).to.have.length(numElements);
expect(elements.length).to.be.greaterThan(numElements);
});
});
});
Expand Down
8 changes: 7 additions & 1 deletion x-pack/test/upgrade/apps/discover/discover_smoke_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export default function ({ getPageObjects }: FtrProviderContext) {
basePath,
});
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.selectIndexPattern(`kibana_sample_data_${name}`);
const indices = await PageObjects.discover.getIndexPatterns();
const index = indices.find((element) => {
if (element.toLowerCase().includes(name)) {
return true;
}
});
await PageObjects.discover.selectIndexPattern(String(index));
await PageObjects.discover.waitUntilSearchingHasFinished();
if (timefield) {
await PageObjects.timePicker.setCommonlyUsedTime('Last_24 hours');
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/upgrade/apps/rules/rules_smoke_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await testSubjects.click('rulesTab');
});
it('shows created rule with no errors', async () => {
const createdRuleName = 'Upgrade Rule';
const createdRuleName = 'UpgradeRule';
await testSubjects.click('rulesTab');
await rulesHelper.searchRules('"' + createdRuleName + '"');
const workAround = process.env.TEST_RULE_WORKAROUND ? true : false;
Expand Down
13 changes: 0 additions & 13 deletions x-pack/test/upgrade/services/maps_upgrade_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,8 @@ import { FtrProviderContext } from '../ftr_provider_context';
export function MapsHelper({ getPageObjects, getService }: FtrProviderContext) {
const PageObjects = getPageObjects(['maps', 'common']);
const testSubjects = getService('testSubjects');
const log = getService('log');

return {
async toggleLayerVisibility(layerName: string) {
log.debug('Inside toggleLayerVisibility');
await PageObjects.maps.openLayerTocActionsPanel(layerName);
await testSubjects.click('layerVisibilityToggleButton');
await PageObjects.common.sleep(3000);
const isTooltipOpen = await testSubjects.exists(`layerTocTooltip`, { timeout: 5000 });
if (isTooltipOpen) {
await testSubjects.click(`layerTocTooltip`);
await PageObjects.common.sleep(1000);
}
},

// In v7.16, e-commerce sample data was re-worked so that geo.src field to match country code of geo.coordinates
// https://github.com/elastic/kibana/pull/110885
// Maps created before this change will have a layer called "Total Requests by Country"
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/upgrade/services/rules_upgrade_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function RulesHelper({ getPageObjects, getService }: FtrProviderContext)
'statusDropdown' + status + 'Item'
);
await actionsMenuItemElem.click();
await actionsDropdown.findByClassName('euiLoadingSpinner euiLoadingSpinner--small');
await actionsDropdown.waitForDeletedByCssSelector('.euiLoadingSpinner');
await retry.try(async () => {
await this.getRulesList();
expect(await this.isStatus(status)).to.eql(true);
Expand Down

0 comments on commit 3304bbf

Please sign in to comment.