Skip to content

Commit

Permalink
fix(cache): global cache init (#6314)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed May 24, 2020
1 parent 996399f commit 0aae466
Show file tree
Hide file tree
Showing 31 changed files with 42 additions and 89 deletions.
2 changes: 0 additions & 2 deletions lib/config/presets/github/index.spec.ts
@@ -1,7 +1,6 @@
import { mocked } from '../../../../test/util';
import { PLATFORM_FAILURE } from '../../../constants/error-messages';
import { GotResponse } from '../../../platform';
import * as globalCache from '../../../util/cache/global';
import _got from '../../../util/got';
import * as _hostRules from '../../../util/host-rules';
import * as github from '.';
Expand All @@ -16,7 +15,6 @@ const hostRules = mocked(_hostRules);
describe('config/presets/github', () => {
beforeEach(() => {
got.mockReset();
return globalCache.rmAll();
});
describe('fetchJSONFile()', () => {
it('returns JSON', async () => {
Expand Down
2 changes: 0 additions & 2 deletions lib/config/presets/gitlab/index.spec.ts
@@ -1,5 +1,4 @@
import * as httpMock from '../../../../test/httpMock';
import * as globalCache from '../../../util/cache/global';
import * as gitlab from '.';

const gitlabApiHost = 'https://gitlab.com';
Expand All @@ -8,7 +7,6 @@ describe('config/presets/gitlab', () => {
beforeEach(() => {
httpMock.reset();
httpMock.setup();
return globalCache.rmAll();
});
describe('getPreset()', () => {
it('throws if non-default', async () => {
Expand Down
2 changes: 0 additions & 2 deletions lib/config/presets/local/index.spec.ts
@@ -1,4 +1,3 @@
import * as globalCache from '../../../util/cache/global';
import * as github from '../github';
import * as gitlab from '../gitlab';
import * as local from '.';
Expand All @@ -19,7 +18,6 @@ describe('config/presets/local', () => {
gitlabGetPreset.mockResolvedValueOnce({ resolved: 'preset' });
githubGetPreset.mockReset();
githubGetPreset.mockResolvedValueOnce({ resolved: 'preset' });
return globalCache.rmAll();
});
describe('getPreset()', () => {
it('throws for unsupported platform', async () => {
Expand Down
2 changes: 0 additions & 2 deletions lib/config/presets/npm/index.spec.ts
@@ -1,5 +1,4 @@
import nock from 'nock';
import * as globalCache from '../../../util/cache/global';
import * as npm from '.';

jest.mock('registry-auth-token');
Expand All @@ -11,7 +10,6 @@ describe('config/presets/npm', () => {
jest.resetAllMocks();
global.trustLevel = 'low';
nock.cleanAll();
return globalCache.rmAll();
});
afterEach(() => {
delete process.env.RENOVATE_CACHE_NPM_MINUTES;
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/cdnjs/index.spec.ts
@@ -1,6 +1,5 @@
import fs from 'fs';
import { DATASOURCE_FAILURE } from '../../constants/error-messages';
import * as globalCache from '../../util/cache/global';
import _got from '../../util/got';
import { getReleases } from '.';

Expand All @@ -23,7 +22,6 @@ describe('datasource/cdnjs', () => {
describe('getReleases', () => {
beforeEach(() => {
jest.clearAllMocks();
return globalCache.rmAll();
});
it('throws for empty result', async () => {
got.mockResolvedValueOnce(null);
Expand Down
3 changes: 0 additions & 3 deletions lib/datasource/docker/index.spec.ts
Expand Up @@ -2,7 +2,6 @@ import AWS from 'aws-sdk';
import AWSMock from 'aws-sdk-mock';
import { getPkgReleases } from '..';
import { DATASOURCE_FAILURE } from '../../constants/error-messages';
import * as globalCache from '../../util/cache/global';
import _got from '../../util/got';
import * as _hostRules from '../../util/host-rules';
import * as docker from '.';
Expand Down Expand Up @@ -35,7 +34,6 @@ describe('api/docker', () => {
password: 'some-password',
});
hostRules.hosts = jest.fn(() => []);
return globalCache.rmAll();
});
it('returns null if no token', async () => {
got.mockReturnValueOnce({ body: {} });
Expand Down Expand Up @@ -279,7 +277,6 @@ describe('api/docker', () => {
describe('getReleases', () => {
beforeEach(() => {
jest.clearAllMocks();
return globalCache.rmAll();
});
it('returns null if no token', async () => {
got.mockReturnValueOnce({ body: {} });
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/git-refs/index.spec.ts
@@ -1,6 +1,5 @@
import fs from 'fs-extra';
import _simpleGit from 'simple-git/promise';
import * as globalCache from '../../util/cache/global';
import { getDigest, getReleases } from '.';

jest.mock('simple-git/promise');
Expand All @@ -14,7 +13,6 @@ const lsRemote1 = fs.readFileSync(
);

describe('datasource/git-refs', () => {
beforeEach(() => globalCache.rmAll());
describe('getReleases', () => {
it('returns nil if response is wrong', async () => {
simpleGit.mockReturnValue({
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/git-submodules/index.spec.ts
@@ -1,5 +1,4 @@
import _simpleGit from 'simple-git/promise';
import * as globalCache from '../../util/cache/global';
import { getDigest, getReleases } from '.';

jest.mock('simple-git/promise');
Expand All @@ -9,7 +8,6 @@ const lookupName = 'https://github.com/example/example.git';
const registryUrls = [lookupName, 'master'];

describe('datasource/git-submoduless', () => {
beforeEach(() => globalCache.rmAll());
describe('getReleases', () => {
it('returns null if response is wrong', async () => {
simpleGit.mockReturnValue({
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/git-tags/index.spec.ts
@@ -1,6 +1,5 @@
import fs from 'fs-extra';
import _simpleGit from 'simple-git/promise';
import * as globalCache from '../../util/cache/global';
import { getDigest, getReleases } from '.';

jest.mock('simple-git/promise');
Expand All @@ -14,7 +13,6 @@ const lsRemote1 = fs.readFileSync(
);

describe('datasource/git-tags', () => {
beforeEach(() => globalCache.rmAll());
describe('getReleases', () => {
it('returns nil if response is wrong', async () => {
simpleGit.mockReturnValue({
Expand Down
4 changes: 1 addition & 3 deletions lib/datasource/github-releases/index.spec.ts
@@ -1,5 +1,4 @@
import * as httpMock from '../../../test/httpMock';
import * as globalCache from '../../util/cache/global';
import * as _hostRules from '../../util/host-rules';
import * as github from '.';

Expand All @@ -9,8 +8,7 @@ const hostRules: any = _hostRules;
const githubApiHost = 'https://api.github.com';

describe('datasource/github-releases', () => {
beforeEach(async () => {
await globalCache.rmAll();
beforeEach(() => {
hostRules.hosts = jest.fn(() => []);
hostRules.find.mockReturnValue({
token: 'some-token',
Expand Down
6 changes: 1 addition & 5 deletions lib/datasource/github-tags/index.spec.ts
@@ -1,5 +1,4 @@
import * as httpMock from '../../../test/httpMock';
import * as globalCache from '../../util/cache/global';
import * as _hostRules from '../../util/host-rules';
import * as github from '.';

Expand All @@ -9,9 +8,8 @@ const hostRules: any = _hostRules;
const githubApiHost = 'https://api.github.com';

describe('datasource/github-tags', () => {
beforeEach(async () => {
beforeEach(() => {
httpMock.setup();
await globalCache.rmAll();
});

afterEach(() => {
Expand All @@ -28,7 +26,6 @@ describe('datasource/github-tags', () => {
hostRules.find.mockReturnValue({
token: 'some-token',
});
return globalCache.rmAll();
});

it('returns null if no token', async () => {
Expand Down Expand Up @@ -93,7 +90,6 @@ describe('datasource/github-tags', () => {
describe('getReleases', () => {
const lookupName = 'some/dep2';

beforeAll(() => globalCache.rmAll());
it('returns tags', async () => {
const body = [{ name: 'v1.0.0' }, { name: 'v1.1.0' }];
httpMock
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/gitlab-tags/index.spec.ts
@@ -1,12 +1,10 @@
import * as httpMock from '../../../test/httpMock';
import * as globalCache from '../../util/cache/global';
import * as gitlab from '.';

describe('datasource/gitlab-tags', () => {
beforeEach(() => {
httpMock.reset();
httpMock.setup();
return globalCache.rmAll();
});
describe('getReleases', () => {
it('returns tags', async () => {
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/gradle-version/index.spec.ts
@@ -1,5 +1,4 @@
import fs from 'fs';
import * as globalCache from '../../util/cache/global';
import _got from '../../util/got';
import * as gradleVersion from '.';

Expand All @@ -20,7 +19,6 @@ describe('datasource/gradle-version', () => {
lookupName: 'abc',
};
jest.clearAllMocks();
return globalCache.rmAll();
});

it('processes real data', async () => {
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/helm/index.spec.ts
@@ -1,5 +1,4 @@
import fs from 'fs';
import * as globalCache from '../../util/cache/global';
import _got from '../../util/got';
import { getReleases } from '.';

Expand All @@ -17,7 +16,6 @@ describe('datasource/helm', () => {
describe('getReleases', () => {
beforeEach(() => {
jest.resetAllMocks();
return globalCache.rmAll();
});
it('returns null if lookupName was not provided', async () => {
expect(
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/maven/index.spec.ts
Expand Up @@ -3,7 +3,6 @@ import { resolve } from 'path';
import nock from 'nock';
import { getPkgReleases } from '..';
import { DATASOURCE_FAILURE } from '../../constants/error-messages';
import * as globalCache from '../../util/cache/global';
import * as hostRules from '../../util/host-rules';
import * as mavenVersioning from '../../versioning/maven';
import * as maven from '.';
Expand Down Expand Up @@ -98,7 +97,6 @@ describe('datasource/maven', () => {
.head(path)
.reply(status, '', {});
});
return globalCache.rmAll();
});

afterEach(() => {
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/npm/index.spec.ts
Expand Up @@ -3,7 +3,6 @@ import nock from 'nock';
import _registryAuthToken from 'registry-auth-token';
import { getName } from '../../../test/util';
import { DATASOURCE_FAILURE } from '../../constants/error-messages';
import * as globalCache from '../../util/cache/global';
import * as hostRules from '../../util/host-rules';
import * as npm from '.';

Expand Down Expand Up @@ -54,7 +53,6 @@ describe(getName(__filename), () => {
},
};
nock.cleanAll();
return globalCache.rmAll();
});
afterEach(() => {
delete process.env.RENOVATE_CACHE_NPM_MINUTES;
Expand Down
4 changes: 0 additions & 4 deletions lib/datasource/nuget/index.spec.ts
@@ -1,5 +1,4 @@
import fs from 'fs';
import * as globalCache from '../../util/cache/global';
import _got from '../../util/got';
import * as _hostRules from '../../util/host-rules';
import * as nuget from '.';
Expand Down Expand Up @@ -95,9 +94,6 @@ const configV3Multiple = {
};

describe('datasource/nuget', () => {
beforeEach(() => {
return globalCache.rmAll();
});
describe('getReleases', () => {
beforeEach(() => {
jest.resetAllMocks();
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/orb/index.spec.ts
@@ -1,4 +1,3 @@
import * as globalCache from '../../util/cache/global';
import _got from '../../util/got';
import * as datasource from '.';

Expand Down Expand Up @@ -31,7 +30,6 @@ describe('datasource/orb', () => {
describe('getReleases', () => {
beforeEach(() => {
jest.clearAllMocks();
return globalCache.rmAll();
});
it('returns null for empty result', async () => {
got.mockReturnValueOnce({ body: {} });
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/packagist/index.spec.ts
@@ -1,5 +1,4 @@
import fs from 'fs';
import * as globalCache from '../../util/cache/global';
import _got from '../../util/got';
import * as _hostRules from '../../util/host-rules';
import * as composerVersioning from '../../versioning/composer';
Expand Down Expand Up @@ -35,7 +34,6 @@ describe('datasource/packagist', () => {
'https://packagist.org',
],
};
return globalCache.rmAll();
});
it('supports custom registries', async () => {
config = {
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/pod/index.spec.ts
@@ -1,6 +1,5 @@
import { getPkgReleases } from '..';
import * as httpMock from '../../../test/httpMock';
import * as globalCache from '../../util/cache/global';
import * as rubyVersioning from '../../versioning/ruby';
import * as pod from '.';

Expand All @@ -19,7 +18,6 @@ describe('datasource/cocoapods', () => {
beforeEach(() => {
jest.resetAllMocks();
httpMock.setup();
return globalCache.rmAll();
});

afterEach(() => {
Expand Down
4 changes: 0 additions & 4 deletions lib/datasource/ruby-version/index.spec.ts
@@ -1,5 +1,4 @@
import fs from 'fs';
import * as globalCache from '../../util/cache/global';
import _got from '../../util/got';
import { getReleases } from '.';

Expand All @@ -14,9 +13,6 @@ const rubyReleasesHtml = fs.readFileSync(

describe('datasource/gradle', () => {
describe('getReleases', () => {
beforeEach(() => {
return globalCache.rmAll();
});
it('parses real data', async () => {
got.mockReturnValueOnce({
body: rubyReleasesHtml,
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/terraform-module/index.spec.ts
@@ -1,5 +1,4 @@
import fs from 'fs';
import * as globalCache from '../../util/cache/global';
import _got from '../../util/got';
import * as terraform from '.';

Expand All @@ -15,7 +14,6 @@ describe('datasource/terraform-module', () => {
describe('getReleases', () => {
beforeEach(() => {
jest.clearAllMocks();
return globalCache.rmAll();
});
it('returns null for empty result', async () => {
got.mockReturnValueOnce({ body: {} });
Expand Down
2 changes: 0 additions & 2 deletions lib/datasource/terraform-provider/index.spec.ts
@@ -1,5 +1,4 @@
import fs from 'fs';
import * as globalCache from '../../util/cache/global';
import _got from '../../util/got';
import * as terraformProvider from '.';

Expand All @@ -15,7 +14,6 @@ describe('datasource/terraform', () => {
describe('getReleases', () => {
beforeEach(() => {
jest.clearAllMocks();
return globalCache.rmAll();
});
it('returns null for empty result', async () => {
got.mockReturnValueOnce({ body: {} });
Expand Down
1 change: 0 additions & 1 deletion lib/globals.d.ts
Expand Up @@ -6,7 +6,6 @@ declare namespace Renovate {
interface Cache {
get<T = any>(namespace: string, key: string): Promise<T>;
rm(namespace: string, key: string): Promise<void>;
rmAll(): Promise<void>;

set<T = any>(
namespace: string,
Expand Down

0 comments on commit 0aae466

Please sign in to comment.