2020-06-18 19:31:40 +00:00
|
|
|
import { getPkgReleases } from '..';
|
2020-12-11 12:29:43 +00:00
|
|
|
import * as httpMock from '../../../test/http-mock';
|
2021-08-18 05:46:56 +00:00
|
|
|
import { loadFixture } from '../../../test/util';
|
2021-06-25 12:12:23 +00:00
|
|
|
import { TerraformModuleDatasource } from '.';
|
2018-10-06 07:52:00 +00:00
|
|
|
|
2021-04-26 14:15:03 +00:00
|
|
|
const consulData: any = loadFixture('registry-consul.json');
|
|
|
|
const serviceDiscoveryResult: any = loadFixture('service-discovery.json');
|
2021-04-23 16:58:48 +00:00
|
|
|
const serviceDiscoveryCustomResult: any = loadFixture(
|
|
|
|
'service-custom-discovery.json'
|
2020-07-13 05:37:01 +00:00
|
|
|
);
|
2018-10-06 07:52:00 +00:00
|
|
|
|
2021-06-25 12:12:23 +00:00
|
|
|
const datasource = TerraformModuleDatasource.id;
|
2020-06-16 05:11:21 +00:00
|
|
|
const baseUrl = 'https://registry.terraform.io';
|
2020-07-13 05:37:01 +00:00
|
|
|
const localTerraformEnterprisebaseUrl = 'https://terraform.foo.bar';
|
2020-06-16 05:11:21 +00:00
|
|
|
|
2021-08-18 05:46:56 +00:00
|
|
|
describe('datasource/terraform-module/index', () => {
|
2020-04-04 06:53:52 +00:00
|
|
|
describe('getReleases', () => {
|
2018-10-06 07:52:00 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
2020-06-16 05:11:21 +00:00
|
|
|
});
|
|
|
|
|
2018-10-06 07:52:00 +00:00
|
|
|
it('returns null for empty result', async () => {
|
2020-06-16 05:11:21 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/v1/modules/hashicorp/consul/aws')
|
2020-07-13 05:37:01 +00:00
|
|
|
.reply(200, {})
|
|
|
|
.get('/.well-known/terraform.json')
|
|
|
|
.reply(200, serviceDiscoveryResult);
|
2018-10-06 07:52:00 +00:00
|
|
|
expect(
|
2020-06-18 19:31:40 +00:00
|
|
|
await getPkgReleases({
|
|
|
|
datasource,
|
|
|
|
depName: 'hashicorp/consul/aws',
|
2020-03-12 11:48:57 +00:00
|
|
|
})
|
|
|
|
).toBeNull();
|
2020-06-16 05:11:21 +00:00
|
|
|
expect(httpMock.getTrace()).toMatchSnapshot();
|
2020-03-12 11:48:57 +00:00
|
|
|
});
|
|
|
|
it('returns null for 404', async () => {
|
2020-06-16 05:11:21 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/v1/modules/hashicorp/consul/aws')
|
2020-07-13 05:37:01 +00:00
|
|
|
.reply(404, {})
|
|
|
|
.get('/.well-known/terraform.json')
|
|
|
|
.reply(200, serviceDiscoveryResult);
|
2020-03-12 11:48:57 +00:00
|
|
|
expect(
|
2020-06-18 19:31:40 +00:00
|
|
|
await getPkgReleases({
|
|
|
|
datasource,
|
|
|
|
depName: 'hashicorp/consul/aws',
|
2020-03-12 11:48:57 +00:00
|
|
|
})
|
|
|
|
).toBeNull();
|
2020-06-16 05:11:21 +00:00
|
|
|
expect(httpMock.getTrace()).toMatchSnapshot();
|
2020-03-12 11:48:57 +00:00
|
|
|
});
|
|
|
|
it('returns null for unknown error', async () => {
|
2020-06-16 05:11:21 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/v1/modules/hashicorp/consul/aws')
|
2020-07-13 05:37:01 +00:00
|
|
|
.replyWithError('')
|
|
|
|
.get('/.well-known/terraform.json')
|
|
|
|
.reply(200, serviceDiscoveryResult);
|
2020-03-12 11:48:57 +00:00
|
|
|
expect(
|
2020-06-18 19:31:40 +00:00
|
|
|
await getPkgReleases({
|
|
|
|
datasource,
|
|
|
|
depName: 'hashicorp/consul/aws',
|
2019-01-28 05:40:37 +00:00
|
|
|
})
|
2018-10-06 07:52:00 +00:00
|
|
|
).toBeNull();
|
2020-06-16 05:11:21 +00:00
|
|
|
expect(httpMock.getTrace()).toMatchSnapshot();
|
2018-10-06 07:52:00 +00:00
|
|
|
});
|
|
|
|
it('processes real data', async () => {
|
2020-06-16 05:11:21 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/v1/modules/hashicorp/consul/aws')
|
2020-07-13 05:37:01 +00:00
|
|
|
.reply(200, consulData)
|
|
|
|
.get('/.well-known/terraform.json')
|
|
|
|
.reply(200, serviceDiscoveryResult);
|
2020-06-18 19:31:40 +00:00
|
|
|
const res = await getPkgReleases({
|
|
|
|
datasource,
|
|
|
|
depName: 'hashicorp/consul/aws',
|
2019-01-28 05:40:37 +00:00
|
|
|
});
|
2018-10-06 07:52:00 +00:00
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
expect(res).not.toBeNull();
|
2020-06-16 05:11:21 +00:00
|
|
|
expect(httpMock.getTrace()).toMatchSnapshot();
|
2018-10-06 07:52:00 +00:00
|
|
|
});
|
2019-01-30 08:55:57 +00:00
|
|
|
it('processes with registry in name', async () => {
|
2020-06-16 05:11:21 +00:00
|
|
|
httpMock
|
|
|
|
.scope(baseUrl)
|
|
|
|
.get('/v1/modules/hashicorp/consul/aws')
|
2020-07-13 05:37:01 +00:00
|
|
|
.reply(200, consulData)
|
|
|
|
.get('/.well-known/terraform.json')
|
|
|
|
.reply(200, serviceDiscoveryResult);
|
2020-06-18 19:31:40 +00:00
|
|
|
const res = await getPkgReleases({
|
|
|
|
datasource,
|
|
|
|
depName: 'registry.terraform.io/hashicorp/consul/aws',
|
2019-01-30 08:55:57 +00:00
|
|
|
});
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
expect(res).not.toBeNull();
|
2020-06-16 05:11:21 +00:00
|
|
|
expect(httpMock.getTrace()).toMatchSnapshot();
|
2019-01-30 08:55:57 +00:00
|
|
|
});
|
2018-10-06 07:52:00 +00:00
|
|
|
it('rejects mismatch', async () => {
|
2020-06-16 05:11:21 +00:00
|
|
|
httpMock
|
|
|
|
.scope('https://terraform.company.com')
|
|
|
|
.get('/v1/modules/consul/foo')
|
2020-07-13 05:37:01 +00:00
|
|
|
.reply(200, consulData)
|
|
|
|
.get('/.well-known/terraform.json')
|
|
|
|
.reply(200, serviceDiscoveryResult);
|
2020-06-18 19:31:40 +00:00
|
|
|
const res = await getPkgReleases({
|
|
|
|
datasource,
|
|
|
|
depName: 'consul/foo',
|
2019-01-30 08:55:57 +00:00
|
|
|
registryUrls: ['https://terraform.company.com'],
|
|
|
|
});
|
2018-10-06 07:52:00 +00:00
|
|
|
expect(res).toBeNull();
|
2020-06-16 05:11:21 +00:00
|
|
|
expect(httpMock.getTrace()).toMatchSnapshot();
|
2018-10-06 07:52:00 +00:00
|
|
|
});
|
2020-07-13 05:37:01 +00:00
|
|
|
it('rejects servicediscovery', async () => {
|
|
|
|
httpMock
|
|
|
|
.scope('https://terraform.company.com')
|
|
|
|
.get('/.well-known/terraform.json')
|
|
|
|
.reply(404);
|
|
|
|
const res = await getPkgReleases({
|
|
|
|
datasource,
|
|
|
|
depName: 'consul/foo',
|
|
|
|
registryUrls: ['https://terraform.company.com'],
|
|
|
|
});
|
|
|
|
expect(res).toBeNull();
|
|
|
|
expect(httpMock.getTrace()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('processes real data on changed subpath', async () => {
|
|
|
|
httpMock
|
|
|
|
.scope(localTerraformEnterprisebaseUrl)
|
|
|
|
.get('/api/registry/v1/modules/hashicorp/consul/aws')
|
|
|
|
.reply(200, consulData)
|
|
|
|
.get('/.well-known/terraform.json')
|
|
|
|
.reply(200, serviceDiscoveryCustomResult);
|
|
|
|
const res = await getPkgReleases({
|
|
|
|
datasource,
|
2020-07-13 19:33:24 +00:00
|
|
|
registryUrls: ['https://terraform.foo.bar'],
|
2020-07-13 05:37:01 +00:00
|
|
|
depName: 'hashicorp/consul/aws',
|
|
|
|
});
|
2020-07-22 18:15:48 +00:00
|
|
|
expect(httpMock.getTrace()).toMatchSnapshot();
|
2020-07-13 05:37:01 +00:00
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
expect(res).not.toBeNull();
|
|
|
|
});
|
2018-10-06 07:52:00 +00:00
|
|
|
});
|
|
|
|
});
|