Skip to content

Commit

Permalink
chore: add hcl tests to edge test
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Mar 4, 2024
1 parent ac4ef36 commit 11ff59b
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 35 deletions.
2 changes: 1 addition & 1 deletion test/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export class TestDriver {

const isWindows = process.platform === "win32";
const isPosix = process.platform !== "win32";
const isHcl =
export const isHcl =
process.env.SYNTH_HCL_OUTPUT === "true" ||
process.env.SYNTH_HCL_OUTPUT === "1";

Expand Down
288 changes: 288 additions & 0 deletions test/typescript/edge/__snapshots__/test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`edge provider test IteratorStack synth generates HCL, not JSON 1`] = `
"terraform {
required_providers {
edge = {
source = "registry.terraform.io/cdktf/edge"
}
}
backend "local" {
path = "/private/var/folders/m4/673s3vwn1_g7c72bmvq521g00000gn/T/testQeCsmG/terraform.iterator.tfstate"
}
}
provider "edge" {
reqstr = "reqstr"
reqnum = 123
reqbool = true
}
resource "optional_attribute_resource" "target" {
strList = [
"a",
"b",
"c"
]
}
resource "list_block_resource" "list" {
req {
reqstr = "reqstr"
reqnum = 1
reqbool = true
}
req {
reqstr = "reqstr2"
reqnum = 0
reqbool = false
}
singlereq {
reqstr = "reqstr"
reqnum = 1
reqbool = false
}
}
resource "map_resource" "map" {
optMap = {
key1 = "value1"
key2 = "value2"
}
reqMap = {
key1 = true
}
}
resource "optional_attribute_resource" "string_list_target" {
str = "\${each.value}"
for_each = "\${toset(optional_attribute_resource.target.strList)}"
}
resource "optional_attribute_resource" "complex_list_target" {
str = "\${each.value.reqstr}"
num = "\${each.value.reqnum}"
for_each = "\${toset(list_block_resource.list.req)}"
}
resource "optional_attribute_resource" "string_map_target" {
str = "\${each.value}"
for_each = "\${map_resource.map.optMap}"
}
resource "list_block_resource" "list_attribute" {
dynamic "req" {
for_each = "\${toset(list_block_resource.list.req)}"
iterator = each
content {
reqbool = "\${each.value.reqbool}"
reqstr = "\${each.value.reqstr}"
reqnum = "\${each.value.reqnum}"
}
}
singlereq {
reqstr = "a"
reqnum = 0
reqbool = true
}
}"
`;

