2020-06-26 08:59:00 +00:00
|
|
|
import _fs from 'fs-extra';
|
2021-08-15 06:21:08 +00:00
|
|
|
import { setGlobalConfig } from '../../config/global';
|
2021-05-17 13:21:28 +00:00
|
|
|
import type { UpdateArtifactsConfig } from '../types';
|
2020-06-26 08:59:00 +00:00
|
|
|
import { updateArtifacts } from './artifacts';
|
|
|
|
|
|
|
|
const fs: jest.Mocked<typeof _fs> = _fs as any;
|
|
|
|
|
|
|
|
jest.mock('fs-extra');
|
|
|
|
jest.mock('child_process');
|
|
|
|
jest.mock('../../util/exec');
|
|
|
|
|
2021-05-17 13:21:28 +00:00
|
|
|
const config: UpdateArtifactsConfig = {};
|
2020-06-26 08:59:00 +00:00
|
|
|
|
|
|
|
const newPackageFileContent = `atomicwrites==1.4.0 \
|
|
|
|
--hash=sha256:03472c30eb2c5d1ba9227e4c2ca66ab8287fbfbbda3888aa93dc2e28fc6811b4 \
|
|
|
|
--hash=sha256:75a9445bac02d8d058d5e1fe689654ba5a6556a1dfd8ce6ec55a0ed79866cfa6`;
|
|
|
|
|
2021-08-18 05:46:56 +00:00
|
|
|
describe('manager/pip_requirements/artifacts', () => {
|
2020-06-26 08:59:00 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
jest.resetModules();
|
2021-08-16 16:00:51 +00:00
|
|
|
setGlobalConfig({ localDir: '' });
|
2020-06-26 08:59:00 +00:00
|
|
|
});
|
|
|
|
it('returns null if no updatedDeps were provided', async () => {
|
|
|
|
expect(
|
|
|
|
await updateArtifacts({
|
|
|
|
packageFileName: 'requirements.txt',
|
|
|
|
updatedDeps: [],
|
|
|
|
newPackageFileContent,
|
2021-05-14 13:09:40 +00:00
|
|
|
config,
|
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns null if no hashes', async () => {
|
|
|
|
fs.readFile.mockResolvedValueOnce('eventlet==0.30.2\npbr>=1.9\n' as any);
|
|
|
|
expect(
|
|
|
|
await updateArtifacts({
|
|
|
|
packageFileName: 'requirements.txt',
|
2021-06-26 13:29:01 +00:00
|
|
|
updatedDeps: [{ depName: 'eventlet' }],
|
2021-05-14 13:09:40 +00:00
|
|
|
newPackageFileContent,
|
2020-06-26 08:59:00 +00:00
|
|
|
config,
|
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns null if unchanged', async () => {
|
|
|
|
fs.readFile.mockResolvedValueOnce(newPackageFileContent as any);
|
|
|
|
expect(
|
|
|
|
await updateArtifacts({
|
|
|
|
packageFileName: 'requirements.txt',
|
2021-06-26 13:29:01 +00:00
|
|
|
updatedDeps: [{ depName: 'atomicwrites' }],
|
2020-06-26 08:59:00 +00:00
|
|
|
newPackageFileContent,
|
|
|
|
config,
|
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
it('returns updated file', async () => {
|
|
|
|
fs.readFile.mockResolvedValueOnce('new content' as any);
|
|
|
|
expect(
|
|
|
|
await updateArtifacts({
|
|
|
|
packageFileName: 'requirements.txt',
|
2021-06-26 13:29:01 +00:00
|
|
|
updatedDeps: [{ depName: 'atomicwrites' }],
|
2020-06-26 08:59:00 +00:00
|
|
|
newPackageFileContent,
|
|
|
|
config,
|
|
|
|
})
|
|
|
|
).toHaveLength(1);
|
|
|
|
});
|
|
|
|
it('catches and returns errors', async () => {
|
|
|
|
fs.readFile.mockResolvedValueOnce('new content' as any);
|
|
|
|
expect(
|
|
|
|
await updateArtifacts({
|
|
|
|
packageFileName: null,
|
2021-06-26 13:29:01 +00:00
|
|
|
updatedDeps: [{ depName: 'atomicwrites' }],
|
2020-06-26 08:59:00 +00:00
|
|
|
newPackageFileContent,
|
|
|
|
config,
|
|
|
|
})
|
|
|
|
).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|