test: fix http mocks (#11191)

This commit is contained in:
Michael Kriese
2021-08-09 19:37:28 +02:00
committed by GitHub
parent c6cb110953
commit 394f0bb741
15 changed files with 95 additions and 1 deletions
+5
View File
@@ -233,6 +233,11 @@ describe(getName(), () => {
const pom = loadFixture('pom.scm-prefix.xml', upath.join('..', 'maven'));
mockGenericPackage({ pom });
httpMock
.scope('https://repo.maven.apache.org')
.get('/maven2/org/example/package/maven-metadata.xml')
.reply(200, '###');
const { sourceUrl } = await get();
expect(sourceUrl).toEqual('https://github.com/example/test');
+2
View File
@@ -97,6 +97,8 @@ describe(getName(), () => {
});
it('returns null for missing registry url', async () => {
// FIXME: should not call default registry?
httpMock.scope(baseUrl).get('/no/n_/non_existent_crate').reply(404, {});
expect(
await getPkgReleases({
datasource,
+5
View File
@@ -22,6 +22,11 @@ describe(getName(), () => {
).toBeNull();
});
it('returns null if repository was not provided', async () => {
// FIXME: should it call default rtegisty?
httpMock
.scope('https://charts.helm.sh')
.get('/stable/index.yaml')
.reply(404);
expect(
await getPkgReleases({
datasource: HelmDatasource.id,
+5
View File
@@ -33,6 +33,10 @@ describe(getName(), () => {
});
it('supports custom registries', async () => {
httpMock
.scope('https://composer.renovatebot.com')
.get('/packages.json')
.reply(404);
config = {
registryUrls: ['https://composer.renovatebot.com'],
};
@@ -44,6 +48,7 @@ describe(getName(), () => {
});
expect(res).toBeNull();
});
it('supports plain packages', async () => {
const packagesOnly = {
packages: {
+10
View File
@@ -22,6 +22,11 @@ describe(getName(), () => {
});
it('returns null for invalid inputs', async () => {
// FIXME: why get request?
httpMock
.scope(cocoapodsHost)
.get('/all_pods_versions_3_8_5.txt')
.reply(404);
expect(
await getPkgReleases({
datasource: pod.id,
@@ -31,6 +36,11 @@ describe(getName(), () => {
).toBeNull();
});
it('returns null for empty result', async () => {
// FIXME: why get request?
httpMock
.scope(cocoapodsHost)
.get('/all_pods_versions_a_c_b.txt')
.reply(404);
expect(await getPkgReleases(config)).toBeNull();
});
it('returns null for 404', async () => {
+4
View File
@@ -167,6 +167,10 @@ describe(getName(), () => {
.reply(200, railsInfo)
.get('/api/v1/versions/rails.json')
.reply(500, {});
httpMock
.scope('https://firstparty.com/basepath')
.get('/api/v1/gems/rails.json')
.reply(500);
expect(await getPkgReleases(params)).toBeNull();
});
});
+6
View File
@@ -193,6 +193,12 @@ describe(getName(), () => {
currentValue: '0.6.0',
newValue: '0.8.0',
};
httpMock
.scope('https://github.com')
.get('/bazelbuild/bazel-skyfoo/archive/0.8.0.tar.gz')
.reply(500);
const res = await updateDependency({
fileContent: content,
upgrade,
+9
View File
@@ -100,6 +100,7 @@ describe(getName(), () => {
);
});
it('should init', async () => {
httpMock.scope(baseUrl).get('/2.0/user').reply(200);
expect(
await bitbucket.initPlatform({
username: 'abc',
@@ -611,6 +612,10 @@ describe(getName(), () => {
describe('ensureComment()', () => {
it('does not throw', async () => {
httpMock
.scope(baseUrl)
.get('/2.0/repositories/undefined/pullrequests/3/comments?pagelen=100')
.reply(500);
expect(
await bitbucket.ensureComment({
number: 3,
@@ -623,6 +628,10 @@ describe(getName(), () => {
describe('ensureCommentRemoval()', () => {
it('does not throw', async () => {
httpMock
.scope(baseUrl)
.get('/2.0/repositories/undefined/pullrequests/3/comments?pagelen=100')
.reply(500);
expect(
await bitbucket.ensureCommentRemoval({ number: 3, topic: 'topic' })
).toMatchSnapshot();
+3 -1
View File
@@ -1028,7 +1028,9 @@ describe(getName(), () => {
.get('/api/v4/users?username=someuser')
.reply(200, [{ id: 1 }])
.get('/api/v4/users?username=someotheruser')
.reply(200, [{ id: 2 }]);
.reply(200, [{ id: 2 }])
.put('/api/v4/projects/undefined/merge_requests/42')
.reply(200);
await gitlab.addReviewers(42, ['someuser', 'foo', 'someotheruser']);
expect(scope.isDone()).toBeTrue();
+8
View File
@@ -162,6 +162,14 @@ describe(getName(), () => {
'minor'
)
).toBe('neutral');
// FIXME: no cache hit
httpMock
.scope('https://badges.renovateapi.com')
.get(
`/packages/${datasource}/${depName}-new/${newVersion}/confidence.api/${currentVersion}`
)
.reply(403);
// memory cache
expect(
await getMergeConfidenceLevel(
+21
View File
@@ -1,3 +1,4 @@
import * as httpMock from '../../../../test/http-mock';
import { getName } from '../../../../test/util';
import { PLATFORM_TYPE_GITHUB } from '../../../constants/platforms';
import * as hostRules from '../../../util/host-rules';
@@ -30,6 +31,11 @@ const upgrade: BranchUpgradeConfig = {
};
describe(getName(), () => {
afterEach(() => {
// FIXME: add missing http mocks
httpMock.clear(false);
});
describe('getChangeLogJSON', () => {
beforeEach(() => {
hostRules.clear();
@@ -39,6 +45,7 @@ describe(getName(), () => {
token: 'abc',
});
});
it('returns null if @types', async () => {
expect(
await getChangeLogJSON({
@@ -47,6 +54,7 @@ describe(getName(), () => {
})
).toBeNull();
});
it('returns null if no currentVersion', async () => {
expect(
await getChangeLogJSON({
@@ -55,6 +63,7 @@ describe(getName(), () => {
})
).toBeNull();
});
it('returns null if currentVersion equals newVersion', async () => {
expect(
await getChangeLogJSON({
@@ -64,6 +73,7 @@ describe(getName(), () => {
})
).toBeNull();
});
it('skips invalid repos', async () => {
expect(
await getChangeLogJSON({
@@ -72,6 +82,7 @@ describe(getName(), () => {
})
).toBeNull();
});
it('works without Github', async () => {
// FIXME: explicit assert condition
expect(
@@ -80,6 +91,7 @@ describe(getName(), () => {
})
).toMatchSnapshot();
});
it('uses GitHub tags', async () => {
// FIXME: explicit assert condition
expect(
@@ -88,6 +100,7 @@ describe(getName(), () => {
})
).toMatchSnapshot();
});
it('filters unnecessary warns', async () => {
// FIXME: explicit assert condition
expect(
@@ -97,6 +110,7 @@ describe(getName(), () => {
})
).toMatchSnapshot();
});
it('supports node engines', async () => {
// FIXME: explicit assert condition
expect(
@@ -106,6 +120,7 @@ describe(getName(), () => {
})
).toMatchSnapshot();
});
it('handles no sourceUrl', async () => {
expect(
await getChangeLogJSON({
@@ -114,6 +129,7 @@ describe(getName(), () => {
})
).toBeNull();
});
it('handles invalid sourceUrl', async () => {
expect(
await getChangeLogJSON({
@@ -122,6 +138,7 @@ describe(getName(), () => {
})
).toBeNull();
});
it('handles missing Github token', async () => {
expect(
await getChangeLogJSON({
@@ -130,6 +147,7 @@ describe(getName(), () => {
})
).toEqual({ error: ChangeLogError.MissingGithubToken });
});
it('handles no releases', async () => {
expect(
await getChangeLogJSON({
@@ -138,6 +156,7 @@ describe(getName(), () => {
})
).toBeNull();
});
it('handles not enough releases', async () => {
expect(
await getChangeLogJSON({
@@ -146,6 +165,7 @@ describe(getName(), () => {
})
).toBeNull();
});
it('supports github enterprise and github.com changelog', async () => {
hostRules.add({
hostType: PLATFORM_TYPE_GITHUB,
@@ -160,6 +180,7 @@ describe(getName(), () => {
})
).toMatchSnapshot();
});
it('supports github enterprise and github enterprise changelog', async () => {
hostRules.add({
hostType: PLATFORM_TYPE_GITHUB,
+5
View File
@@ -32,6 +32,11 @@ const upgrade: BranchUpgradeConfig = {
const matchHost = 'https://gitlab.com/';
describe(getName(), () => {
afterEach(() => {
// FIXME: add missing http mocks
httpMock.clear(false);
});
describe('getChangeLogJSON', () => {
beforeEach(() => {
hostRules.clear();
+2
View File
@@ -147,6 +147,8 @@ describe(getName(), () => {
depType: 'engines',
})
).toMatchSnapshot();
// FIXME: missing mocks
httpMock.clear(false);
});
it('handles no sourceUrl', async () => {
expect(
@@ -228,6 +228,11 @@ describe(getName(), () => {
it.each([[''], ['v'], ['other-']])(
'gets null from repository without gitlab/github in domain %s',
async (prefix) => {
// FIXME: Should not call `api.lol.lol` ?
httpMock
.scope('https://api.lol.lol')
.get('/repos/some/other-repository/releases?per_page=100')
.reply(404);
const res = await getReleaseNotes(
'some/other-repository',
'1.0.1',
@@ -241,6 +246,7 @@ describe(getName(), () => {
});
describe('getReleaseNotesMd()', () => {
it('handles not found', async () => {
httpMock.scope('https://api.github.com').get('/repos/chalk').reply(404);
const res = await getReleaseNotesMd(
'chalk',
'2.0.0',
+4
View File
@@ -46,11 +46,15 @@ export function clear(throwOnPending = true): void {
const pending = nock.pendingMocks();
nock.abortPendingRequests();
nock.cleanAll();
const missing = missingLog;
requestLog = [];
missingLog = [];
if (!isDone && throwOnPending) {
throw new Error(`Pending mocks!\n * ${pending.join('\n * ')}`);
}
if (missing.length && throwOnPending) {
throw new Error(`Missing mocks!\n * ${missing.join('\n * ')}`);
}
}
export function scope(basePath: BasePath, options?: nock.Options): nock.Scope {