exports[`edge provider test ReferenceStack synth generates HCL, not JSON 1`] = `
"terraform {
required_providers {
edge = {
source = "registry.terraform.io/cdktf/edge"
}
}
backend "local" {
path = "/private/var/folders/m4/673s3vwn1_g7c72bmvq521g00000gn/T/testQeCsmG/terraform.reference.tfstate"
}
}
provider "edge" {
reqstr = "reqstr"
reqnum = 123
reqbool = true
}
resource "optional_attribute_resource" "null" {
bool = null
}
resource "optional_attribute_resource" "test" {
}
resource "list_block_resource" "list" {
req {
reqstr = "reqstr"
reqnum = 1
reqbool = true
}
req {
reqstr = "reqstr2"
reqnum = 0
reqbool = false
}
singlereq {
reqstr = "reqstr"
reqnum = 1
reqbool = false
}
}
resource "map_resource" "map" {
optMap = {
key1 = "value1"
}
reqMap = {
key1 = true
}
}
resource "set_block_resource" "set_block" {
set {
reqstr = "reqstr"
reqnum = 1
reqbool = true
}
set {
reqstr = "reqstr2"
reqnum = 0
reqbool = false
}
}
resource "required_attribute_resource" "plain" {
str = "\${optional_attribute_resource.test.str}"
num = "\${optional_attribute_resource.test.num}"
bool = "\${optional_attribute_resource.test.bool}"
strList = "\${optional_attribute_resource.test.strList}"
numList = "\${optional_attribute_resource.test.numList}"
boolList = "\${optional_attribute_resource.test.boolList}"
}
resource "required_attribute_resource" "from_single_list" {
str = "\${list_block_resource.list.singlereq[0].reqstr}"
num = "\${list_block_resource.list.singlereq[0].reqnum}"
bool = "\${list_block_resource.list.singlereq[0].reqbool}"
strList = [
"\${list_block_resource.list.singlereq[0].reqstr}"
]
numList = [
$ { list_block_resource.list.singlereq[0].reqnum }
]
boolList = [
$ { list_block_resource.list.singlereq[0].reqbool }
]
}
resource "required_attribute_resource" "from_list" {
str = "\${list_block_resource.list.req[0].reqstr}"
num = "\${element(list_block_resource.list.req, 0).reqnum}"
bool = "\${element(list_block_resource.list.req, 0).reqbool}"
strList = [
"\${list_block_resource.list.req[0].reqstr}"
]
numList = [
$ { element(list_block_resource.list.req, 0).reqnum }
]
boolList = [
$ { element(list_block_resource.list.req, 0).reqbool }
]
}
resource "list_block_resource" "list_reference" {
req = "\${list_block_resource.list.req}"
singlereq {
optstr = "\${list_block_resource.list.singlereq[0].optstr}"
optnum = "\${list_block_resource.list.singlereq[0].optnum}"
optbool = "\${list_block_resource.list.singlereq[0].optbool}"
reqstr = "\${list_block_resource.list.singlereq[0].reqstr}"
reqnum = "\${list_block_resource.list.singlereq[0].reqnum}"
reqbool = "\${list_block_resource.list.singlereq[0].reqbool}"
computedstr = "\${list_block_resource.list.singlereq[0].computedstr}"
computednum = "\${list_block_resource.list.singlereq[0].computednum}"
computedbool = "\${list_block_resource.list.singlereq[0].computedbool}"
}
}
resource "list_block_resource" "list_literal" {
req {
0 = "$"
1 = {
2 = "l"
3 = "i"
4 = "s"
5 = "t"
6 = "_"
7 = "b"
8 = "l"
9 = "o"
10 = "c"
11 = "k"
12 = "_"
13 = "r"
14 = "e"
15 = "s"
16 = "o"
17 = "u"
18 = "r"
19 = "c"
20 = "e"
21 = "."
22 = "l"
23 = "i"
24 = "s"
25 = "t"
26 = "."
27 = "s"
28 = "i"
29 = "n"
30 = "g"
31 = "l"
32 = "e"
33 = "r"
34 = "e"
35 = "q"
36 = [
37 = 0
38 = "]"
39 = "}"
}
singlereq {
optstr = "\${list_block_resource.list.singlereq[0].optstr}"
optnum = "\${list_block_resource.list.singlereq[0].optnum}"
optbool = "\${list_block_resource.list.singlereq[0].optbool}"
reqstr = "\${list_block_resource.list.singlereq[0].reqstr}"
reqnum = "\${list_block_resource.list.singlereq[0].reqnum}"
reqbool = "\${list_block_resource.list.singlereq[0].reqbool}"
computedstr = "\${list_block_resource.list.singlereq[0].computedstr}"
computednum = "\${list_block_resource.list.singlereq[0].computednum}"
computedbool = "\${list_block_resource.list.singlereq[0].computedbool}"
}
}
resource "required_attribute_resource" "from_map" {
str = "\${lookup(map_resource.map.optMap, "key1", "missing")}"
num = "\${map_resource.map.computedMap.key1}"
bool = "\${map_resource.map.reqMap.key1}"
strList = [
"\${lookup(map_resource.map.optMap, "key1", "missing")}"
]
numList = [
$ { map_resource.map.computedMap.key1 }
]
boolList = [
$ { map_resource.map.reqMap.key1 }
]
}
resource "map_resource" "map_reference" {
optMap = "\${map_resource.map.optMap}"
reqMap = "\${map_resource.map.reqMap}"
}
resource "set_block_resource" "set_from_list" {
set = "\${list_block_resource.list.req}"
}
resource "list_block_resource" "list_from_set" {
req = "\${tolist(set_block_resource.set_block.set)}"
singlereq {
reqstr = "reqstr"
reqnum = 1
reqbool = true
}
}
output "list_from_list_type_ref" {
value = "\${list_block_resource.list.computedListOfObject}"
}
resource "optional_attribute_resource" "list_item_from_list_type_ref" {
str = "\${list_block_resource.list.computedListOfObject[5].str}"
}"
`;
20 changes: 17 additions & 3 deletions test/typescript/edge/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Copyright (c) HashiCorp, Inc
// SPDX-License-Identifier: MPL-2.0
import { QueryableStack, TestDriver, onlyJson } from "../../test-helper";
import {
QueryableStack,
TestDriver,
onlyJson,
onlyHcl,
isHcl,
} from "../../test-helper";
import * as path from "path";
import * as fs from "fs-extra";

