Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update unit tests #233

Merged
merged 9 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/osd-apm-config-loader/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const getDefaultConfig = (isDistributable: boolean): ApmAgentConfig => {
return {
active: false,
serverUrl: 'https://f1542b814f674090afd914960583265f.apm.us-central1.gcp.cloud.es.io:443',
// TODO: serverUrl
// TODO: [RENAMEME] Update serverUrl and secretToken if we have replacements
// The secretToken below is intended to be hardcoded in this file even though
// it makes it public. This is not a security/privacy issue. Normally we'd
// instead disable the need for a secretToken in the APM Server config where
Expand Down
Binary file modified packages/osd-opensearch/src/utils/__fixtures__/snapshot.tar.gz
Binary file not shown.
Binary file modified packages/osd-opensearch/src/utils/__fixtures__/snapshot.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/osd-pm/src/utils/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('#getExecutables()', () => {
});

expect(project.getExecutables()).toEqual({
opensearchDashboards: resolve(rootPath, 'bin/script.js'),
'opensearch-dashboards': resolve(rootPath, 'bin/script.js'),
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ const HAS_METADATA = dedent`

some text

<!-- opensearchDashboardsCiData = {"failed-test": {"foo": "bar"}} -->
<!-- OpenSearchDashboardsCiData = {"failed-test": {"foo": "bar"}} -->
`;

const HAS_SOME_OTHER_METADATA = dedent`
# my issue

some text

<!-- opensearchDashboardsCiData = {"some-other": {"foo": "bar"}} -->
<!-- OpenSearchDashboardsCiData = {"some-other": {"foo": "bar"}} -->
`;

const INVALID_METADATA = dedent`
# my issue

some text

<!-- opensearchDashboardsCiData = {"failed-test" -->
<!-- OpenSearchDashboardsCiData = {"failed-test" -->
`;

const MISSING_METADATA = dedent`
Expand Down Expand Up @@ -88,9 +88,7 @@ describe('updateIssueMetadata', () => {

some text

<!-- opensearchDashboardsCiData = {\\"failed-test\\": {\\"foo\\": \\"bar\\"}} -->

<!-- OpenSearchDashboardsCiData = {\\"failed-test\\":{\\"box\\":\\"baz\\"}} -->"
<!-- OpenSearchDashboardsCiData = {\\"failed-test\\":{\\"foo\\":\\"bar\\",\\"box\\":\\"baz\\"}} -->"
`);
});

Expand All @@ -116,9 +114,7 @@ describe('updateIssueMetadata', () => {

some text

<!-- opensearchDashboardsCiData = {\\"some-other\\": {\\"foo\\": \\"bar\\"}} -->

<!-- OpenSearchDashboardsCiData = {\\"failed-test\\":{\\"box\\":\\"baz\\"}} -->"
<!-- OpenSearchDashboardsCiData = {\\"some-other\\":{\\"foo\\":\\"bar\\"},\\"failed-test\\":{\\"box\\":\\"baz\\"}} -->"
`);
});

Expand All @@ -132,8 +128,6 @@ describe('updateIssueMetadata', () => {

some text

<!-- opensearchDashboardsCiData = {\\"failed-test\\" -->

<!-- OpenSearchDashboardsCiData = {\\"failed-test\\":{\\"box\\":\\"baz\\"}} -->"
`);
});
Expand Down
Binary file modified src/cli_plugin/install/__fixtures__/replies/invalid_name.zip
Binary file not shown.
Binary file modified src/cli_plugin/install/__fixtures__/replies/test_plugin.zip
Binary file not shown.
Binary file not shown.
Binary file modified src/cli_plugin/install/__fixtures__/replies/test_plugin_many.zip
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions src/cli_plugin/install/pack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ describe('opensearchDashboards cli', function () {
"bin",
"bin/executable",
"bin/not-executable",
"opensearch_dashboards.json",
"node_modules",
"node_modules/some-package",
"node_modules/some-package/index.js",
"node_modules/some-package/package.json",
"opensearch_dashboards.json",
"public",
"public/index.js",
]
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('opensearchDashboards cli', function () {
it('throw an error if there an invalid plugin name', async () => {
await copyReplyFile('invalid_name.zip');
await expect(getPackData(settings, logger)).rejects.toThrowErrorMatchingInlineSnapshot(
`"No opensearch-dashboards plugins found in archive"`
`"Invalid plugin name [invalid name] in opensearch_dashboards.json, expected it to be valid camelCase"`
mihirsoni marked this conversation as resolved.
Show resolved Hide resolved
);
});
});
Expand Down
25 changes: 23 additions & 2 deletions src/cli_plugin/install/zip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ describe('opensearchDashboards cli', function () {
describe('analyzeArchive', function () {
it('returns array of plugins', async () => {
const packages = await analyzeArchive(archivePath);
expect(packages).toMatchInlineSnapshot(`Array []`);
expect(packages).toMatchInlineSnapshot(`
Array [
Object {
"id": "testPlugin",
"opensearchDashboardsVersion": "1.0.0",
"stripPrefix": "opensearch-dashboards/test-plugin",
},
]
`);
mihirsoni marked this conversation as resolved.
Show resolved Hide resolved
});
});

Expand All @@ -56,7 +64,20 @@ describe('opensearchDashboards cli', function () {
const archive = path.resolve(repliesPath, 'test_plugin.zip');
await extractArchive(archive, tempPath, 'opensearch-dashboards/test-plugin');

expect(glob.sync('**/*', { cwd: tempPath })).toMatchInlineSnapshot(`Array []`);
expect(glob.sync('**/*', { cwd: tempPath })).toMatchInlineSnapshot(`
Array [
"bin",
"bin/executable",
"bin/not-executable",
"node_modules",
"node_modules/some-package",
"node_modules/some-package/index.js",
"node_modules/some-package/package.json",
"opensearch_dashboards.json",
"public",
"public/index.js",
]
`);
});
});

Expand Down
3 changes: 1 addition & 2 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export class DocLinksService {
public setup() {}
public start({ injectedMetadata }: StartDeps): DocLinksStart {
const DOC_LINK_VERSION = injectedMetadata.getOpenSearchDashboardsBranch();
// const OPENSEARCH_WEBSITE_URL = 'https://www.opensearch.co/';
const OPENSEARCH_WEBSITE_URL = 'https://www.opensearch.com/';
const OPENSEARCH_WEBSITE_URL = 'https://www.opensearch.co/';
const OPENSEARCH_DOCS = `${OPENSEARCH_WEBSITE_URL}guide/en/elasticsearch/reference/${DOC_LINK_VERSION}/`;

return deepFreeze({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ test('return manifest when plugin expected OpenSearch Dashboards version is `ope
JSON.stringify({
id: 'someId',
version: 'some-version',
opensearchDashboardsVersion: 'opensearch-dashboards',
opensearchDashboardsVersion: 'opensearchDashboards',
requiredPlugins: ['some-required-plugin'],
server: true,
ui: true,
Expand All @@ -416,7 +416,7 @@ test('return manifest when plugin expected OpenSearch Dashboards version is `ope
id: 'someId',
configPath: 'some_id',
version: 'some-version',
opensearchDashboardsVersion: 'opensearch-dashboards',
opensearchDashboardsVersion: 'opensearchDashboards',
optionalPlugins: [],
requiredPlugins: ['some-required-plugin'],
requiredBundles: [],
Expand Down
6 changes: 2 additions & 4 deletions src/core/server/plugins/discovery/plugins_discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ describe('plugins discovery system', () => {
const plugins = await plugin$.pipe(toArray()).toPromise();
const pluginNames = plugins.map((plugin) => plugin.name);

expect(pluginNames).toHaveLength(3);
expect(pluginNames).toEqual(expect.arrayContaining(['pluginA', 'pluginB', 'pluginC']));
expect(pluginNames).toHaveLength(2);
expect(pluginNames).toEqual(expect.arrayContaining(['pluginA', 'pluginB']));
mihirsoni marked this conversation as resolved.
Show resolved Hide resolved
});

it('return errors when the manifest is invalid or incompatible', async () => {
Expand Down Expand Up @@ -230,11 +230,9 @@ describe('plugins discovery system', () => {
.toPromise();

const srcPluginsPath = resolve(OPENSEARCH_DASHBOARDS_ROOT, 'src', 'plugins');
const xpackPluginsPath = resolve(OPENSEARCH_DASHBOARDS_ROOT, 'x-pack', 'plugins');
expect(errors).toEqual(
expect.arrayContaining([
`Error: EACCES, permission denied '${srcPluginsPath}' (invalid-search-path, ${srcPluginsPath})`,
`Error: ENOENT, no such file or directory '${xpackPluginsPath}' (invalid-search-path, ${xpackPluginsPath})`,
])
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const migratorInstanceMock = mockOpenSearchDashboardsMigrator.create();
export const OpenSearchDashboardsMigratorMock = jest
.fn()
.mockImplementation(() => migratorInstanceMock);
jest.doMock('./migrations/opensearch-dashboards/opensearch_dashboards_migrator', () => ({
jest.doMock('./migrations/opensearch_dashboards/opensearch_dashboards_migrator', () => ({
OpenSearchDashboardsMigrator: OpenSearchDashboardsMigratorMock,
}));

Expand Down
7 changes: 6 additions & 1 deletion src/dev/jest/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ export default {
coverageDirectory: '<rootDir>/target/opensearch-dashboards-coverage/jest',
coverageReporters: ['html', 'text'],
moduleFileExtensions: ['js', 'mjs', 'json', 'ts', 'tsx', 'node'],
modulePathIgnorePatterns: ['__fixtures__/', 'target/'],
modulePathIgnorePatterns: [
'__fixtures__/',
'target/',
'<rootDir>/src/plugins/maps_legacy',
'<rootDir>/src/plugins/region_map',
mihirsoni marked this conversation as resolved.
Show resolved Hide resolved
],
testEnvironment: 'jest-environment-jsdom-thirteen',
testMatch: ['**/*.test.{js,mjs,ts,tsx}'],
testPathIgnorePatterns: [
Expand Down
15 changes: 0 additions & 15 deletions src/optimize/bundles_route/bundles_route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,6 @@ describe('validation', () => {
});
});

describe('image', () => {
it('responds with exact file data', async () => {
const server = createServer();
const response = await server.inject({
url: '/1234/bundles/plugin/foo/image.png',
});

expect(response.statusCode).toBe(200);
const image = readFileSync(resolve(fooPluginFixture, 'image.png'));
expect(response.headers).toHaveProperty('content-length', image.length);
expect(response.headers).toHaveProperty('content-type', 'image/png');
expect(image).toEqual(response.rawPayload);
});
});

describe('js file', () => {
it('responds with no content-length and exact file data', async () => {
const server = createServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Settings', function () {
describe('Advanced', function () {
describe('getCategoryName(category)', function () {
it('should capitalize unknown category', function () {
expect(getCategoryName('opensearch')).to.be('OpenSearch');
expect(getCategoryName('unknown')).to.be('Unknown');
mihirsoni marked this conversation as resolved.
Show resolved Hide resolved
});

it('should return empty string for no category', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('utils/osd_field_types', () => {
test('returns a OsdFieldType instance by name', () => {
const osdFieldType = getOsdFieldType(OPENSEARCH_FIELD_TYPES.STRING);

expect(osdFieldType).toBeInstanceOf(osdFieldType);
expect(osdFieldType).toBeInstanceOf(OsdFieldType);
expect(osdFieldType).toHaveProperty('name', OPENSEARCH_FIELD_TYPES.STRING);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('OpenSearch search strategy', () => {
get: () => {},
},
},
elasticsearch: { client: { asCurrentUser: { search: mockApiCaller } } },
opensearch: { client: { asCurrentUser: { search: mockApiCaller } } },
},
};
const mockConfig$ = pluginInitializerContextConfigMock<any>({}).legacy.globalConfig$;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
* under the License.
*/

import { elasticsearchServiceMock } from '../../../../../core/server/mocks';
import { opensearchServiceMock } from '../../../../../core/server/mocks';
import { shimAbortSignal } from '.';

describe('shimAbortSignal', () => {
it('aborts the promise if the signal is aborted', () => {
const promise = elasticsearchServiceMock.createSuccessTransportRequestPromise({
const promise = opensearchServiceMock.createSuccessTransportRequestPromise({
success: true,
});
const controller = new AbortController();
Expand All @@ -33,7 +33,7 @@ describe('shimAbortSignal', () => {
});

it('returns the original promise', async () => {
const promise = elasticsearchServiceMock.createSuccessTransportRequestPromise({
const promise = opensearchServiceMock.createSuccessTransportRequestPromise({
success: true,
});
const controller = new AbortController();
Expand All @@ -43,7 +43,7 @@ describe('shimAbortSignal', () => {
});

it('allows the promise to be aborted manually', () => {
const promise = elasticsearchServiceMock.createSuccessTransportRequestPromise({
const promise = opensearchServiceMock.createSuccessTransportRequestPromise({
success: true,
});
const controller = new AbortController();
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/server/search/routes/msearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('msearch route', () => {
const mockClient = { msearch: jest.fn().mockResolvedValue(response) };
const mockContext = {
core: {
elasticsearch: { client: { asCurrentUser: mockClient } },
opensearch: { client: { asCurrentUser: mockClient } },
uiSettings: { client: { get: jest.fn() } },
},
};
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('msearch route', () => {
};
const mockContext = {
core: {
elasticsearch: { client: { asCurrentUser: mockClient } },
opensearch: { client: { asCurrentUser: mockClient } },
uiSettings: { client: { get: jest.fn() } },
},
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ test('should add `noreferrer` and `nooopener` to unknown links in new tabs', ()
expect(component.render().find('a').prop('rel')).toBe('noopener noreferrer');
});

test('should only add `nooopener` to known links in new tabs', () => {
// TODO: In @elastic/eui/src/services/url.ts it is unknown if it does not match the regex
// TODO: [RENAMEME] if we fork EUI and update that regex then we can include this test again
xtest('should only add `nooopener` to known links in new tabs', () => {
const component = shallow(
<Markdown openLinksInNewTab={true} markdown="[link](https://www.opensearch.co/cool/path" />
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import {
savedObjectsRepositoryMock,
loggingSystemMock,
opensearchDashboardsServiceMock,
opensearchServiceMock,
} from '../../../../../core/server/mocks';
import {
CollectorOptions,
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('telemetry_application_usage', () => {
const getUsageCollector = jest.fn();
const registerType = jest.fn();
const callCluster = jest.fn();
const opensearchClient = opensearchDashboardsServiceMock.createClusterClient().asInternalUser;
const opensearchClient = opensearchServiceMock.createClusterClient().asInternalUser;

beforeAll(() =>
registerApplicationUsageCollector(logger, usageCollectionMock, registerType, getUsageCollector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('telemetry_opensearch_dashboards', () => {

test('fetch', async () => {
expect(await collector.fetch(callCluster)).toStrictEqual({
index: '.opensearch_dashboards-tests',
index: '.opensearch_dashboards_tests',
dashboard: { total: 0 },
visualization: { total: 0 },
search: { total: 0 },
Expand All @@ -59,7 +59,7 @@ describe('telemetry_opensearch_dashboards', () => {

test('formatForBulkUpload', async () => {
const resultFromFetch = {
index: '.opensearch_dashboards-tests',
index: '.opensearch_dashboards_tests',
dashboard: { total: 0 },
visualization: { total: 0 },
search: { total: 0 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import { defaultAlertText } from './default_alert';

describe('defaultAlertText', () => {
// TODO: [RENAMEME] Ignoring because the defaultAlertText was commented out because it upsells a hosted solution.
xdescribe('defaultAlertText', () => {
ananzh marked this conversation as resolved.
Show resolved Hide resolved
it('creates a valid MountPoint that can cleanup correctly', () => {
const mountPoint = defaultAlertText(jest.fn());

Expand Down
1 change: 0 additions & 1 deletion src/plugins/share/public/opensearch_dashboards_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/

// TODO: Replace this logic with OpenSearchDashboardsURL once it is available.
// https://github.com/elastic/kibana/issues/64497
export class OpenSearchDashboardsURL {
public readonly path: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { SavedObjectsClientContract, SavedObject } from 'opensearch-dashboards/s
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../core/server/mocks';

describe('shortUrlLookupProvider', () => {
const ID = 'bf00ad16941fc51420f91a93428b27a0';
const ID = '631b8fa45c5d0b8948aaf38cc3a001ca';
const TYPE = 'url';
const URL = 'http://opensearch.co';

Expand Down
Loading