/
index.spec.ts
112 lines (107 loc) · 2.88 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
import { Fixtures } from '../../../../../test/fixtures';
import { parseHCL, parseJSON } from './index';
const modulesTF = Fixtures.get('modules.tf');
const resourcesTF = Fixtures.get('resources.tf');
const resourcesTFJSON = Fixtures.get('resources.tf.json');
const lockedVersion = Fixtures.get('lockedVersion.tf');
describe('modules/manager/terraform/hcl/index', () => {
describe('parseHCL()', () => {
it('should return flat modules', async () => {
const res = await parseHCL(modulesTF, 'file.tf');
expect(res?.module).toBeDefined();
expect(Object.keys(res!.module!)).toBeArrayOfSize(6);
expect(res).toMatchObject({
module: {
bar: [
{
source: 'github.com/hashicorp/example?ref=next',
},
],
consul: [
{
source: 'hashicorp/consul/aws',
version: '0.1.0',
},
],
foo: [
{
source: 'github.com/hashicorp/example?ref=v1.0.0',
},
],
'repo-with-dot': [
{
source: 'github.com/hashicorp/example.2.3?ref=v1.0.0',
},
],
'repo-with-dot-and-git-suffix': [
{
source: 'github.com/hashicorp/example.2.3.git?ref=v1.0.0',
},
],
'repo-with-non-semver-ref': [
{
source:
'github.com/githubuser/myrepo//terraform/modules/moduleone?ref=tfmodule_one-v0.0.9',
},
],
},
});
});
it('should return nested terraform block', async () => {
const res = await parseHCL(lockedVersion, 'file.tf');
expect(res).toMatchObject({
terraform: [
{
required_providers: [
{
aws: {},
azurerm: {},
kubernetes: {},
},
],
},
],
});
});
it('should return resource blocks', async () => {
const res = await parseHCL(resourcesTF, 'file.tf');
expect(res).toMatchObject({
resource: {
docker_container: {
foo: {},
invalid: {},
},
docker_service: {
foo: [
{
name: 'foo-service',
task_spec: [
{
container_spec: {},
},
],
endpoint_spec: [
{
ports: {},
},
],
},
],
},
},
});
});
});
describe('parseJSON', () => {
it('should parse json', () => {
const res = parseJSON(resourcesTFJSON);
expect(res).toMatchObject({
resource: {
aws_instance: {
example: {},
},
},
});
});
});
});