Skip to content

Commit

Permalink
test: deprecate old loads fixtures functions (#15539)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed May 11, 2022
1 parent 9fa7355 commit 4738542
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 97 deletions.
4 changes: 1 addition & 3 deletions lib/modules/datasource/maven/s3.spec.ts
Expand Up @@ -25,9 +25,7 @@ function get(
return getPkgReleases(registryUrls ? { ...conf, registryUrls } : conf);
}

const meta = Readable.from(
Buffer.from(Fixtures.get('metadata-s3.xml'), 'utf-8')
);
const meta = Readable.from(Fixtures.getBinary('metadata-s3.xml'));

describe('modules/datasource/maven/s3', () => {
const s3mock = mockClient(S3Client);
Expand Down
38 changes: 19 additions & 19 deletions lib/modules/datasource/nuget/index.spec.ts
Expand Up @@ -169,7 +169,7 @@ describe('modules/datasource/nuget/index', () => {
httpMock
.scope('https://api.nuget.org')
.get('/v3/index.json')
.reply(200, JSON.parse(nugetIndexV3))
.reply(200, nugetIndexV3)
.get('/v3/registration5-gz-semver2/nunit/index.json')
.reply(500);

Expand All @@ -184,7 +184,7 @@ describe('modules/datasource/nuget/index', () => {
httpMock
.scope('https://api.nuget.org')
.get('/v3/index.json')
.reply(200, JSON.parse(nugetIndexV3))
.reply(200, nugetIndexV3)
.get('/v3/registration5-gz-semver2/nunit/index.json')
.reply(200, {});

Expand All @@ -205,7 +205,7 @@ describe('modules/datasource/nuget/index', () => {
.get(
'/api/v2/FindPackagesById()?id=%27nunit%27&$select=Version,IsLatestVersion,ProjectUrl,Published'
)
.reply(200, null);
.reply(200);
expect(
await getPkgReleases({
...configV3V2,
Expand Down Expand Up @@ -299,7 +299,7 @@ describe('modules/datasource/nuget/index', () => {
.scope('https://api.nuget.org')
.get('/v3/index.json')
.twice()
.reply(200, JSON.parse(nugetIndexV3))
.reply(200, nugetIndexV3)
.get('/v3-flatcontainer/nunit/3.12.0/nunit.nuspec')
.twice()
.reply(200, pkgInfoV3FromNuget)
Expand All @@ -310,14 +310,14 @@ describe('modules/datasource/nuget/index', () => {
.scope('https://myprivatefeed')
.get('/index.json')
.twice()
.reply(200, JSON.parse(nugetIndexV3));
.reply(200, nugetIndexV3);

const res = await getPkgReleases({
...configV3Multiple,
});
expect(res).not.toBeNull();
expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(45);
expect(res?.releases).toHaveLength(45);
});

it('returns null for unknown error in getReleasesFromV3Feed (v3)', async () => {
Expand All @@ -336,7 +336,7 @@ describe('modules/datasource/nuget/index', () => {
httpMock
.scope('https://api.nuget.org')
.get('/v3/index.json')
.reply(200, JSON.parse(nugetIndexV3))
.reply(200, nugetIndexV3)
.get('/v3/registration5-gz-semver2/nunit/index.json')
.replyWithError('');
expect(
Expand Down Expand Up @@ -365,7 +365,7 @@ describe('modules/datasource/nuget/index', () => {
.scope('https://api.nuget.org')
.get('/v3/index.json')
.twice()
.reply(200, JSON.parse(nugetIndexV3))
.reply(200, nugetIndexV3)
.get('/v3/registration5-gz-semver2/nunit/index.json')
.reply(200, pkgListV3Registration)
.get('/v3-flatcontainer/nunit/3.12.0/nunit.nuspec')
Expand All @@ -375,15 +375,15 @@ describe('modules/datasource/nuget/index', () => {
});
expect(res).not.toBeNull();
expect(res).toMatchSnapshot();
expect(res.sourceUrl).toBeDefined();
expect(res?.sourceUrl).toBeDefined();
});

it('processes real data (v3) for several catalog pages', async () => {
const scope = httpMock
.scope('https://api.nuget.org')
.get('/v3/index.json')
.twice()
.reply(200, JSON.parse(nugetIndexV3));
.reply(200, nugetIndexV3);
nlogMocks.forEach(({ url, result }) => {
scope.get(url).reply(200, result);
});
Expand All @@ -393,7 +393,7 @@ describe('modules/datasource/nuget/index', () => {
});
expect(res).not.toBeNull();
expect(res).toMatchSnapshot();
expect(res.sourceUrl).toBeDefined();
expect(res?.sourceUrl).toBeDefined();
});

it('processes real data (v3) feed is not a nuget.org', async () => {
Expand All @@ -415,22 +415,22 @@ describe('modules/datasource/nuget/index', () => {
.scope('https://myprivatefeed')
.get('/index.json')
.twice()
.reply(200, JSON.parse(nugetIndexV3));
.reply(200, nugetIndexV3);

const res = await getPkgReleases({
...configV3NotNugetOrg,
});
expect(res).not.toBeNull();
expect(res).toMatchSnapshot();
expect(res.sourceUrl).toBeDefined();
expect(res?.sourceUrl).toBeDefined();
});

it('processes real data (v3) nuspec fetch error', async () => {
httpMock
.scope('https://api.nuget.org')
.get('/v3/index.json')
.twice()
.reply(200, JSON.parse(nugetIndexV3))
.reply(200, nugetIndexV3)
.get('/v3/registration5-gz-semver2/nunit/index.json')
.reply(200, pkgListV3Registration)
.get('/v3-flatcontainer/nunit/3.12.0/nunit.nuspec')
Expand All @@ -440,15 +440,15 @@ describe('modules/datasource/nuget/index', () => {
});
expect(res).not.toBeNull();
expect(res).toMatchSnapshot();
expect(res.sourceUrl).toBeUndefined();
expect(res?.sourceUrl).toBeUndefined();
});

it('processes real data (v3) nuspec fetch 404 error', async () => {
httpMock
.scope('https://api.nuget.org')
.get('/v3/index.json')
.twice()
.reply(200, JSON.parse(nugetIndexV3))
.reply(200, nugetIndexV3)
.get('/v3/registration5-gz-semver2/nunit/index.json')
.reply(200, pkgListV3Registration)
.get('/v3-flatcontainer/nunit/3.12.0/nunit.nuspec')
Expand All @@ -458,7 +458,7 @@ describe('modules/datasource/nuget/index', () => {
});
expect(res).not.toBeNull();
expect(res).toMatchSnapshot();
expect(res.sourceUrl).toBeUndefined();
expect(res?.sourceUrl).toBeUndefined();
});

it('processes real data (v2)', async () => {
Expand All @@ -473,7 +473,7 @@ describe('modules/datasource/nuget/index', () => {
});
expect(res).not.toBeNull();
expect(res).toMatchSnapshot();
expect(res.sourceUrl).toBeDefined();
expect(res?.sourceUrl).toBeDefined();
});

it('processes real data no relase (v2)', async () => {
Expand Down Expand Up @@ -501,7 +501,7 @@ describe('modules/datasource/nuget/index', () => {
});
expect(res).not.toBeNull();
expect(res).toMatchSnapshot();
expect(res.sourceUrl).toBeUndefined();
expect(res?.sourceUrl).toBeUndefined();
});

it('processes real data with no github project url (v2)', async () => {
Expand Down
2 changes: 0 additions & 2 deletions lib/modules/datasource/pypi/__snapshots__/index.spec.ts.snap
Expand Up @@ -280,5 +280,3 @@ Object {
],
}
`;

exports[`modules/datasource/pypi/index getReleases returns non-github home_page 1`] = `"https://microsoft.com"`;
55 changes: 26 additions & 29 deletions lib/modules/datasource/pypi/index.spec.ts
@@ -1,20 +1,20 @@
import { getPkgReleases } from '..';
import { Fixtures } from '../../../../test/fixtures';
import * as httpMock from '../../../../test/http-mock';
import { loadFixture } from '../../../../test/util';
import * as hostRules from '../../../util/host-rules';
import { PypiDatasource } from '.';

const res1 = loadFixture('azure-cli-monitor.json');
const res2 = loadFixture('azure-cli-monitor-updated.json');
const htmlResponse = loadFixture('versions-html.html');
const badResponse = loadFixture('versions-html-badfile.html');
const dataRequiresPythonResponse = loadFixture(
const res1 = Fixtures.get('azure-cli-monitor.json');
const res2 = Fixtures.get('azure-cli-monitor-updated.json');
const htmlResponse = Fixtures.get('versions-html.html');
const badResponse = Fixtures.get('versions-html-badfile.html');
const dataRequiresPythonResponse = Fixtures.get(
'versions-html-data-requires-python.html'
);
const mixedHyphensResponse = loadFixture('versions-html-mixed-hyphens.html');
const mixedCaseResponse = loadFixture('versions-html-mixed-case.html');
const withPeriodsResponse = loadFixture('versions-html-with-periods.html');
const hyphensResponse = loadFixture('versions-html-hyphens.html');
const mixedHyphensResponse = Fixtures.get('versions-html-mixed-hyphens.html');
const mixedCaseResponse = Fixtures.get('versions-html-mixed-case.html');
const withPeriodsResponse = Fixtures.get('versions-html-with-periods.html');
const hyphensResponse = Fixtures.get('versions-html-hyphens.html');

const baseUrl = 'https://pypi.org/pypi';
const datasource = PypiDatasource.id;
Expand Down Expand Up @@ -55,10 +55,7 @@ describe('modules/datasource/pypi/index', () => {
});

it('processes real data', async () => {
httpMock
.scope(baseUrl)
.get('/azure-cli-monitor/json')
.reply(200, JSON.parse(res1));
httpMock.scope(baseUrl).get('/azure-cli-monitor/json').reply(200, res1);
expect(
await getPkgReleases({
datasource,
Expand All @@ -71,7 +68,7 @@ describe('modules/datasource/pypi/index', () => {
httpMock
.scope('https://custom.pypi.net/foo')
.get('/azure-cli-monitor/json')
.reply(200, JSON.parse(res1));
.reply(200, res1);
const config = {
registryUrls: ['https://custom.pypi.net/foo'],
};
Expand All @@ -93,7 +90,7 @@ describe('modules/datasource/pypi/index', () => {
httpMock
.scope('https://customprivate.pypi.net/foo')
.get('/azure-cli-monitor/json')
.reply(200, JSON.parse(res1));
.reply(200, res1);
const config = {
registryUrls: ['https://customprivate.pypi.net/foo'],
};
Expand All @@ -102,7 +99,7 @@ describe('modules/datasource/pypi/index', () => {
datasource,
depName: 'azure-cli-monitor',
});
expect(res.isPrivate).toBeTrue();
expect(res?.isPrivate).toBeTrue();
});

it('supports multiple custom datasource urls', async () => {
Expand All @@ -113,11 +110,11 @@ describe('modules/datasource/pypi/index', () => {
httpMock
.scope('https://second-index/foo')
.get('/azure-cli-monitor/json')
.reply(200, JSON.parse(res1));
.reply(200, res1);
httpMock
.scope('https://third-index/foo')
.get('/azure-cli-monitor/json')
.reply(200, JSON.parse(res2));
.reply(200, res2);
const config = {
registryUrls: [
'https://custom.pypi.net/foo',
Expand All @@ -130,7 +127,7 @@ describe('modules/datasource/pypi/index', () => {
datasource,
depName: 'azure-cli-monitor',
});
expect(res.releases.pop()).toMatchObject({
expect(res?.releases.pop()).toMatchObject({
version: '0.2.15',
releaseTimestamp: '2019-06-18T13:58:55.000Z',
});
Expand All @@ -153,8 +150,8 @@ describe('modules/datasource/pypi/index', () => {
datasource,
depName: 'something',
})
).homepage
).toMatchSnapshot();
)?.homepage
).toBe('https://microsoft.com');
});

it('find url from project_urls', async () => {
Expand All @@ -177,8 +174,8 @@ describe('modules/datasource/pypi/index', () => {
datasource,
depName: 'flexget',
});
expect(result.sourceUrl).toBe(info.project_urls.Repository);
expect(result.changelogUrl).toBe(info.project_urls.changelog);
expect(result?.sourceUrl).toBe(info.project_urls.Repository);
expect(result?.changelogUrl).toBe(info.project_urls.changelog);
});

it('normalizes the package name according to PEP 503', async () => {
Expand Down Expand Up @@ -313,7 +310,7 @@ describe('modules/datasource/pypi/index', () => {
constraints: { python: '2.7' },
depName: 'dj-database-url',
});
expect(res.isPrivate).toBeTrue();
expect(res?.isPrivate).toBeTrue();
});

it('process data from simple endpoint with hyphens', async () => {
Expand All @@ -329,7 +326,7 @@ describe('modules/datasource/pypi/index', () => {
...config,
depName: 'package--with-hyphens',
});
expect(res.releases).toMatchObject([
expect(res?.releases).toMatchObject([
{ version: '2.0.0' },
{ version: '2.0.1' },
{ version: '2.0.2' },
Expand Down Expand Up @@ -367,7 +364,7 @@ describe('modules/datasource/pypi/index', () => {
...config,
depName: 'PackageWithMixedCase',
});
expect(res.releases).toMatchObject([
expect(res?.releases).toMatchObject([
{ version: '2.0.0' },
{ version: '2.0.1' },
{ version: '2.0.2' },
Expand All @@ -387,7 +384,7 @@ describe('modules/datasource/pypi/index', () => {
...config,
depName: 'packagewithmixedcase',
});
expect(res.releases).toMatchObject([
expect(res?.releases).toMatchObject([
{ version: '2.0.0' },
{ version: '2.0.1' },
{ version: '2.0.2' },
Expand All @@ -407,7 +404,7 @@ describe('modules/datasource/pypi/index', () => {
...config,
depName: 'package.with.periods',
});
expect(res.releases).toMatchObject([
expect(res?.releases).toMatchObject([
{ version: '2.0.0' },
{ version: '2.0.1' },
{ version: '2.0.2' },
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/datasource/terraform-provider/index.spec.ts
Expand Up @@ -68,7 +68,7 @@ describe('modules/datasource/terraform-provider/index', () => {
httpMock
.scope(primaryUrl)
.get('/v1/providers/hashicorp/azurerm')
.reply(200, JSON.parse(consulData))
.reply(200, consulData)
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
const res = await getPkgReleases({
Expand All @@ -83,7 +83,7 @@ describe('modules/datasource/terraform-provider/index', () => {
httpMock
.scope('https://registry.company.com')
.get('/v1/providers/hashicorp/azurerm')
.reply(200, JSON.parse(consulData))
.reply(200, consulData)
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
const res = await getPkgReleases({
Expand All @@ -108,7 +108,7 @@ describe('modules/datasource/terraform-provider/index', () => {
httpMock
.scope(secondaryUrl)
.get('/index.json')
.reply(200, JSON.parse(hashicorpReleases));
.reply(200, hashicorpReleases);

const res = await getPkgReleases({
datasource: TerraformProviderDatasource.id,
Expand Down

0 comments on commit 4738542

Please sign in to comment.