@cdktn/hcl2cdk 0.24.0-pre.5 → 0.24.0-pre.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.spec.swcrc +22 -0
- package/LICENSE +355 -0
- package/README.md +1 -1
- package/build/__tests__/jsii-rosetta-workarounds.test.js +2 -2
- package/build/expressions.js +3 -4
- package/build/function-bindings/functions.generated.js +2 -2
- package/build/generation.js +2 -2
- package/build/index.d.ts +20 -20
- package/build/index.js +4 -4
- package/build/references.js +2 -3
- package/build/schema.d.ts +60 -60
- package/build/utils.d.ts +1 -1
- package/build/utils.js +3 -3
- package/jest.config.js +18 -11
- package/package.json +37 -25
- package/package.sh +1 -1
- package/src/__tests__/coerceType.test.ts +207 -0
- package/src/__tests__/expressionToTs.test.ts +1167 -0
- package/src/__tests__/expressions.test.ts +541 -0
- package/src/__tests__/findExpressionType.test.ts +112 -0
- package/src/__tests__/functions.test.ts +768 -0
- package/src/__tests__/generation.test.ts +72 -0
- package/src/__tests__/jsii-rosetta-workarounds.test.ts +145 -0
- package/src/__tests__/partialCode.test.ts +432 -0
- package/src/__tests__/terraformSchema.test.ts +107 -0
- package/src/__tests__/testHelpers.ts +11 -0
- package/src/coerceType.ts +261 -0
- package/src/dynamic-blocks.ts +61 -0
- package/src/expressions.ts +968 -0
- package/src/function-bindings/functions.generated.ts +1139 -0
- package/src/function-bindings/functions.ts +104 -0
- package/src/generation.ts +1189 -0
- package/src/index.ts +584 -0
- package/src/iteration.ts +156 -0
- package/src/jsii-rosetta-workarounds.ts +145 -0
- package/src/partialCode.ts +132 -0
- package/src/provider.ts +60 -0
- package/src/references.ts +193 -0
- package/src/schema.ts +74 -0
- package/src/terraformSchema.ts +182 -0
- package/src/types.ts +58 -0
- package/src/utils.ts +19 -0
- package/src/variables.ts +214 -0
- package/test/__snapshots__/backends.test.ts.snap +70 -0
- package/test/__snapshots__/externals.test.ts.snap +37 -0
- package/test/__snapshots__/granular-imports.test.ts.snap +180 -0
- package/test/__snapshots__/imports.test.ts.snap +159 -0
- package/test/__snapshots__/iteration.test.ts.snap +532 -0
- package/test/__snapshots__/jsiiLanguage.test.ts.snap +347 -0
- package/test/__snapshots__/locals.test.ts.snap +55 -0
- package/test/__snapshots__/modules.test.ts.snap +127 -0
- package/test/__snapshots__/outputs.test.ts.snap +77 -0
- package/test/__snapshots__/partialCode.test.ts.snap +120 -0
- package/test/__snapshots__/provider.test.ts.snap +128 -0
- package/test/__snapshots__/references.test.ts.snap +376 -0
- package/test/__snapshots__/resource-meta-properties.test.ts.snap +342 -0
- package/test/__snapshots__/resources.test.ts.snap +613 -0
- package/test/__snapshots__/tfExpressions.test.ts.snap +537 -0
- package/test/__snapshots__/typeCoercion.test.ts.snap +253 -0
- package/test/__snapshots__/variables.test.ts.snap +150 -0
- package/test/backends.test.ts +75 -0
- package/test/convertProject.test.ts +257 -0
- package/test/externals.test.ts +35 -0
- package/test/globalSetup.ts +224 -0
- package/test/globalTeardown.ts +11 -0
- package/test/granular-imports.test.ts +161 -0
- package/test/hcl2cdk.test.ts +88 -0
- package/test/helpers/convert.ts +543 -0
- package/test/helpers/tmp.ts +25 -0
- package/test/imports.test.ts +141 -0
- package/test/iteration.test.ts +342 -0
- package/test/jsiiLanguage.test.ts +73 -0
- package/test/locals.test.ts +47 -0
- package/test/modules.test.ts +143 -0
- package/test/outputs.test.ts +69 -0
- package/test/partialCode.test.ts +25 -0
- package/test/provider.test.ts +106 -0
- package/test/references.test.ts +287 -0
- package/test/resource-meta-properties.test.ts +288 -0
- package/test/resources.test.ts +551 -0
- package/test/tfExpressions.test.ts +300 -0
- package/test/typeCoercion.test.ts +154 -0
- package/test/variables.test.ts +96 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) HashiCorp, Inc.
|
|
3
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { variableTypeToAst } from "../generation";
|
|
7
|
+
import { ProgramScope } from "../types";
|
|
8
|
+
import { astToCode } from "./testHelpers";
|
|
9
|
+
|
|
10
|
+
describe("variableTypeToAst", () => {
|
|
11
|
+
async function run(type: string) {
|
|
12
|
+
return astToCode(
|
|
13
|
+
await variableTypeToAst(
|
|
14
|
+
{
|
|
15
|
+
importables: [],
|
|
16
|
+
} as unknown as ProgramScope,
|
|
17
|
+
type,
|
|
18
|
+
),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
it("should convert a simple type", async () => {
|
|
23
|
+
expect(await run("${string}")).toMatchInlineSnapshot(
|
|
24
|
+
`"VariableType.STRING"`,
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should convert a object type", async () => {
|
|
29
|
+
expect(
|
|
30
|
+
await run(
|
|
31
|
+
"${object({\n name = string\n address = string\n })}",
|
|
32
|
+
),
|
|
33
|
+
).toMatchInlineSnapshot(`
|
|
34
|
+
"VariableType.object({
|
|
35
|
+
"address": VariableType.STRING,
|
|
36
|
+
"name": VariableType.STRING
|
|
37
|
+
})"
|
|
38
|
+
`);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should convert a list type", async () => {
|
|
42
|
+
expect(
|
|
43
|
+
await run(
|
|
44
|
+
"${list(object({\n internal = number\n external = number\n protocol = string\n }))}",
|
|
45
|
+
),
|
|
46
|
+
).toMatchInlineSnapshot(`
|
|
47
|
+
"VariableType.list(VariableType.object({
|
|
48
|
+
"external": VariableType.NUMBER,
|
|
49
|
+
"internal": VariableType.NUMBER,
|
|
50
|
+
"protocol": VariableType.STRING
|
|
51
|
+
}))"
|
|
52
|
+
`);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should convert a set type", async () => {
|
|
56
|
+
expect(await run("${set(string)}")).toMatchInlineSnapshot(
|
|
57
|
+
`"VariableType.set(VariableType.STRING)"`,
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("should convert a map type", async () => {
|
|
62
|
+
expect(await run("${map(string)}")).toMatchInlineSnapshot(
|
|
63
|
+
`"VariableType.map(VariableType.STRING)"`,
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should convert a tuple type", async () => {
|
|
68
|
+
expect(await run("${tuple(string, number, bool)}")).toMatchInlineSnapshot(
|
|
69
|
+
`"VariableType.tuple(VariableType.STRING, VariableType.NUMBER, VariableType.BOOL)"`,
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// Copyright (c) HashiCorp, Inc
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
replaceCsharpImports,
|
|
6
|
+
replaceGoImports,
|
|
7
|
+
replaceJavaImports,
|
|
8
|
+
replacePythonImports,
|
|
9
|
+
} from "../jsii-rosetta-workarounds";
|
|
10
|
+
|
|
11
|
+
describe("jsii-rosetta-workarounds", () => {
|
|
12
|
+
describe("replacePythonImports", () => {
|
|
13
|
+
it("normal imports", () => {
|
|
14
|
+
const code = `
|
|
15
|
+
import constructs as constructs
|
|
16
|
+
# Provider bindings are generated by running cdktn get.
|
|
17
|
+
# See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
18
|
+
import ...gen.providers.scaleway as scaleway
|
|
19
|
+
class MyConvertedCode(constructs.Construct):
|
|
20
|
+
def __init__(self, scope, name):
|
|
21
|
+
super().__init__(scope, name)
|
|
22
|
+
scaleway.provider.ScalewayProvider(self, "scaleway",
|
|
23
|
+
region="fr-par",
|
|
24
|
+
zone="fr-par-1"
|
|
25
|
+
)`;
|
|
26
|
+
|
|
27
|
+
expect(replacePythonImports(code)).toEqual(
|
|
28
|
+
expect.stringContaining("import imports.scaleway as scaleway"),
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("granular imports", () => {
|
|
33
|
+
const code = `from ...gen.providers.aws.lib.rdsCluster import RdsCluster`;
|
|
34
|
+
|
|
35
|
+
expect(replacePythonImports(code)).toEqual(
|
|
36
|
+
"from imports.aws.rdsCluster import RdsCluster",
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const withoutLibCode = `from ...gen.providers.azurerm.resource_group import ResourceGroup`;
|
|
40
|
+
expect(replacePythonImports(withoutLibCode)).toEqual(
|
|
41
|
+
"from imports.azurerm.resource_group import ResourceGroup",
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("resource imports", () => {
|
|
46
|
+
const code = `import ...gen.providers.aws.lib.rdsCluster as RdsCluster`;
|
|
47
|
+
|
|
48
|
+
expect(replacePythonImports(code)).toEqual(
|
|
49
|
+
"import imports.aws.rdsCluster as RdsCluster",
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("fixes module imports", () => {
|
|
54
|
+
const code = `import ...gen.modules.hello_module as HelloModule`;
|
|
55
|
+
|
|
56
|
+
expect(replacePythonImports(code)).toEqual(
|
|
57
|
+
"import imports.hello_module as HelloModule",
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("replaceCsharpImports", () => {
|
|
63
|
+
it("normal imports", () => {
|
|
64
|
+
const code = `using Gen.Providers.Aws.Lib.RdsCluster;`;
|
|
65
|
+
|
|
66
|
+
expect(replaceCsharpImports(code)).toEqual("using aws.RdsCluster;");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("fixes module imports", () => {
|
|
70
|
+
const code = `using Gen.Modules.HelloModule`;
|
|
71
|
+
|
|
72
|
+
expect(replaceCsharpImports(code)).toEqual("using HelloModule");
|
|
73
|
+
|
|
74
|
+
const anotherCode = `using Gen.Modules.Hello.Module`;
|
|
75
|
+
|
|
76
|
+
expect(replaceCsharpImports(anotherCode)).toEqual("using Hello.Module");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("replaceJavaImports", () => {
|
|
81
|
+
it("normal imports", () => {
|
|
82
|
+
const code = `import gen.providers.scaleway.objectResource.*;`;
|
|
83
|
+
|
|
84
|
+
expect(replaceJavaImports(code)).toEqual(
|
|
85
|
+
"import imports.scaleway.objectResource.*;",
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("precise imports", () => {
|
|
90
|
+
const code = `import gen.providers.aws.lib.s3Bucket.S3Bucket;`;
|
|
91
|
+
|
|
92
|
+
expect(replaceJavaImports(code)).toEqual(
|
|
93
|
+
"import imports.aws.s3Bucket.S3Bucket;",
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const withoutLibImport = `import gen.providers.aws.s3Bucket.S3Bucket;`;
|
|
97
|
+
|
|
98
|
+
expect(replaceJavaImports(withoutLibImport)).toEqual(
|
|
99
|
+
"import imports.aws.s3Bucket.S3Bucket;",
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("fixes module imports", () => {
|
|
104
|
+
const code = `import gen.modules.hello.module.*;`;
|
|
105
|
+
|
|
106
|
+
expect(replaceJavaImports(code)).toEqual(
|
|
107
|
+
"import imports.hello.module.*;",
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const anotherCode = `import gen.modules.helloModule.*;`;
|
|
111
|
+
|
|
112
|
+
expect(replaceJavaImports(anotherCode)).toEqual(
|
|
113
|
+
"import imports.helloModule.*;",
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe("replaceGoImports", () => {
|
|
119
|
+
it("normal imports", () => {
|
|
120
|
+
const code = `import "github.com/aws-samples/dummy/gen/providers/scaleway/objectBucket"`;
|
|
121
|
+
|
|
122
|
+
expect(replaceGoImports(code)).toEqual(
|
|
123
|
+
`import "cdk.tf/go/stack/generated/scaleway/objectBucket"`,
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("precise imports", () => {
|
|
128
|
+
const code = `import "github.com/aws-samples/dummy/gen/providers/aws/lib/dbInstance"`;
|
|
129
|
+
|
|
130
|
+
expect(replaceGoImports(code)).toEqual(
|
|
131
|
+
`import "cdk.tf/go/stack/generated/aws/dbInstance"`,
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("fixes module imports", () => {
|
|
136
|
+
const code = `import helloModule "github.com/aws-samples/dummy/gen/modules/hello_module"`;
|
|
137
|
+
|
|
138
|
+
expect(replaceGoImports(code)).toEqual(
|
|
139
|
+
// TODO: Set up cdktn.io/ static redirect?
|
|
140
|
+
// "github.com/open-constructs/cdk-terrain/examples/go/documentation/generated/terraform-aws-modules/aws/vpc"
|
|
141
|
+
`import helloModule "cdk.tf/go/stack/generated/hello_module"`,
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) HashiCorp, Inc.
|
|
3
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { fillWithConfigAccessors } from "../partialCode";
|
|
7
|
+
import { ProgramScope } from "../types";
|
|
8
|
+
|
|
9
|
+
const getScope = () =>
|
|
10
|
+
({
|
|
11
|
+
providerSchema: {
|
|
12
|
+
format_version: "0.1",
|
|
13
|
+
provider_schemas: {
|
|
14
|
+
aws: {
|
|
15
|
+
data_source_schemas: {},
|
|
16
|
+
provider: {
|
|
17
|
+
block: {
|
|
18
|
+
attributes: {},
|
|
19
|
+
block_types: {},
|
|
20
|
+
},
|
|
21
|
+
version: 0,
|
|
22
|
+
},
|
|
23
|
+
resource_schemas: {
|
|
24
|
+
aws_image: {
|
|
25
|
+
version: 0,
|
|
26
|
+
block: {
|
|
27
|
+
block_types: {
|
|
28
|
+
c: {
|
|
29
|
+
nesting_mode: "single",
|
|
30
|
+
block: {
|
|
31
|
+
attributes: {
|
|
32
|
+
d: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description_kind: "plain",
|
|
35
|
+
optional: true,
|
|
36
|
+
required: true,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
block_types: {},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
d: {
|
|
43
|
+
nesting_mode: "list",
|
|
44
|
+
block: {
|
|
45
|
+
attributes: {
|
|
46
|
+
e: {
|
|
47
|
+
type: "string",
|
|
48
|
+
description_kind: "plain",
|
|
49
|
+
optional: true,
|
|
50
|
+
required: true,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
block_types: {},
|
|
54
|
+
},
|
|
55
|
+
min_items: 1,
|
|
56
|
+
},
|
|
57
|
+
timeouts: {
|
|
58
|
+
nesting_mode: "single",
|
|
59
|
+
block: {
|
|
60
|
+
attributes: {
|
|
61
|
+
read: {
|
|
62
|
+
type: "string",
|
|
63
|
+
description_kind: "plain",
|
|
64
|
+
optional: true,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
block_types: {},
|
|
68
|
+
description_kind: "plain",
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
attributes: {
|
|
73
|
+
a: {
|
|
74
|
+
type: "string",
|
|
75
|
+
required: true,
|
|
76
|
+
},
|
|
77
|
+
b: {
|
|
78
|
+
type: "string",
|
|
79
|
+
required: true,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
constructs: new Set(),
|
|
89
|
+
hasTokenBasedTypeCoercion: false,
|
|
90
|
+
nodeIds: [],
|
|
91
|
+
providerGenerator: {},
|
|
92
|
+
variables: {},
|
|
93
|
+
importables: [],
|
|
94
|
+
|
|
95
|
+
// This should be mutated
|
|
96
|
+
topLevelConfig: {},
|
|
97
|
+
}) as ProgramScope;
|
|
98
|
+
|
|
99
|
+
describe("fillWithConfigAccessors", () => {
|
|
100
|
+
it("adds a missing required attributes", () => {
|
|
101
|
+
const scope = getScope();
|
|
102
|
+
const result = fillWithConfigAccessors(
|
|
103
|
+
scope,
|
|
104
|
+
{
|
|
105
|
+
a: "a",
|
|
106
|
+
c: {
|
|
107
|
+
d: "d",
|
|
108
|
+
},
|
|
109
|
+
timeouts: {
|
|
110
|
+
read: "20m",
|
|
111
|
+
},
|
|
112
|
+
d: [{ e: "e" }],
|
|
113
|
+
},
|
|
114
|
+
"aws.image",
|
|
115
|
+
);
|
|
116
|
+
expect(scope.topLevelConfig.b).toEqual("aws.image.b");
|
|
117
|
+
expect(result).toMatchInlineSnapshot(`
|
|
118
|
+
{
|
|
119
|
+
"a": "a",
|
|
120
|
+
"b": {
|
|
121
|
+
"computed": false,
|
|
122
|
+
"object": {
|
|
123
|
+
"name": "config",
|
|
124
|
+
"type": "Identifier",
|
|
125
|
+
},
|
|
126
|
+
"optional": null,
|
|
127
|
+
"property": {
|
|
128
|
+
"name": "b",
|
|
129
|
+
"type": "Identifier",
|
|
130
|
+
},
|
|
131
|
+
"type": "MemberExpression",
|
|
132
|
+
},
|
|
133
|
+
"c": {
|
|
134
|
+
"d": "d",
|
|
135
|
+
},
|
|
136
|
+
"d": [
|
|
137
|
+
{
|
|
138
|
+
"e": "e",
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
"timeouts": {
|
|
142
|
+
"read": "20m",
|
|
143
|
+
},
|
|
144
|
+
}
|
|
145
|
+
`);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("ignores missing unrequired set block types", () => {
|
|
149
|
+
const scope = getScope();
|
|
150
|
+
const result = fillWithConfigAccessors(
|
|
151
|
+
scope,
|
|
152
|
+
{
|
|
153
|
+
a: "a",
|
|
154
|
+
b: "b",
|
|
155
|
+
c: {
|
|
156
|
+
d: "d",
|
|
157
|
+
},
|
|
158
|
+
d: [{ e: "e" }],
|
|
159
|
+
},
|
|
160
|
+
"aws.image",
|
|
161
|
+
);
|
|
162
|
+
expect(scope.topLevelConfig).toEqual({});
|
|
163
|
+
expect(result).toMatchInlineSnapshot(`
|
|
164
|
+
{
|
|
165
|
+
"a": "a",
|
|
166
|
+
"b": "b",
|
|
167
|
+
"c": {
|
|
168
|
+
"d": "d",
|
|
169
|
+
},
|
|
170
|
+
"d": [
|
|
171
|
+
{
|
|
172
|
+
"e": "e",
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
}
|
|
176
|
+
`);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("fills within a single block type", () => {
|
|
180
|
+
const scope = getScope();
|
|
181
|
+
const result = fillWithConfigAccessors(
|
|
182
|
+
scope,
|
|
183
|
+
{
|
|
184
|
+
a: "a",
|
|
185
|
+
b: "b",
|
|
186
|
+
c: {},
|
|
187
|
+
d: [{ e: "e" }],
|
|
188
|
+
},
|
|
189
|
+
"aws.image",
|
|
190
|
+
);
|
|
191
|
+
expect(scope.topLevelConfig).toEqual({
|
|
192
|
+
d: "aws.image.c.d",
|
|
193
|
+
});
|
|
194
|
+
expect(result).toMatchInlineSnapshot(`
|
|
195
|
+
{
|
|
196
|
+
"a": "a",
|
|
197
|
+
"b": "b",
|
|
198
|
+
"c": {
|
|
199
|
+
"d": {
|
|
200
|
+
"computed": false,
|
|
201
|
+
"object": {
|
|
202
|
+
"name": "config",
|
|
203
|
+
"type": "Identifier",
|
|
204
|
+
},
|
|
205
|
+
"optional": null,
|
|
206
|
+
"property": {
|
|
207
|
+
"name": "d",
|
|
208
|
+
"type": "Identifier",
|
|
209
|
+
},
|
|
210
|
+
"type": "MemberExpression",
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
"d": [
|
|
214
|
+
{
|
|
215
|
+
"e": "e",
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
}
|
|
219
|
+
`);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("fills an entire single block type", () => {
|
|
223
|
+
const scope = getScope();
|
|
224
|
+
const result = fillWithConfigAccessors(
|
|
225
|
+
scope,
|
|
226
|
+
{
|
|
227
|
+
a: "a",
|
|
228
|
+
b: "b",
|
|
229
|
+
d: [{ e: "e" }],
|
|
230
|
+
},
|
|
231
|
+
"aws.image",
|
|
232
|
+
);
|
|
233
|
+
expect(scope.topLevelConfig).toEqual({
|
|
234
|
+
c: "aws.image.c",
|
|
235
|
+
});
|
|
236
|
+
expect(result).toMatchInlineSnapshot(`
|
|
237
|
+
{
|
|
238
|
+
"a": "a",
|
|
239
|
+
"b": "b",
|
|
240
|
+
"c": {
|
|
241
|
+
"computed": false,
|
|
242
|
+
"object": {
|
|
243
|
+
"name": "config",
|
|
244
|
+
"type": "Identifier",
|
|
245
|
+
},
|
|
246
|
+
"optional": null,
|
|
247
|
+
"property": {
|
|
248
|
+
"name": "c",
|
|
249
|
+
"type": "Identifier",
|
|
250
|
+
},
|
|
251
|
+
"type": "MemberExpression",
|
|
252
|
+
},
|
|
253
|
+
"d": [
|
|
254
|
+
{
|
|
255
|
+
"e": "e",
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
}
|
|
259
|
+
`);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("fills within a list block type", () => {
|
|
263
|
+
const scope = getScope();
|
|
264
|
+
const result = fillWithConfigAccessors(
|
|
265
|
+
scope,
|
|
266
|
+
{
|
|
267
|
+
a: "a",
|
|
268
|
+
b: "b",
|
|
269
|
+
c: { d: "d" },
|
|
270
|
+
d: [{}],
|
|
271
|
+
},
|
|
272
|
+
"aws.image",
|
|
273
|
+
);
|
|
274
|
+
expect(scope.topLevelConfig).toEqual({
|
|
275
|
+
e: "aws.image.d.[].e",
|
|
276
|
+
});
|
|
277
|
+
expect(result).toMatchInlineSnapshot(`
|
|
278
|
+
{
|
|
279
|
+
"a": "a",
|
|
280
|
+
"b": "b",
|
|
281
|
+
"c": {
|
|
282
|
+
"d": "d",
|
|
283
|
+
},
|
|
284
|
+
"d": [
|
|
285
|
+
{
|
|
286
|
+
"e": {
|
|
287
|
+
"computed": false,
|
|
288
|
+
"object": {
|
|
289
|
+
"name": "config",
|
|
290
|
+
"type": "Identifier",
|
|
291
|
+
},
|
|
292
|
+
"optional": null,
|
|
293
|
+
"property": {
|
|
294
|
+
"name": "e",
|
|
295
|
+
"type": "Identifier",
|
|
296
|
+
},
|
|
297
|
+
"type": "MemberExpression",
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
],
|
|
301
|
+
}
|
|
302
|
+
`);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("fills an entire list block type", () => {
|
|
306
|
+
const scope = getScope();
|
|
307
|
+
const result = fillWithConfigAccessors(
|
|
308
|
+
scope,
|
|
309
|
+
{
|
|
310
|
+
a: "a",
|
|
311
|
+
b: "b",
|
|
312
|
+
c: { d: "d" },
|
|
313
|
+
},
|
|
314
|
+
"aws.image",
|
|
315
|
+
);
|
|
316
|
+
expect(scope.topLevelConfig).toEqual({
|
|
317
|
+
d: "aws.image.d",
|
|
318
|
+
});
|
|
319
|
+
expect(result).toMatchInlineSnapshot(`
|
|
320
|
+
{
|
|
321
|
+
"a": "a",
|
|
322
|
+
"b": "b",
|
|
323
|
+
"c": {
|
|
324
|
+
"d": "d",
|
|
325
|
+
},
|
|
326
|
+
"d": {
|
|
327
|
+
"computed": false,
|
|
328
|
+
"object": {
|
|
329
|
+
"name": "config",
|
|
330
|
+
"type": "Identifier",
|
|
331
|
+
},
|
|
332
|
+
"optional": null,
|
|
333
|
+
"property": {
|
|
334
|
+
"name": "d",
|
|
335
|
+
"type": "Identifier",
|
|
336
|
+
},
|
|
337
|
+
"type": "MemberExpression",
|
|
338
|
+
},
|
|
339
|
+
}
|
|
340
|
+
`);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("can handle multiple fills with the same name", () => {
|
|
344
|
+
const scope = getScope();
|
|
345
|
+
const result = fillWithConfigAccessors(
|
|
346
|
+
scope,
|
|
347
|
+
{
|
|
348
|
+
a: "a",
|
|
349
|
+
b: "b",
|
|
350
|
+
c: {},
|
|
351
|
+
},
|
|
352
|
+
"aws.image",
|
|
353
|
+
);
|
|
354
|
+
expect(scope.topLevelConfig).toEqual({
|
|
355
|
+
d: "aws.image.c.d",
|
|
356
|
+
d1: "aws.image.d",
|
|
357
|
+
});
|
|
358
|
+
expect(result).toMatchInlineSnapshot(`
|
|
359
|
+
{
|
|
360
|
+
"a": "a",
|
|
361
|
+
"b": "b",
|
|
362
|
+
"c": {
|
|
363
|
+
"d": {
|
|
364
|
+
"computed": false,
|
|
365
|
+
"object": {
|
|
366
|
+
"name": "config",
|
|
367
|
+
"type": "Identifier",
|
|
368
|
+
},
|
|
369
|
+
"optional": null,
|
|
370
|
+
"property": {
|
|
371
|
+
"name": "d",
|
|
372
|
+
"type": "Identifier",
|
|
373
|
+
},
|
|
374
|
+
"type": "MemberExpression",
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
"d": {
|
|
378
|
+
"computed": false,
|
|
379
|
+
"object": {
|
|
380
|
+
"name": "config",
|
|
381
|
+
"type": "Identifier",
|
|
382
|
+
},
|
|
383
|
+
"optional": null,
|
|
384
|
+
"property": {
|
|
385
|
+
"name": "d1",
|
|
386
|
+
"type": "Identifier",
|
|
387
|
+
},
|
|
388
|
+
"type": "MemberExpression",
|
|
389
|
+
},
|
|
390
|
+
}
|
|
391
|
+
`);
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it("fills lists with min_items > 0", () => {
|
|
395
|
+
const scope = getScope();
|
|
396
|
+
const result = fillWithConfigAccessors(
|
|
397
|
+
scope,
|
|
398
|
+
{
|
|
399
|
+
a: "a",
|
|
400
|
+
b: "b",
|
|
401
|
+
c: { d: "d" },
|
|
402
|
+
d: [],
|
|
403
|
+
},
|
|
404
|
+
"aws.image",
|
|
405
|
+
);
|
|
406
|
+
expect(scope.topLevelConfig).toEqual({
|
|
407
|
+
d: "aws.image.d",
|
|
408
|
+
});
|
|
409
|
+
expect(result).toMatchInlineSnapshot(`
|
|
410
|
+
{
|
|
411
|
+
"a": "a",
|
|
412
|
+
"b": "b",
|
|
413
|
+
"c": {
|
|
414
|
+
"d": "d",
|
|
415
|
+
},
|
|
416
|
+
"d": {
|
|
417
|
+
"computed": false,
|
|
418
|
+
"object": {
|
|
419
|
+
"name": "config",
|
|
420
|
+
"type": "Identifier",
|
|
421
|
+
},
|
|
422
|
+
"optional": null,
|
|
423
|
+
"property": {
|
|
424
|
+
"name": "d",
|
|
425
|
+
"type": "Identifier",
|
|
426
|
+
},
|
|
427
|
+
"type": "MemberExpression",
|
|
428
|
+
},
|
|
429
|
+
}
|
|
430
|
+
`);
|
|
431
|
+
});
|
|
432
|
+
});
|