forked from renovatebot/renovate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.spec.ts
150 lines (145 loc) · 4.71 KB
/
index.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import fs from 'fs';
import { getPkgReleases } from '..';
import * as httpMock from '../../../test/httpMock';
import { id as datasource } from '.';
const consulData: any = fs.readFileSync(
'lib/datasource/terraform-module/__fixtures__/registry-consul.json'
);
const serviceDiscoveryResult: any = fs.readFileSync(
'lib/datasource/terraform-module/__fixtures__/service-discovery.json'
);
const serviceDiscoveryCustomResult: any = fs.readFileSync(
'lib/datasource/terraform-module/__fixtures__/service-custom-discovery.json'
);
const baseUrl = 'https://registry.terraform.io';
const localTerraformEnterprisebaseUrl = 'https://terraform.foo.bar';
describe('datasource/terraform-module', () => {
describe('getReleases', () => {
beforeEach(() => {
jest.clearAllMocks();
httpMock.setup();
});
afterEach(() => {
httpMock.reset();
});
it('returns null for empty result', async () => {
httpMock
.scope(baseUrl)
.get('/v1/modules/hashicorp/consul/aws')
.reply(200, {})
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
expect(
await getPkgReleases({
datasource,
depName: 'hashicorp/consul/aws',
})
).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('returns null for 404', async () => {
httpMock
.scope(baseUrl)
.get('/v1/modules/hashicorp/consul/aws')
.reply(404, {})
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
expect(
await getPkgReleases({
datasource,
depName: 'hashicorp/consul/aws',
})
).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('returns null for unknown error', async () => {
httpMock
.scope(baseUrl)
.get('/v1/modules/hashicorp/consul/aws')
.replyWithError('')
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
expect(
await getPkgReleases({
datasource,
depName: 'hashicorp/consul/aws',
})
).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('processes real data', async () => {
httpMock
.scope(baseUrl)
.get('/v1/modules/hashicorp/consul/aws')
.reply(200, consulData)
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
const res = await getPkgReleases({
datasource,
depName: 'hashicorp/consul/aws',
});
expect(res).toMatchSnapshot();
expect(res).not.toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('processes with registry in name', async () => {
httpMock
.scope(baseUrl)
.get('/v1/modules/hashicorp/consul/aws')
.reply(200, consulData)
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
const res = await getPkgReleases({
datasource,
depName: 'registry.terraform.io/hashicorp/consul/aws',
});
expect(res).toMatchSnapshot();
expect(res).not.toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('rejects mismatch', async () => {
httpMock
.scope('https://terraform.company.com')
.get('/v1/modules/consul/foo')
.reply(200, consulData)
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
const res = await getPkgReleases({
datasource,
depName: 'consul/foo',
registryUrls: ['https://terraform.company.com'],
});
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
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,
registryUrls: ['terraform.foo.bar'],
depName: 'hashicorp/consul/aws',
});
expect(res).toMatchSnapshot();
expect(res).not.toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
});
});