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

refactor: move util/fs under util/gitfs #6618

Merged
merged 3 commits into from Jun 28, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 33 additions & 33 deletions lib/manager/bundler/artifacts.spec.ts
Expand Up @@ -8,11 +8,11 @@ import { setUtilConfig } from '../../util';
import { BinarySource } from '../../util/exec/common';
import * as docker from '../../util/exec/docker';
import * as _env from '../../util/exec/env';
import * as _fs from '../../util/fs';
import * as _gitfs from '../../util/gitfs';
import * as _bundlerHostRules from './host-rules';
import { updateArtifacts } from '.';

const fs: jest.Mocked<typeof _fs> = _fs as any;
const gitfs: jest.Mocked<typeof _gitfs> = _gitfs as any;
const exec: jest.Mock<typeof _exec> = _exec as any;
const env = mocked(_env);
const datasource = mocked(_datasource);
Expand All @@ -22,7 +22,7 @@ jest.mock('fs-extra');
jest.mock('child_process');
jest.mock('../../../lib/util/exec/env');
jest.mock('../../../lib/datasource');
jest.mock('../../../lib/util/fs');
jest.mock('../../../lib/util/gitfs');
jest.mock('../../../lib/util/host-rules');
jest.mock('./host-rules');

Expand Down Expand Up @@ -59,13 +59,13 @@ describe('bundler.updateArtifacts()', () => {
).toBeNull();
});
it('returns null if Gemfile.lock was not changed', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
fs.writeLocalFile.mockResolvedValueOnce(null as never);
gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
gitfs.writeLocalFile.mockResolvedValueOnce(null as never);
const execSnapshots = mockExecAll(exec);
platform.getRepoStatus.mockResolvedValueOnce({
modified: [],
} as Git.StatusResult);
fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts({
packageFileName: 'Gemfile',
Expand All @@ -77,14 +77,14 @@ describe('bundler.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot();
});
it('works for default binarySource', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
fs.writeLocalFile.mockResolvedValueOnce(null as never);
fs.readLocalFile.mockResolvedValueOnce(null);
gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
gitfs.writeLocalFile.mockResolvedValueOnce(null as never);
gitfs.readLocalFile.mockResolvedValueOnce(null);
const execSnapshots = mockExecAll(exec);
platform.getRepoStatus.mockResolvedValueOnce({
modified: ['Gemfile.lock'],
} as Git.StatusResult);
fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts({
packageFileName: 'Gemfile',
Expand All @@ -96,14 +96,14 @@ describe('bundler.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot();
});
it('works explicit global binarySource', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
fs.writeLocalFile.mockResolvedValueOnce(null as never);
fs.readLocalFile.mockResolvedValueOnce(null);
gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
gitfs.writeLocalFile.mockResolvedValueOnce(null as never);
gitfs.readLocalFile.mockResolvedValueOnce(null);
const execSnapshots = mockExecAll(exec);
platform.getRepoStatus.mockResolvedValueOnce({
modified: ['Gemfile.lock'],
} as Git.StatusResult);
fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts({
packageFileName: 'Gemfile',
Expand All @@ -123,9 +123,9 @@ describe('bundler.updateArtifacts()', () => {
await setUtilConfig({ ...config, binarySource: BinarySource.Docker });
});
it('.ruby-version', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
fs.writeLocalFile.mockResolvedValueOnce(null as never);
fs.readLocalFile.mockResolvedValueOnce('1.2.0');
gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
gitfs.writeLocalFile.mockResolvedValueOnce(null as never);
gitfs.readLocalFile.mockResolvedValueOnce('1.2.0');
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '1.0.0' },
Expand All @@ -137,7 +137,7 @@ describe('bundler.updateArtifacts()', () => {
platform.getRepoStatus.mockResolvedValueOnce({
modified: ['Gemfile.lock'],
} as Git.StatusResult);
fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts({
packageFileName: 'Gemfile',
Expand All @@ -152,8 +152,8 @@ describe('bundler.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot();
});
it('compatibility options', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
fs.writeLocalFile.mockResolvedValueOnce(null as never);
gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
gitfs.writeLocalFile.mockResolvedValueOnce(null as never);
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '1.0.0' },
Expand All @@ -165,7 +165,7 @@ describe('bundler.updateArtifacts()', () => {
platform.getRepoStatus.mockResolvedValueOnce({
modified: ['Gemfile.lock'],
} as Git.StatusResult);
fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts({
packageFileName: 'Gemfile',
Expand All @@ -185,8 +185,8 @@ describe('bundler.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot();
});
it('invalid compatibility options', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
fs.writeLocalFile.mockResolvedValueOnce(null as never);
gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
gitfs.writeLocalFile.mockResolvedValueOnce(null as never);
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '1.0.0' },
Expand All @@ -198,7 +198,7 @@ describe('bundler.updateArtifacts()', () => {
platform.getRepoStatus.mockResolvedValueOnce({
modified: ['Gemfile.lock'],
} as Git.StatusResult);
fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts({
packageFileName: 'Gemfile',
Expand All @@ -219,9 +219,9 @@ describe('bundler.updateArtifacts()', () => {
});

it('injects bundler host configuration environment variables', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
fs.writeLocalFile.mockResolvedValueOnce(null as never);
fs.readLocalFile.mockResolvedValueOnce('1.2.0');
gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
gitfs.writeLocalFile.mockResolvedValueOnce(null as never);
gitfs.readLocalFile.mockResolvedValueOnce('1.2.0');
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '1.0.0' },
Expand All @@ -245,7 +245,7 @@ describe('bundler.updateArtifacts()', () => {
platform.getRepoStatus.mockResolvedValueOnce({
modified: ['Gemfile.lock'],
} as Git.StatusResult);
fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts({
packageFileName: 'Gemfile',
Expand All @@ -264,8 +264,8 @@ describe('bundler.updateArtifacts()', () => {
const execError = new Error();
(execError as any).stdout = ' foo was resolved to';
(execError as any).stderr = '';
fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
fs.writeLocalFile.mockResolvedValueOnce(null as never);
gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
gitfs.writeLocalFile.mockResolvedValueOnce(null as never);
const execSnapshots = mockExecAll(exec, execError);
platform.getRepoStatus.mockResolvedValueOnce({
modified: ['Gemfile.lock'],
Expand All @@ -284,13 +284,13 @@ describe('bundler.updateArtifacts()', () => {
expect(execSnapshots).toMatchSnapshot();
});
it('performs lockFileMaintenance', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
fs.writeLocalFile.mockResolvedValueOnce(null as never);
gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
gitfs.writeLocalFile.mockResolvedValueOnce(null as never);
const execSnapshots = mockExecAll(exec);
platform.getRepoStatus.mockResolvedValueOnce({
modified: ['Gemfile.lock'],
} as Git.StatusResult);
fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts({
packageFileName: 'Gemfile',
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/bundler/artifacts.ts
Expand Up @@ -10,7 +10,7 @@ import {
getSiblingFileName,
readLocalFile,
writeLocalFile,
} from '../../util/fs';
} from '../../util/gitfs';
import { isValid } from '../../versioning/ruby';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';
import {
Expand Down
18 changes: 9 additions & 9 deletions lib/manager/bundler/extract.spec.ts
@@ -1,11 +1,11 @@
import { readFileSync } from 'fs';
import * as _fs from '../../util/fs';
import * as _gitfs from '../../util/gitfs';
import { isValid } from '../../versioning/ruby';
import { extractPackageFile } from './extract';

jest.mock('../../util/fs');
jest.mock('../../util/gitfs');

const fs: any = _fs;
const gitfs: any = _gitfs;

const railsGemfile = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.rails',
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('lib/manager/bundler/extract', () => {
expect(await extractPackageFile('nothing here', 'Gemfile')).toBeNull();
});
it('parses rails Gemfile', async () => {
fs.readLocalFile.mockReturnValueOnce(railsGemfileLock);
gitfs.readLocalFile.mockReturnValueOnce(railsGemfileLock);
const res = await extractPackageFile(railsGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
// couple of dependency of ruby rails are not present in the lock file. Filter out those before processing
Expand All @@ -98,7 +98,7 @@ describe('lib/manager/bundler/extract', () => {
validateGems(sourceGroupGemfile, res);
});
it('parse webpacker Gemfile', async () => {
fs.readLocalFile.mockReturnValueOnce(webPackerGemfileLock);
gitfs.readLocalFile.mockReturnValueOnce(webPackerGemfileLock);
const res = await extractPackageFile(webPackerGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(
Expand All @@ -112,7 +112,7 @@ describe('lib/manager/bundler/extract', () => {
validateGems(webPackerGemfile, res);
});
it('parse mastodon Gemfile', async () => {
fs.readLocalFile.mockReturnValueOnce(mastodonGemfileLock);
gitfs.readLocalFile.mockReturnValueOnce(mastodonGemfileLock);
const res = await extractPackageFile(mastodonGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(
Expand All @@ -130,7 +130,7 @@ describe('lib/manager/bundler/extract', () => {
validateGems(mastodonGemfile, res);
});
it('parse Ruby CI Gemfile', async () => {
fs.readLocalFile.mockReturnValueOnce(rubyCIGemfileLock);
gitfs.readLocalFile.mockReturnValueOnce(rubyCIGemfileLock);
const res = await extractPackageFile(rubyCIGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(
Expand All @@ -145,7 +145,7 @@ describe('lib/manager/bundler/extract', () => {
});
});
it('parse Gitlab Foss Gemfile', async () => {
fs.readLocalFile.mockReturnValueOnce(gitlabFossGemfileLock);
gitfs.readLocalFile.mockReturnValueOnce(gitlabFossGemfileLock);
const res = await extractPackageFile(gitlabFossGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(
Expand All @@ -160,7 +160,7 @@ describe('lib/manager/bundler/extract', () => {
});

it('parse source blocks with spaces in Gemfile', async () => {
fs.readLocalFile.mockReturnValueOnce(sourceBlockWithNewLinesGemfileLock);
gitfs.readLocalFile.mockReturnValueOnce(sourceBlockWithNewLinesGemfileLock);
const res = await extractPackageFile(
sourceBlockWithNewLinesGemfile,
'Gemfile'
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/bundler/extract.ts
@@ -1,7 +1,7 @@
import * as datasourceRubygems from '../../datasource/rubygems';
import { logger } from '../../logger';
import { SkipReason } from '../../types';
import { readLocalFile } from '../../util/fs';
import { readLocalFile } from '../../util/gitfs';
import { regEx } from '../../util/regex';
import { PackageDependency, PackageFile } from '../common';
import { extractLockFileEntries } from './locked-version';
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/bundler/utils.ts
@@ -1,6 +1,6 @@
import { join } from 'upath';
import { logger } from '../../logger';
import { ensureDir } from '../../util/fs';
import { ensureDir } from '../../util/gitfs';
import { UpdateArtifactsConfig } from '../common';

export async function getGemHome(
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/cargo/artifacts.ts
Expand Up @@ -5,7 +5,7 @@ import {
getSiblingFileName,
readLocalFile,
writeLocalFile,
} from '../../util/fs';
} from '../../util/gitfs';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';

export async function updateArtifacts({
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/cocoapods/artifacts.ts
Expand Up @@ -7,7 +7,7 @@ import {
getSiblingFileName,
readLocalFile,
writeLocalFile,
} from '../../util/fs';
} from '../../util/gitfs';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';
import { getCocoaPodsHome } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion lib/manager/cocoapods/utils.ts
@@ -1,6 +1,6 @@
import { join } from 'upath';
import { logger } from '../../logger';
import { ensureDir } from '../../util/fs';
import { ensureDir } from '../../util/gitfs';
import { UpdateArtifactsConfig } from '../common';

export async function getCocoaPodsHome(
Expand Down