renovate/test/datasource/terraform.spec.js
Rhys Arkins a9332a8db0
feat: replace purl with datasource (#3154)
This deprecates the (internal) use of package URLs and instead replaces with `datasource`/`lookupName`.

Closes #3005
2019-02-04 09:41:22 +01:00

85 lines
2.4 KiB
JavaScript

const fs = require('fs');
const got = require('../../lib/util/got');
const datasource = require('../../lib/datasource');
jest.mock('../../lib/util/got');
const consulData = fs.readFileSync(
'test/_fixtures/terraform/registry-consul.json'
);
describe('datasource/terraform', () => {
describe('getPkgReleases', () => {
beforeEach(() => {
jest.clearAllMocks();
global.repoCache = {};
return global.renovateCache.rmAll();
});
it('returns null for empty result', async () => {
got.mockReturnValueOnce({ body: {} });
expect(
await datasource.getPkgReleases({
datasource: 'terraform',
lookupName: 'hashicorp/consul/aws',
})
).toBeNull();
});
it('returns null for 404', async () => {
got.mockImplementationOnce(() =>
Promise.reject({
statusCode: 404,
})
);
expect(
await datasource.getPkgReleases({
datasource: 'terraform',
lookupName: 'hashicorp/consul/aws',
})
).toBeNull();
});
it('returns null for unknown error', async () => {
got.mockImplementationOnce(() => {
throw new Error();
});
expect(
await datasource.getPkgReleases({
datasource: 'terraform',
lookupName: 'hashicorp/consul/aws',
})
).toBeNull();
});
it('processes real data', async () => {
got.mockReturnValueOnce({
body: JSON.parse(consulData),
});
const res = await datasource.getPkgReleases({
datasource: 'terraform',
lookupName: 'hashicorp/consul/aws',
});
expect(res).toMatchSnapshot();
expect(res).not.toBeNull();
});
it('processes with registry in name', async () => {
got.mockReturnValueOnce({
body: JSON.parse(consulData),
});
const res = await datasource.getPkgReleases({
datasource: 'terraform',
lookupName: 'registry.terraform.io/hashicorp/consul/aws',
});
expect(res).toMatchSnapshot();
expect(res).not.toBeNull();
});
it('rejects mismatch', async () => {
got.mockReturnValueOnce({
body: JSON.parse(consulData),
});
const res = await datasource.getPkgReleases({
datasource: 'terraform',
lookupName: 'consul/foo',
registryUrls: ['https://terraform.company.com'],
});
expect(res).toBeNull();
});
});
});