Skip to content

Commit

Permalink
Adjust unit test to pick buffer extractor.
Browse files Browse the repository at this point in the history
  • Loading branch information
skh committed Oct 5, 2020
1 parent f54e3a2 commit 2c30b69
Showing 1 changed file with 2 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@

import { AssetParts } from '../../../types';
import { getBufferExtractor, pathParts, splitPkgKey } from './index';
import { getArchiveLocation } from './cache';
import { untarBuffer, unzipBuffer } from './extract';

jest.mock('./cache', () => {
return {
getArchiveLocation: jest.fn(),
};
});

const mockedGetArchiveLocation = getArchiveLocation as jest.Mock;

const testPaths = [
{
path: 'foo-1.1.0/service/type/file.yml',
Expand Down Expand Up @@ -92,19 +83,13 @@ describe('splitPkgKey tests', () => {
});

describe('getBufferExtractor', () => {
it('throws if the archive has not been downloaded/cached yet', () => {
expect(() => getBufferExtractor('missing', '1.2.3')).toThrow('no archive location');
});

it('returns unzipBuffer if the archive key ends in .zip', () => {
mockedGetArchiveLocation.mockImplementation(() => '.zip');
const extractor = getBufferExtractor('will-use-mocked-key', 'a.b.c');
const extractor = getBufferExtractor('.zip');
expect(extractor).toBe(unzipBuffer);
});

it('returns untarBuffer if the key ends in anything else', () => {
mockedGetArchiveLocation.mockImplementation(() => 'xyz');
const extractor = getBufferExtractor('will-use-mocked-key', 'a.b.c');
const extractor = getBufferExtractor('.xyz');
expect(extractor).toBe(untarBuffer);
});
});

0 comments on commit 2c30b69

Please sign in to comment.