0
0
Fork 0
mirror of https://github.com/renovatebot/renovate.git synced 2025-05-18 01:52:07 +00:00
renovatebot_renovate/lib/modules/datasource/pod/index.spec.ts

346 lines
10 KiB
TypeScript
Raw Permalink Normal View History

2020-04-05 08:38:48 +02:00
import { getPkgReleases } from '..';
import { EXTERNAL_HOST_ERROR } from '../../../constants/error-messages';
import * as hostRules from '../../../util/host-rules';
2020-05-01 18:03:48 +02:00
import * as rubyVersioning from '../../versioning/ruby';
import { PodDatasource } from '.';
2025-03-13 18:52:09 +01:00
import * as httpMock from '~test/http-mock';
2020-03-01 13:03:16 +04:00
const config = {
2020-04-05 08:38:48 +02:00
versioning: rubyVersioning.id,
datasource: PodDatasource.id,
packageName: 'foo',
2020-04-05 08:38:48 +02:00
registryUrls: [],
2020-03-01 13:03:16 +04:00
};
const githubApiHost = 'https://api.github.com';
const githubEntApiHost = 'https://github.foo.com';
const githubEntApiHost2 = 'https://ghe.foo.com';
const cocoapodsHost = 'https://cdn.cocoapods.org';
describe('modules/datasource/pod/index', () => {
describe('getReleases', () => {
2020-04-05 08:38:48 +02:00
beforeEach(() => {
hostRules.clear();
});
2020-03-01 13:03:16 +04:00
it('returns null for invalid inputs', async () => {
2021-08-09 19:37:28 +02:00
// FIXME: why get request?
httpMock
.scope(cocoapodsHost)
.get('/all_pods_versions_3_8_5.txt')
.reply(404);
2020-03-01 13:03:16 +04:00
expect(
2020-04-05 08:38:48 +02:00
await getPkgReleases({
datasource: PodDatasource.id,
packageName: 'foobar',
2020-03-01 13:03:16 +04:00
registryUrls: [],
}),
2020-03-01 13:03:16 +04:00
).toBeNull();
});
it('returns null disabled host', async () => {
hostRules.add({ matchHost: cocoapodsHost, enabled: false });
expect(
await getPkgReleases({
datasource: PodDatasource.id,
packageName: 'foobar',
}),
).toBeNull();
});
2020-03-01 13:03:16 +04:00
it('returns null for empty result', async () => {
2021-08-09 19:37:28 +02:00
// FIXME: why get request?
httpMock
.scope(cocoapodsHost)
.get('/all_pods_versions_a_c_b.txt')
.reply(404);
2020-04-05 08:38:48 +02:00
expect(await getPkgReleases(config)).toBeNull();
2020-03-01 13:03:16 +04:00
});
2020-03-01 13:03:16 +04:00
it('returns null for 404', async () => {
httpMock
.scope(githubApiHost)
.get('/repos/foo/bar/contents/Specs/a/c/b/foo')
.reply(404)
.get('/repos/foo/bar/contents/a/c/b/foo')
.reply(404)
.get('/repos/foo/bar/contents/Specs/foo')
.reply(404)
.get('/repos/foo/bar/contents/foo')
.reply(404);
const res = await getPkgReleases({
...config,
registryUrls: [...config.registryUrls, 'https://github.com/foo/bar'],
});
expect(res).toBeNull();
});
it('returns null for 404 Github enterprise', async () => {
httpMock
.scope(githubEntApiHost)
.get('/api/v3/repos/foo/bar/contents/Specs/a/c/b/foo')
.reply(404)
.get('/api/v3/repos/foo/bar/contents/a/c/b/foo')
.reply(404)
.get('/api/v3/repos/foo/bar/contents/Specs/foo')
.reply(404)
.get('/api/v3/repos/foo/bar/contents/foo')
.reply(404);
const res = await getPkgReleases({
...config,
registryUrls: [
...config.registryUrls,
'https://github.foo.com/foo/bar',
],
});
expect(res).toBeNull();
});
it('returns null for 404 Github enterprise with different url style', async () => {
httpMock
.scope(githubEntApiHost2)
.get('/api/v3/repos/foo/bar/contents/Specs/a/c/b/foo')
.reply(404)
.get('/api/v3/repos/foo/bar/contents/a/c/b/foo')
.reply(404)
.get('/api/v3/repos/foo/bar/contents/Specs/foo')
.reply(404)
.get('/api/v3/repos/foo/bar/contents/foo')
.reply(404);
const res = await getPkgReleases({
...config,
registryUrls: [...config.registryUrls, 'https://ghe.foo.com/foo/bar'],
});
expect(res).toBeNull();
2020-03-01 13:03:16 +04:00
});
2020-03-01 13:03:16 +04:00
it('returns null for 401', async () => {
httpMock
.scope(cocoapodsHost)
.get('/all_pods_versions_a_c_b.txt')
.reply(401);
2020-04-05 08:38:48 +02:00
expect(await getPkgReleases(config)).toBeNull();
2020-03-01 13:03:16 +04:00
});
2020-03-01 13:03:16 +04:00
it('throws for 429', async () => {
httpMock
.scope(cocoapodsHost)
.get('/all_pods_versions_a_c_b.txt')
.reply(429);
2020-06-22 21:28:02 +02:00
await expect(getPkgReleases(config)).rejects.toThrow(EXTERNAL_HOST_ERROR);
});
it('throws for 500', async () => {
httpMock
.scope(cocoapodsHost)
.get('/all_pods_versions_a_c_b.txt')
.reply(500);
await expect(getPkgReleases(config)).rejects.toThrow(EXTERNAL_HOST_ERROR);
2020-03-01 13:03:16 +04:00
});
2020-03-01 13:03:16 +04:00
it('returns null for unknown error', async () => {
httpMock
.scope(cocoapodsHost)
.get('/all_pods_versions_a_c_b.txt')
.replyWithError('foobar');
2020-04-05 08:38:48 +02:00
expect(await getPkgReleases(config)).toBeNull();
2020-03-01 13:03:16 +04:00
});
2020-03-01 13:03:16 +04:00
it('processes real data from CDN', async () => {
httpMock
.scope(cocoapodsHost)
.get('/all_pods_versions_a_c_b.txt')
.reply(200, 'foo/1.2.3');
2020-03-01 13:03:16 +04:00
expect(
2020-04-05 08:38:48 +02:00
await getPkgReleases({
2020-03-01 13:03:16 +04:00
...config,
2020-04-05 08:38:48 +02:00
registryUrls: ['https://github.com/CocoaPods/Specs'],
}),
2020-03-01 13:03:16 +04:00
).toEqual({
registryUrl: 'https://github.com/CocoaPods/Specs',
2020-03-01 13:03:16 +04:00
releases: [
{
version: '1.2.3',
},
],
});
});
it('processes real data from Github with shard with specs', async () => {
httpMock
.scope(githubApiHost)
.get('/repos/Artsy/Specs/contents/Specs/a/c/b/foo')
.reply(200, [{ name: '1.2.3' }]);
const res = await getPkgReleases({
...config,
registryUrls: ['https://github.com/Artsy/Specs'],
});
expect(res).toEqual({
registryUrl: 'https://github.com/Artsy/Specs',
releases: [
{
version: '1.2.3',
},
],
});
});
it('processes real data from Github with shard without specs', async () => {
httpMock
.scope(githubApiHost)
.get('/repos/Artsy/Specs/contents/Specs/a/c/b/foo')
.reply(404)
.get('/repos/Artsy/Specs/contents/a/c/b/foo')
.reply(200, [{ name: '1.2.3' }]);
const res = await getPkgReleases({
...config,
registryUrls: ['https://github.com/Artsy/Specs'],
});
expect(res).toEqual({
registryUrl: 'https://github.com/Artsy/Specs',
releases: [
{
version: '1.2.3',
},
],
});
});
it('processes real data from Github with specs without shard', async () => {
httpMock
.scope(githubApiHost)
.get('/repos/Artsy/Specs/contents/Specs/a/c/b/foo')
.reply(404)
.get('/repos/Artsy/Specs/contents/a/c/b/foo')
.reply(404)
.get('/repos/Artsy/Specs/contents/Specs/foo')
.reply(200, [{ name: '1.2.3' }]);
const res = await getPkgReleases({
...config,
registryUrls: ['https://github.com/Artsy/Specs'],
});
expect(res).toEqual({
registryUrl: 'https://github.com/Artsy/Specs',
releases: [
{
version: '1.2.3',
},
],
});
});
it('processes real data from Github without specs without shard', async () => {
httpMock
.scope(githubApiHost)
.get('/repos/Artsy/Specs/contents/Specs/a/c/b/foo')
.reply(404)
.get('/repos/Artsy/Specs/contents/a/c/b/foo')
.reply(404)
.get('/repos/Artsy/Specs/contents/Specs/foo')
.reply(404)
.get('/repos/Artsy/Specs/contents/foo')
.reply(200, [{ name: '1.2.3' }]);
const res = await getPkgReleases({
...config,
registryUrls: ['https://github.com/Artsy/Specs'],
});
expect(res).toEqual({
registryUrl: 'https://github.com/Artsy/Specs',
2020-03-01 13:03:16 +04:00
releases: [
{
version: '1.2.3',
},
],
});
});
it('processes real data from Github Enterprise with shard with specs', async () => {
httpMock
.scope(githubEntApiHost)
.get('/api/v3/repos/foo/bar/contents/Specs/a/c/b/foo')
.reply(200, [{ name: '1.2.3' }]);
const res = await getPkgReleases({
...config,
registryUrls: ['https://github.foo.com/foo/bar'],
});
expect(res).toEqual({
registryUrl: 'https://github.foo.com/foo/bar',
releases: [
{
version: '1.2.3',
},
],
});
});
it('processes real data from Github Enterprise with shard without specs', async () => {
httpMock
.scope(githubEntApiHost)
.get('/api/v3/repos/foo/bar/contents/Specs/a/c/b/foo')
.reply(404)
.get('/api/v3/repos/foo/bar/contents/a/c/b/foo')
.reply(200, [{ name: '1.2.3' }]);
const res = await getPkgReleases({
...config,
registryUrls: ['https://github.foo.com/foo/bar'],
});
expect(res).toEqual({
registryUrl: 'https://github.foo.com/foo/bar',
releases: [
{
version: '1.2.3',
},
],
});
});
it('processes real data from Github Enterprise with specs without shard', async () => {
httpMock
.scope(githubEntApiHost)
.get('/api/v3/repos/foo/bar/contents/Specs/a/c/b/foo')
.reply(404)
.get('/api/v3/repos/foo/bar/contents/a/c/b/foo')
.reply(404)
.get('/api/v3/repos/foo/bar/contents/Specs/foo')
.reply(200, [{ name: '1.2.3' }]);
const res = await getPkgReleases({
...config,
registryUrls: ['https://github.foo.com/foo/bar'],
});
expect(res).toEqual({
registryUrl: 'https://github.foo.com/foo/bar',
releases: [
{
version: '1.2.3',
},
],
});
});
it('processes real data from Github Enterprise without specs without shard', async () => {
httpMock
.scope(githubEntApiHost)
.get('/api/v3/repos/foo/bar/contents/Specs/a/c/b/foo')
.reply(404)
.get('/api/v3/repos/foo/bar/contents/a/c/b/foo')
.reply(404)
.get('/api/v3/repos/foo/bar/contents/Specs/foo')
.reply(404)
.get('/api/v3/repos/foo/bar/contents/foo')
.reply(200, [{ name: '1.2.3' }]);
const res = await getPkgReleases({
...config,
registryUrls: ['https://github.foo.com/foo/bar'],
});
expect(res).toEqual({
registryUrl: 'https://github.foo.com/foo/bar',
releases: [
{
version: '1.2.3',
},
],
});
2020-03-01 13:03:16 +04:00
});
});
});