Skip to content

Commit

Permalink
Src/fixtures,setup node env,test utils (#141)
Browse files Browse the repository at this point in the history
* [Rename] src/fixtures directory

* [Rename] src/setup_node_env directory

* [Rename] src/test_utils directory

* [Rename] src/apm.js

* [Rename] addressed review feedbacks

Signed-off-by: Mihir Soni <[email protected]>
  • Loading branch information
mihirsoni authored and kavilla committed Mar 20, 2021
1 parent 8d0b60d commit 8380e42
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 34 deletions.
12 changes: 6 additions & 6 deletions src/apm.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@

const { join } = require('path');
const { name, build } = require('../package.json');
const { loadConfiguration } = require('@kbn/apm-config-loader');
const { loadConfiguration } = require('@osd/apm-config-loader');

const ROOT_DIR = join(__dirname, '..');
let apmConfig;

/**
* Flag to disable APM RUM support on all kibana builds by default
* Flag to disable APM RUM support on all opensearch-dashboards builds by default
*/
const isKibanaDistributable = Boolean(build && build.distributable === true);
const isOpenSearchDashboardsDistributable = Boolean(build && build.distributable === true);

module.exports = function (serviceName = name) {
if (process.env.kbnWorkerType === 'optmzr') {
if (process.env.osdWorkerType === 'optmzr') {
return;
}

apmConfig = loadConfiguration(process.argv, ROOT_DIR, isKibanaDistributable);
apmConfig = loadConfiguration(process.argv, ROOT_DIR, isOpenSearchDashboardsDistributable);
const conf = apmConfig.getConfig(serviceName);
const apm = require('elastic-apm-node');

Expand All @@ -55,7 +55,7 @@ module.exports = function (serviceName = name) {
};

module.exports.getConfig = (serviceName) => {
// integration test runner starts a kibana server that import the module without initializing APM.
// integration test runner starts a opensearch-dashboards server that import the module without initializing APM.
// so we need to check initialization of the config.
// note that we can't just load the configuration during this module's import
// because jest IT are ran with `--config path-to-jest-config.js` which conflicts with the CLI's `config` arg
Expand Down
2 changes: 1 addition & 1 deletion src/fixtures/config_upgrade_from_4.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"max_score": 1,
"hits": [
{
"_index": ".kibana",
"_index": ".opensearch-dashboards",
"_type": "config",
"_id": "4.0.0",
"_score": 1,
Expand Down
4 changes: 2 additions & 2 deletions src/fixtures/config_upgrade_from_4.0.0_to_4.0.1-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"max_score": 1,
"hits": [
{
"_index": ".kibana",
"_index": ".opensearch-dashboards",
"_type": "config",
"_id": "4.0.1-SNAPSHOT",
"_score": 1,
Expand All @@ -21,7 +21,7 @@
}
},
{
"_index": ".kibana",
"_index": ".opensearch-dashboards",
"_type": "config",
"_id": "4.0.0",
"_score": 1,
Expand Down
4 changes: 2 additions & 2 deletions src/fixtures/config_upgrade_from_4.0.0_to_4.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"max_score": 1,
"hits": [
{
"_index": ".kibana",
"_index": ".opensearch-dashboards",
"_type": "config",
"_id": "4.0.1",
"_score": 1,
Expand All @@ -21,7 +21,7 @@
}
},
{
"_index": ".kibana",
"_index": ".opensearch-dashboards",
"_type": "config",
"_id": "4.0.0",
"_score": 1,
Expand Down
14 changes: 7 additions & 7 deletions src/fixtures/logstash_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* under the License.
*/

import { shouldReadFieldFromDocValues, castEsToKbnFieldTypeName } from '../plugins/data/server';
import { shouldReadFieldFromDocValues, castOpenSearchToOsdFieldTypeName } from '../plugins/data/server';

function stubbedLogstashFields() {
return [
// |aggregatable
// | |searchable
// name esType | | |metadata | subType
// name opensearchType | | |metadata | subType
['bytes', 'long', true, true, { count: 10 }],
['ssl', 'boolean', true, true, { count: 20 }],
['@timestamp', 'date', true, true, { count: 30 }],
Expand Down Expand Up @@ -53,7 +53,7 @@ function stubbedLogstashFields() {
['script date', 'date', true, false, { script: '1234', lang: 'painless' }],
['script murmur3', 'murmur3', true, false, { script: '1234' }],
].map(function (row) {
const [name, esType, aggregatable, searchable, metadata = {}, subType = undefined] = row;
const [name, opensearchType, aggregatable, searchable, metadata = {}, subType = undefined] = row;

const {
count = 0,
Expand All @@ -62,15 +62,15 @@ function stubbedLogstashFields() {
scripted = !!script,
} = metadata;

// the conflict type is actually a kbnFieldType, we
// the conflict type is actually a osdFieldType, we
// don't have any other way to represent it here
const type = esType === 'conflict' ? esType : castEsToKbnFieldTypeName(esType);
const type = opensearchType === 'conflict' ? opensearchType : castOpenSearchToOsdFieldTypeName(opensearchType);

return {
name,
type,
esTypes: [esType],
readFromDocValues: shouldReadFieldFromDocValues(aggregatable, esType),
opensearchTypes: [opensearchType],
readFromDocValues: shouldReadFieldFromDocValues(aggregatable, opensearchType),
aggregatable,
searchable,
count,
Expand Down
10 changes: 5 additions & 5 deletions src/fixtures/stubbed_logstash_index_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import stubbedLogstashFields from 'fixtures/logstash_fields';

import { getKbnFieldType } from '../plugins/data/common';
import { getOsdFieldType } from '../plugins/data/common';
import { getStubIndexPattern } from '../plugins/data/public/test_utils';
import { uiSettingsServiceMock } from '../core/public/ui_settings/ui_settings_service.mock';

Expand All @@ -32,16 +32,16 @@ export default function stubbedLogstashIndexPatternService() {
const mockLogstashFields = stubbedLogstashFields();

const fields = mockLogstashFields.map(function (field) {
const kbnType = getKbnFieldType(field.type);
const osdType = getOsdFieldType(field.type);

if (!kbnType || kbnType.name === 'unknown') {
if (!osdType || osdType.name === 'unknown') {
throw new TypeError(`unknown type ${field.type}`);
}

return {
...field,
sortable: 'sortable' in field ? !!field.sortable : kbnType.sortable,
filterable: 'filterable' in field ? !!field.filterable : kbnType.filterable,
sortable: 'sortable' in field ? !!field.sortable : osdType.sortable,
filterable: 'filterable' in field ? !!field.filterable : osdType.filterable,
displayName: field.name,
};
});
Expand Down
2 changes: 1 addition & 1 deletion src/fixtures/telemetry_collectors/working_collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const myCollector = makeUsageCollector<Usage>({
isReady: () => true,
fetch() {
const testString = '123';
// query ES and get some data
// query OpenSearch and get some data

// summarize the data into a model
// return the modeled object that includes whatever you want to track
Expand Down
2 changes: 1 addition & 1 deletion src/setup_node_env/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
*/

require('./no_transpilation');
require('@kbn/optimizer').registerNodeAutoTranspilation();
require('@osd/optimizer').registerNodeAutoTranspilation();
4 changes: 2 additions & 2 deletions src/setup_node_env/node_version_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ var rawRequiredVersion = (pkg && pkg.engines && pkg.engines.node) || null;
var requiredVersion = rawRequiredVersion ? 'v' + rawRequiredVersion : rawRequiredVersion;
var isVersionValid = !!currentVersion && !!requiredVersion && currentVersion === requiredVersion;

// Validates current the NodeJS version compatibility when Kibana starts.
// Validates current the NodeJS version compatibility when OpenSearch Dashboards starts.
if (!isVersionValid) {
var errorMessage =
'Kibana does not support the current Node.js version ' +
'OpenSearch Dashboards does not support the current Node.js version ' +
currentVersion +
'. Please use Node.js ' +
requiredVersion +
Expand Down
2 changes: 1 addition & 1 deletion src/setup_node_env/root/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ var uid = process.getuid && process.getuid();
var isRoot = require('./is_root')(uid);

if (isRoot && !force) {
console.error('Kibana should not be run as root. Use --allow-root to continue.');
console.error('OpenSearch Dashboards should not be run as root. Use --allow-root to continue.');
process.exit(1);
}
2 changes: 1 addition & 1 deletion src/test_utils/__tests__/get_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from '@kbn/expect';
import expect from '@osd/expect';
import getUrl from '../get_url';

describe('getUrl', function () {
Expand Down
4 changes: 2 additions & 2 deletions src/test_utils/get_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import url from 'url';
* protocol: 'http',
* hostname: 'localhost',
* port: 9220,
* auth: kibanaTestUser.username + ':' + kibanaTestUser.password
* auth: opensearchDashboardsTestUser.username + ':' + opensearchDashboardsTestUser.password
* }
* @param {object} app The params to append
* example:
* {
* pathname: 'app/kibana',
* pathname: 'app/opensearch-dashboards',
* hash: '/discover'
* }
* @return {string}
Expand Down
6 changes: 3 additions & 3 deletions src/test_utils/public/enzyme_helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*/

/**
* Components using the @kbn/i18n module require access to the intl context.
* Components using the @osd/i18n module require access to the intl context.
* This is not available when mounting single components in Enzyme.
* These helper functions aim to address that and wrap a valid,
* intl context around them.
*/

import { I18nProvider, InjectedIntl, intlShape, __IntlProvider } from '@kbn/i18n/react';
import { I18nProvider, InjectedIntl, intlShape, __IntlProvider } from '@osd/i18n/react';
import { mount, ReactWrapper, render, shallow } from 'enzyme';
import React, { ReactElement, ValidationMap } from 'react';

Expand Down Expand Up @@ -52,7 +52,7 @@ function getOptions(context = {}, childContextTypes: ValidationMap<any> = {}, pr
}

/**
* When using @kbn/i18n `injectI18n` on components, props.intl is required.
* When using @osd/i18n `injectI18n` on components, props.intl is required.
*/
function nodeWithIntlProp<T>(node: ReactElement<T>): ReactElement<T & { intl: InjectedIntl }> {
return React.cloneElement<any>(node, { intl });
Expand Down

0 comments on commit 8380e42

Please sign in to comment.