Skip to content

Commit

Permalink
includes readBundledPackage with other package service tests/mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ogupte committed Apr 18, 2023
1 parent cecca8e commit 06bdf41
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const createClientMock = (): jest.Mocked<PackageClient> => ({
getInstallation: jest.fn(),
ensureInstalledPackage: jest.fn(),
fetchFindLatestPackage: jest.fn(),
readBundledPackage: jest.fn(),
getPackage: jest.fn(),
getPackages: jest.fn(),
reinstallEsAssets: jest.fn(),
Expand Down
19 changes: 19 additions & 0 deletions x-pack/plugins/fleet/server/services/epm/package_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ import * as epmPackagesGet from './packages/get';
import * as epmPackagesInstall from './packages/install';
import * as epmRegistry from './registry';
import * as epmTransformsInstall from './elasticsearch/transform/install';
import * as epmArchiveParse from './archive/parse';

const testKeys = [
'getInstallation',
'ensureInstalledPackage',
'fetchFindLatestPackage',
'getPackage',
'reinstallEsAssets',
'readBundledPackage',
];

function getTest(
Expand Down Expand Up @@ -144,6 +146,23 @@ function getTest(
],
};
break;
case testKeys[5]:
const bundledPackage = { name: 'package name', version: '8.0.0', buffer: Buffer.from([]) };
test = {
method: mocks.packageClient.readBundledPackage.bind(mocks.packageClient),
args: [bundledPackage],
spy: jest.spyOn(epmArchiveParse, 'generatePackageInfoFromArchiveBuffer'),
spyArgs: [bundledPackage.buffer, 'application/zip'],
spyResponse: {
packageInfo: { name: 'readBundledPackage test' },
paths: ['/some/test/path'],
},
expectedReturnValue: {
packageInfo: { name: 'readBundledPackage test' },
paths: ['/some/test/path'],
},
};
break;
default:
throw new Error('invalid test key');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class PackageClientImpl implements PackageClient {
}

public async readBundledPackage(bundledPackage: BundledPackage) {
await this.#runPreflight();
return generatePackageInfoFromArchiveBuffer(bundledPackage.buffer, 'application/zip');
}

Expand Down

0 comments on commit 06bdf41

Please sign in to comment.