From ee6a4c9ae6143d77392322830b7c08c1d5215a8b Mon Sep 17 00:00:00 2001 From: Mark Hopkin Date: Mon, 20 Jun 2022 16:17:31 +0100 Subject: [PATCH 1/6] move getPathParts tests into describe block --- .../services/epm/registry/index.test.ts | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts index 62ea278734795..be92c061065b3 100644 --- a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts @@ -10,46 +10,47 @@ import { getBufferExtractor, getPathParts, untarBuffer, unzipBuffer } from '../a import { splitPkgKey } from '.'; -const testPaths = [ - { - path: 'foo-1.1.0/service/type/file.yml', - assetParts: { - dataset: undefined, - file: 'file.yml', +describe('getPathParts', () => { + const testPaths = [ + { path: 'foo-1.1.0/service/type/file.yml', - pkgkey: 'foo-1.1.0', - service: 'service', - type: 'type', + assetParts: { + dataset: undefined, + file: 'file.yml', + path: 'foo-1.1.0/service/type/file.yml', + pkgkey: 'foo-1.1.0', + service: 'service', + type: 'type', + }, }, - }, - { - path: 'iptables-1.0.4/kibana/visualization/683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', - assetParts: { - dataset: undefined, - file: '683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', + { path: 'iptables-1.0.4/kibana/visualization/683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', - pkgkey: 'iptables-1.0.4', - service: 'kibana', - type: 'visualization', + assetParts: { + dataset: undefined, + file: '683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', + path: 'iptables-1.0.4/kibana/visualization/683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', + pkgkey: 'iptables-1.0.4', + service: 'kibana', + type: 'visualization', + }, }, - }, - { - path: 'coredns-1.0.1/data_stream/stats/fields/coredns.stats.yml', - assetParts: { - dataset: 'stats', - file: 'coredns.stats.yml', + { path: 'coredns-1.0.1/data_stream/stats/fields/coredns.stats.yml', - pkgkey: 'coredns-1.0.1', - service: '', - type: 'fields', + assetParts: { + dataset: 'stats', + file: 'coredns.stats.yml', + path: 'coredns-1.0.1/data_stream/stats/fields/coredns.stats.yml', + pkgkey: 'coredns-1.0.1', + service: '', + type: 'fields', + }, }, - }, -]; - -test('testPathParts', () => { - for (const value of testPaths) { - expect(getPathParts(value.path)).toStrictEqual(value.assetParts as AssetParts); - } + ]; + test('testPathParts', () => { + for (const value of testPaths) { + expect(getPathParts(value.path)).toStrictEqual(value.assetParts as AssetParts); + } + }); }); describe('splitPkgKey tests', () => { @@ -119,3 +120,5 @@ describe('getBufferExtractor called with { contentType }', () => { expect(extractor).toEqual(undefined); }); }); + +describe('fetchFindLatestPackageOrUndefined', () => {}); From 5b0452aa418599d1f524113bd4f05cc934e3b8c0 Mon Sep 17 00:00:00 2001 From: Mark Hopkin Date: Mon, 20 Jun 2022 16:25:09 +0100 Subject: [PATCH 2/6] move archive tests to archive folder --- .../server/services/epm/archive/index.test.ts | 89 +++++++++++++++++++ .../services/epm/registry/index.test.ts | 86 +----------------- 2 files changed, 90 insertions(+), 85 deletions(-) create mode 100644 x-pack/plugins/fleet/server/services/epm/archive/index.test.ts diff --git a/x-pack/plugins/fleet/server/services/epm/archive/index.test.ts b/x-pack/plugins/fleet/server/services/epm/archive/index.test.ts new file mode 100644 index 0000000000000..ab2bb44621b0e --- /dev/null +++ b/x-pack/plugins/fleet/server/services/epm/archive/index.test.ts @@ -0,0 +1,89 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { AssetParts } from '../../../types'; + +import { getBufferExtractor, getPathParts, untarBuffer, unzipBuffer } from '.'; + +describe('getPathParts', () => { + const testPaths = [ + { + path: 'foo-1.1.0/service/type/file.yml', + assetParts: { + dataset: undefined, + file: 'file.yml', + path: 'foo-1.1.0/service/type/file.yml', + pkgkey: 'foo-1.1.0', + service: 'service', + type: 'type', + }, + }, + { + path: 'iptables-1.0.4/kibana/visualization/683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', + assetParts: { + dataset: undefined, + file: '683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', + path: 'iptables-1.0.4/kibana/visualization/683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', + pkgkey: 'iptables-1.0.4', + service: 'kibana', + type: 'visualization', + }, + }, + { + path: 'coredns-1.0.1/data_stream/stats/fields/coredns.stats.yml', + assetParts: { + dataset: 'stats', + file: 'coredns.stats.yml', + path: 'coredns-1.0.1/data_stream/stats/fields/coredns.stats.yml', + pkgkey: 'coredns-1.0.1', + service: '', + type: 'fields', + }, + }, + ]; + test('testPathParts', () => { + for (const value of testPaths) { + expect(getPathParts(value.path)).toStrictEqual(value.assetParts as AssetParts); + } + }); +}); + +describe('getBufferExtractor called with { archivePath }', () => { + it('returns unzipBuffer if `archivePath` ends in .zip', () => { + const extractor = getBufferExtractor({ archivePath: '.zip' }); + expect(extractor).toBe(unzipBuffer); + }); + + it('returns untarBuffer if `archivePath` ends in .gz', () => { + const extractor = getBufferExtractor({ archivePath: '.gz' }); + expect(extractor).toBe(untarBuffer); + const extractor2 = getBufferExtractor({ archivePath: '.tar.gz' }); + expect(extractor2).toBe(untarBuffer); + }); + + it('returns `undefined` if `archivePath` ends in anything else', () => { + const extractor = getBufferExtractor({ archivePath: '.xyz' }); + expect(extractor).toEqual(undefined); + }); +}); + +describe('getBufferExtractor called with { contentType }', () => { + it('returns unzipBuffer if `contentType` is `application/zip`', () => { + const extractor = getBufferExtractor({ contentType: 'application/zip' }); + expect(extractor).toBe(unzipBuffer); + }); + + it('returns untarBuffer if `contentType` is `application/gzip`', () => { + const extractor = getBufferExtractor({ contentType: 'application/gzip' }); + expect(extractor).toBe(untarBuffer); + }); + + it('returns `undefined` if `contentType` ends in anything else', () => { + const extractor = getBufferExtractor({ contentType: '.xyz' }); + expect(extractor).toEqual(undefined); + }); +}); diff --git a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts index be92c061065b3..020b6d7d09bc0 100644 --- a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts @@ -5,55 +5,9 @@ * 2.0. */ -import type { AssetParts } from '../../../types'; -import { getBufferExtractor, getPathParts, untarBuffer, unzipBuffer } from '../archive'; - import { splitPkgKey } from '.'; -describe('getPathParts', () => { - const testPaths = [ - { - path: 'foo-1.1.0/service/type/file.yml', - assetParts: { - dataset: undefined, - file: 'file.yml', - path: 'foo-1.1.0/service/type/file.yml', - pkgkey: 'foo-1.1.0', - service: 'service', - type: 'type', - }, - }, - { - path: 'iptables-1.0.4/kibana/visualization/683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', - assetParts: { - dataset: undefined, - file: '683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', - path: 'iptables-1.0.4/kibana/visualization/683402b0-1f29-11e9-8ec4-cf5d91a864b3-ecs.json', - pkgkey: 'iptables-1.0.4', - service: 'kibana', - type: 'visualization', - }, - }, - { - path: 'coredns-1.0.1/data_stream/stats/fields/coredns.stats.yml', - assetParts: { - dataset: 'stats', - file: 'coredns.stats.yml', - path: 'coredns-1.0.1/data_stream/stats/fields/coredns.stats.yml', - pkgkey: 'coredns-1.0.1', - service: '', - type: 'fields', - }, - }, - ]; - test('testPathParts', () => { - for (const value of testPaths) { - expect(getPathParts(value.path)).toStrictEqual(value.assetParts as AssetParts); - } - }); -}); - -describe('splitPkgKey tests', () => { +describe('splitPkgKey', () => { it('throws an error if there is nothing before the delimiter', () => { expect(() => { splitPkgKey('-0.0.1-dev1'); @@ -84,41 +38,3 @@ describe('splitPkgKey tests', () => { expect(pkgVersion).toBe('0.13.0-alpha.1+abcd'); }); }); - -describe('getBufferExtractor called with { archivePath }', () => { - it('returns unzipBuffer if `archivePath` ends in .zip', () => { - const extractor = getBufferExtractor({ archivePath: '.zip' }); - expect(extractor).toBe(unzipBuffer); - }); - - it('returns untarBuffer if `archivePath` ends in .gz', () => { - const extractor = getBufferExtractor({ archivePath: '.gz' }); - expect(extractor).toBe(untarBuffer); - const extractor2 = getBufferExtractor({ archivePath: '.tar.gz' }); - expect(extractor2).toBe(untarBuffer); - }); - - it('returns `undefined` if `archivePath` ends in anything else', () => { - const extractor = getBufferExtractor({ archivePath: '.xyz' }); - expect(extractor).toEqual(undefined); - }); -}); - -describe('getBufferExtractor called with { contentType }', () => { - it('returns unzipBuffer if `contentType` is `application/zip`', () => { - const extractor = getBufferExtractor({ contentType: 'application/zip' }); - expect(extractor).toBe(unzipBuffer); - }); - - it('returns untarBuffer if `contentType` is `application/gzip`', () => { - const extractor = getBufferExtractor({ contentType: 'application/gzip' }); - expect(extractor).toBe(untarBuffer); - }); - - it('returns `undefined` if `contentType` ends in anything else', () => { - const extractor = getBufferExtractor({ contentType: '.xyz' }); - expect(extractor).toEqual(undefined); - }); -}); - -describe('fetchFindLatestPackageOrUndefined', () => {}); From e6e676160e337a158a8817e81c91b24475439e73 Mon Sep 17 00:00:00 2001 From: Mark Hopkin Date: Mon, 20 Jun 2022 17:18:06 +0100 Subject: [PATCH 3/6] fetchFindLatestPackageOrUndefined tests --- .../services/epm/registry/index.test.ts | 84 ++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts index 020b6d7d09bc0..b7b7e5a62badc 100644 --- a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts @@ -5,7 +5,31 @@ * 2.0. */ -import { splitPkgKey } from '.'; +import { loggingSystemMock } from '@kbn/core-logging-server-mocks'; + +import { splitPkgKey, fetchFindLatestPackageOrUndefined } from '.'; + +const mockLoggerFactory = loggingSystemMock.create(); +const mockLogger = mockLoggerFactory.get('mock logger'); + +const mockGetBundledPackageByName = jest.fn(); +const mockFetchUrl = jest.fn(); +jest.mock('../..', () => ({ + appContextService: { + getLogger: () => mockLogger, + getKibanaBranch: () => 'main', + getKibanaVersion: () => '99.0.0', + getConfig: () => ({}), + }, +})); + +jest.mock('./requests', () => ({ + fetchUrl: (url: string) => mockFetchUrl(url), +})); + +jest.mock('../packages/bundled_packages', () => ({ + getBundledPackageByName: (name: string) => mockGetBundledPackageByName(name), +})); describe('splitPkgKey', () => { it('throws an error if there is nothing before the delimiter', () => { @@ -38,3 +62,61 @@ describe('splitPkgKey', () => { expect(pkgVersion).toBe('0.13.0-alpha.1+abcd'); }); }); + +describe('fetchFindLatestPackageOrUndefined', () => { + afterEach(() => { + mockFetchUrl.mockReset(); + mockGetBundledPackageByName.mockReset(); + }); + + it('Should return registry package if bundled package is older version', async () => { + const bundledPackage = { name: 'testpkg', version: '1.0.0' }; + const registryPackage = { name: 'testpkg', version: '1.0.1' }; + + mockFetchUrl.mockResolvedValue(JSON.stringify([registryPackage])); + + mockGetBundledPackageByName.mockResolvedValue(bundledPackage); + const result = await fetchFindLatestPackageOrUndefined('testpkg'); + expect(result).toEqual(registryPackage); + }); + + it('Should return bundled package if bundled package is newer version', async () => { + const bundledPackage = { name: 'testpkg', version: '1.0.1' }; + const registryPackage = { name: 'testpkg', version: '1.0.0' }; + + mockFetchUrl.mockResolvedValue(JSON.stringify([registryPackage])); + + mockGetBundledPackageByName.mockResolvedValue(bundledPackage); + const result = await fetchFindLatestPackageOrUndefined('testpkg'); + expect(result).toEqual(bundledPackage); + }); + it('Should return bundled package if bundled package there is no registry package', async () => { + const bundledPackage = { name: 'testpkg', version: '1.0.1' }; + + mockFetchUrl.mockResolvedValue(JSON.stringify([])); + + mockGetBundledPackageByName.mockResolvedValue(bundledPackage); + const result = await fetchFindLatestPackageOrUndefined('testpkg'); + expect(result).toEqual(bundledPackage); + }); + + it('Should fall back to bundled package if there is an error getting from the registry', async () => { + const bundledPackage = { name: 'testpkg', version: '1.0.1' }; + + mockFetchUrl.mockRejectedValue(new Error('Registry error')); + + mockGetBundledPackageByName.mockResolvedValue(bundledPackage); + const result = await fetchFindLatestPackageOrUndefined('testpkg'); + expect(result).toEqual(bundledPackage); + }); + + it('Should return undefined if there is a registry error and no bundled package', async () => { + const bundledPackage = null; + + mockFetchUrl.mockRejectedValue(new Error('Registry error')); + + mockGetBundledPackageByName.mockResolvedValue(bundledPackage); + const result = await fetchFindLatestPackageOrUndefined('testpkg'); + expect(result).toEqual(undefined); + }); +}); From 566683f51952ff7374abfa1dc423d9cd6f2a392a Mon Sep 17 00:00:00 2001 From: Mark Hopkin Date: Mon, 20 Jun 2022 17:27:46 +0100 Subject: [PATCH 4/6] fetchFindLatestPackageOrThrow test --- .../services/epm/registry/index.test.ts | 92 +++++++++++-------- 1 file changed, 55 insertions(+), 37 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts index b7b7e5a62badc..72eccca192c6c 100644 --- a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts @@ -7,7 +7,9 @@ import { loggingSystemMock } from '@kbn/core-logging-server-mocks'; -import { splitPkgKey, fetchFindLatestPackageOrUndefined } from '.'; +import { PackageNotFoundError } from '../../../errors'; + +import { splitPkgKey, fetchFindLatestPackageOrUndefined, fetchFindLatestPackageOrThrow } from '.'; const mockLoggerFactory = loggingSystemMock.create(); const mockLogger = mockLoggerFactory.get('mock logger'); @@ -63,60 +65,76 @@ describe('splitPkgKey', () => { }); }); -describe('fetchFindLatestPackageOrUndefined', () => { +describe('fetch package', () => { afterEach(() => { mockFetchUrl.mockReset(); mockGetBundledPackageByName.mockReset(); }); - it('Should return registry package if bundled package is older version', async () => { - const bundledPackage = { name: 'testpkg', version: '1.0.0' }; - const registryPackage = { name: 'testpkg', version: '1.0.1' }; + describe('fetchFindLatestPackageOrUndefined', () => { + it('Should return registry package if bundled package is older version', async () => { + const bundledPackage = { name: 'testpkg', version: '1.0.0' }; + const registryPackage = { name: 'testpkg', version: '1.0.1' }; - mockFetchUrl.mockResolvedValue(JSON.stringify([registryPackage])); + mockFetchUrl.mockResolvedValue(JSON.stringify([registryPackage])); - mockGetBundledPackageByName.mockResolvedValue(bundledPackage); - const result = await fetchFindLatestPackageOrUndefined('testpkg'); - expect(result).toEqual(registryPackage); - }); + mockGetBundledPackageByName.mockResolvedValue(bundledPackage); + const result = await fetchFindLatestPackageOrUndefined('testpkg'); + expect(result).toEqual(registryPackage); + }); - it('Should return bundled package if bundled package is newer version', async () => { - const bundledPackage = { name: 'testpkg', version: '1.0.1' }; - const registryPackage = { name: 'testpkg', version: '1.0.0' }; + it('Should return bundled package if bundled package is newer version', async () => { + const bundledPackage = { name: 'testpkg', version: '1.0.1' }; + const registryPackage = { name: 'testpkg', version: '1.0.0' }; - mockFetchUrl.mockResolvedValue(JSON.stringify([registryPackage])); + mockFetchUrl.mockResolvedValue(JSON.stringify([registryPackage])); - mockGetBundledPackageByName.mockResolvedValue(bundledPackage); - const result = await fetchFindLatestPackageOrUndefined('testpkg'); - expect(result).toEqual(bundledPackage); - }); - it('Should return bundled package if bundled package there is no registry package', async () => { - const bundledPackage = { name: 'testpkg', version: '1.0.1' }; + mockGetBundledPackageByName.mockResolvedValue(bundledPackage); + const result = await fetchFindLatestPackageOrUndefined('testpkg'); + expect(result).toEqual(bundledPackage); + }); + it('Should return bundled package if bundled package there is no registry package', async () => { + const bundledPackage = { name: 'testpkg', version: '1.0.1' }; - mockFetchUrl.mockResolvedValue(JSON.stringify([])); + mockFetchUrl.mockResolvedValue(JSON.stringify([])); - mockGetBundledPackageByName.mockResolvedValue(bundledPackage); - const result = await fetchFindLatestPackageOrUndefined('testpkg'); - expect(result).toEqual(bundledPackage); - }); + mockGetBundledPackageByName.mockResolvedValue(bundledPackage); + const result = await fetchFindLatestPackageOrUndefined('testpkg'); + expect(result).toEqual(bundledPackage); + }); - it('Should fall back to bundled package if there is an error getting from the registry', async () => { - const bundledPackage = { name: 'testpkg', version: '1.0.1' }; + it('Should fall back to bundled package if there is an error getting from the registry', async () => { + const bundledPackage = { name: 'testpkg', version: '1.0.1' }; - mockFetchUrl.mockRejectedValue(new Error('Registry error')); + mockFetchUrl.mockRejectedValue(new Error('Registry error')); - mockGetBundledPackageByName.mockResolvedValue(bundledPackage); - const result = await fetchFindLatestPackageOrUndefined('testpkg'); - expect(result).toEqual(bundledPackage); + mockGetBundledPackageByName.mockResolvedValue(bundledPackage); + const result = await fetchFindLatestPackageOrUndefined('testpkg'); + expect(result).toEqual(bundledPackage); + }); + + it('Should return undefined if there is a registry error and no bundled package', async () => { + const bundledPackage = null; + + mockFetchUrl.mockRejectedValue(new Error('Registry error')); + + mockGetBundledPackageByName.mockResolvedValue(bundledPackage); + const result = await fetchFindLatestPackageOrUndefined('testpkg'); + expect(result).toEqual(undefined); + }); }); - it('Should return undefined if there is a registry error and no bundled package', async () => { - const bundledPackage = null; + describe('fetchFindLatestPackageOrThrow', () => { + it('Should return undefined if there is a registry error and no bundled package', async () => { + const bundledPackage = null; + + mockFetchUrl.mockRejectedValue(new Error('Registry error')); - mockFetchUrl.mockRejectedValue(new Error('Registry error')); + mockGetBundledPackageByName.mockResolvedValue(bundledPackage); - mockGetBundledPackageByName.mockResolvedValue(bundledPackage); - const result = await fetchFindLatestPackageOrUndefined('testpkg'); - expect(result).toEqual(undefined); + expect(() => fetchFindLatestPackageOrThrow('testpkg')).rejects.toBeInstanceOf( + PackageNotFoundError + ); + }); }); }); From b97ff5055acadcde8eb47b801a8159b2f2d6586c Mon Sep 17 00:00:00 2001 From: Mark Hopkin Date: Mon, 20 Jun 2022 17:36:39 +0100 Subject: [PATCH 5/6] move generic tests to util fn --- .../server/services/epm/registry/index.test.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts index 72eccca192c6c..86db00b0ca03b 100644 --- a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts @@ -71,7 +71,8 @@ describe('fetch package', () => { mockGetBundledPackageByName.mockReset(); }); - describe('fetchFindLatestPackageOrUndefined', () => { + type FetchFn = typeof fetchFindLatestPackageOrThrow | typeof fetchFindLatestPackageOrUndefined; + const performGenericFetchTests = (fetchMethodToTest: FetchFn) => { it('Should return registry package if bundled package is older version', async () => { const bundledPackage = { name: 'testpkg', version: '1.0.0' }; const registryPackage = { name: 'testpkg', version: '1.0.1' }; @@ -79,7 +80,7 @@ describe('fetch package', () => { mockFetchUrl.mockResolvedValue(JSON.stringify([registryPackage])); mockGetBundledPackageByName.mockResolvedValue(bundledPackage); - const result = await fetchFindLatestPackageOrUndefined('testpkg'); + const result = await fetchMethodToTest('testpkg'); expect(result).toEqual(registryPackage); }); @@ -90,7 +91,7 @@ describe('fetch package', () => { mockFetchUrl.mockResolvedValue(JSON.stringify([registryPackage])); mockGetBundledPackageByName.mockResolvedValue(bundledPackage); - const result = await fetchFindLatestPackageOrUndefined('testpkg'); + const result = await fetchMethodToTest('testpkg'); expect(result).toEqual(bundledPackage); }); it('Should return bundled package if bundled package there is no registry package', async () => { @@ -99,7 +100,7 @@ describe('fetch package', () => { mockFetchUrl.mockResolvedValue(JSON.stringify([])); mockGetBundledPackageByName.mockResolvedValue(bundledPackage); - const result = await fetchFindLatestPackageOrUndefined('testpkg'); + const result = await fetchMethodToTest('testpkg'); expect(result).toEqual(bundledPackage); }); @@ -109,10 +110,13 @@ describe('fetch package', () => { mockFetchUrl.mockRejectedValue(new Error('Registry error')); mockGetBundledPackageByName.mockResolvedValue(bundledPackage); - const result = await fetchFindLatestPackageOrUndefined('testpkg'); + const result = await fetchMethodToTest('testpkg'); expect(result).toEqual(bundledPackage); }); + }; + describe('fetchFindLatestPackageOrUndefined', () => { + performGenericFetchTests(fetchFindLatestPackageOrUndefined); it('Should return undefined if there is a registry error and no bundled package', async () => { const bundledPackage = null; @@ -125,6 +129,7 @@ describe('fetch package', () => { }); describe('fetchFindLatestPackageOrThrow', () => { + performGenericFetchTests(fetchFindLatestPackageOrThrow); it('Should return undefined if there is a registry error and no bundled package', async () => { const bundledPackage = null; From 97c08203b212ff11709505699fe67c8e2d445eb2 Mon Sep 17 00:00:00 2001 From: Mark Hopkin Date: Mon, 20 Jun 2022 19:32:48 +0100 Subject: [PATCH 6/6] fix spelling --- x-pack/plugins/fleet/server/services/epm/registry/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts index 86db00b0ca03b..e9427732d4aef 100644 --- a/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/registry/index.test.ts @@ -94,7 +94,7 @@ describe('fetch package', () => { const result = await fetchMethodToTest('testpkg'); expect(result).toEqual(bundledPackage); }); - it('Should return bundled package if bundled package there is no registry package', async () => { + it('Should return bundled package if there is no registry package', async () => { const bundledPackage = { name: 'testpkg', version: '1.0.1' }; mockFetchUrl.mockResolvedValue(JSON.stringify([]));