mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
ff2e40bd21
Adds a new datasource for querying terraform module registries.
73 lines
2.1 KiB
JavaScript
73 lines
2.1 KiB
JavaScript
const fs = require('fs');
|
|
const got = require('got');
|
|
const datasource = require('../../lib/datasource');
|
|
|
|
jest.mock('got');
|
|
|
|
const consulData = fs.readFileSync(
|
|
'test/_fixtures/terraform/registry-consul.json'
|
|
);
|
|
|
|
describe('datasource/terraform', () => {
|
|
describe('getPkgReleases', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
return global.renovateCache.rmAll();
|
|
});
|
|
it('returns null for empty result', async () => {
|
|
got.mockReturnValueOnce({ body: {} });
|
|
expect(
|
|
await datasource.getPkgReleases('pkg:terraform/hashicorp/consul/aws')
|
|
).toBeNull();
|
|
});
|
|
it('returns null for 404', async () => {
|
|
got.mockImplementationOnce(() =>
|
|
Promise.reject({
|
|
statusCode: 404,
|
|
})
|
|
);
|
|
expect(
|
|
await datasource.getPkgReleases('pkg:terraform/hashicorp/consul/aws')
|
|
).toBeNull();
|
|
});
|
|
it('returns null for unknown error', async () => {
|
|
got.mockImplementationOnce(() => {
|
|
throw new Error();
|
|
});
|
|
expect(
|
|
await datasource.getPkgReleases('pkg:terraform/hashicorp/consul/aws')
|
|
).toBeNull();
|
|
});
|
|
it('processes real data', async () => {
|
|
got.mockReturnValueOnce({
|
|
body: JSON.parse(consulData),
|
|
});
|
|
const res = await datasource.getPkgReleases(
|
|
'pkg:terraform/hashicorp/consul/aws'
|
|
);
|
|
expect(res).toMatchSnapshot();
|
|
expect(res).not.toBeNull();
|
|
});
|
|
it('returns from cache', async () => {
|
|
got.mockReturnValueOnce({
|
|
body: JSON.parse(consulData),
|
|
});
|
|
const res1 = await datasource.getPkgReleases(
|
|
'pkg:terraform/hashicorp/consul/aws'
|
|
);
|
|
const res2 = await datasource.getPkgReleases(
|
|
'pkg:terraform/hashicorp/consul/aws'
|
|
);
|
|
expect(res1).toEqual(res2);
|
|
});
|
|
it('rejects mismatch', async () => {
|
|
got.mockReturnValueOnce({
|
|
body: JSON.parse(consulData),
|
|
});
|
|
const res = await datasource.getPkgReleases(
|
|
'pkg:terraform/consul/foo?registry=hashicorp'
|
|
);
|
|
expect(res).toBeNull();
|
|
});
|
|
});
|
|
});
|