Expand Down Expand Up @@ -31,7 +37,11 @@ describe("edge provider test", () => {
describe("ReferenceStack", () => {
let stack: QueryableStack;
beforeAll(() => {
stack = driver.synthesizedStack("reference");
stack = isHcl ? (null as any) : driver.synthesizedStack("reference");
});

onlyHcl("synth generates HCL, not JSON", () => {
expect(driver.synthesizedStackContentsRaw("reference")).toMatchSnapshot();
});

onlyJson("renders plain values in lists", () => {
Expand Down Expand Up @@ -226,7 +236,11 @@ describe("edge provider test", () => {
describe("IteratorStack", () => {
let stack: QueryableStack;
beforeAll(() => {
stack = driver.synthesizedStack("iterator");
stack = isHcl ? (null as any) : driver.synthesizedStack("iterator");
});

onlyHcl("synth generates HCL, not JSON", () => {
expect(driver.synthesizedStackContentsRaw("iterator")).toMatchSnapshot();
});

describe("string list", () => {
Expand Down
31 changes: 0 additions & 31 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2285,13 +2285,6 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.19.tgz#35e26df9ec441ab99d73e99e9aca82935eea216d"
integrity sha512-YUgMWAQBWLObABqrvx8qKO1enAvBUdjZOAWQ5grBAkp5LQv45jBvYKZ3oFS9iKRCQyFjqw6iuEa1vmFqtxYLZw==

"@types/[email protected]":
version "18.19.17"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.17.tgz#a581a9fb4b2cfdbc61f008804f4436b2d5c40354"
integrity sha512-SzyGKgwPzuWp2SHhlpXKzCX0pIOfcI4V2eF37nNBJOhwlegQ83omtVQ1XxZpDE06V/d6AQvfQdPfnw0tRC//Ng==
dependencies:
undici-types "~5.26.4"

"@types/[email protected]":
version "18.19.18"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.18.tgz#7526471b28828d1fef1f7e4960fb9477e6e4369c"
Expand Down Expand Up @@ -2376,11 +2369,6 @@
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.8.tgz#ce5ace04cfeabe7ef87c0091e50752e36707deff"
integrity sha512-WZLiwShhwLRmeV6zH+GkbOFT6Z6VklCItrDioxUnv+u4Ll+8vKeFySoFyK/0ctcRpOmwAicELfmys1sDc/Rw+A==

"@types/[email protected]":
version "7.5.7"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.7.tgz#326f5fdda70d13580777bcaa1bc6fa772a5aef0e"
integrity sha512-/wdoPq1QqkSj9/QOeKkFquEuPzQbHTWAMPH/PaUMB+JuR31lXhlWXRZ52IpfDYVlDOUBvX09uBrPwxGT1hjNBg==

"@types/[email protected]":
version "7.5.8"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.8.tgz#8268a8c57a3e4abd25c165ecd36237db7948a55e"
Expand Down Expand Up @@ -7858,25 +7846,6 @@ [email protected]:
typescript "~3.9.10"
yargs "^16.2.0"

[email protected]:
version "5.3.19"
resolved "https://registry.yarnpkg.com/jsii/-/jsii-5.3.19.tgz#ed4f063ee4ee89cffe9ee0cb36a99a4b310eaf4c"
integrity sha512-rc8kkEvnthCG0DS1TK+NY+cl+fkH+OJ4FHCs6o3a8sO2zekMOYb09uJDVHHbxBMlIJXuNKhpp+UYehVnHFkmIA==
dependencies:
"@jsii/check-node" "1.94.0"
"@jsii/spec" "^1.94.0"
case "^1.6.3"
chalk "^4"
downlevel-dts "^0.11.0"
fast-deep-equal "^3.1.3"
log4js "^6.9.1"
semver "^7.6.0"
semver-intersect "^1.5.0"
sort-json "^2.0.1"
spdx-license-list "^6.8.0"
typescript "~5.3"
yargs "^17.7.2"

[email protected]:
version "5.3.24"
resolved "https://registry.yarnpkg.com/jsii/-/jsii-5.3.24.tgz#fb84717a97b3d504cb4047fd3ff4a4ce7746e1a2"
Expand Down

0 comments on commit 11ff59b

Please sign in to comment.