Skip to content

Commit fb6398c

Browse files
committed
[Tests] Add a helper to detect if functional tests are running against cloud (#51817)
* Add a helper to detect if functional tests are running against cloud * PR feedback * Clean up comment * New eslint rules applied
1 parent 95ea6d7 commit fb6398c

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

test/functional/page_objects/common_page.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import { delay } from 'bluebird';
2121
import expect from '@kbn/expect';
22+
import { get } from 'lodash';
2223
// @ts-ignore
2324
import fetch from 'node-fetch';
2425
import { FtrProviderContext } from '../ftr_provider_context';
@@ -414,6 +415,22 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
414415
});
415416
return response.status !== 200;
416417
}
418+
419+
async isCloud(): Promise<boolean> {
420+
const baseUrl = this.getHostPort();
421+
const username = config.get('servers.kibana.username');
422+
const password = config.get('servers.kibana.password');
423+
const response = await fetch(baseUrl + '/api/stats?extended', {
424+
method: 'get',
425+
headers: {
426+
'Content-Type': 'application/json',
427+
Authorization: 'Basic ' + Buffer.from(username + ':' + password).toString('base64'),
428+
},
429+
});
430+
const data = await response.json();
431+
return get(data, 'usage.cloud.is_cloud_enabled', false);
432+
}
433+
417434
async waitForSaveModalToClose() {
418435
log.debug('Waiting for save modal to close');
419436
await retry.try(async () => {

x-pack/test/functional/services/monitoring/no_data.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export function MonitoringNoDataProvider({ getService }) {
7+
export function MonitoringNoDataProvider({ getService, getPageObjects }) {
88
const testSubjects = getService('testSubjects');
99
const retry = getService('retry');
10+
const PageObjects = getPageObjects(['common']);
1011

1112
return new (class NoData {
1213
async enableMonitoring() {
13-
await testSubjects.click('useInternalCollection');
14+
// Cloud currently does not support Metricbeat-based collection
15+
// so the UI does not give the user a choice between the two collection
16+
// methods. So if we're on cloud, do not try and switch to internal collection
17+
// as it's already the default
18+
if (!(await PageObjects.common.isCloud())) {
19+
await testSubjects.click('useInternalCollection');
20+
}
1421
await testSubjects.click('enableCollectionEnabled');
1522
}
1623

0 commit comments

Comments
 (0)