Skip to content

Commit

Permalink
Merge pull request #6 from reproio/support-code-fence-in-code-fence
Browse files Browse the repository at this point in the history
support code block in code block
  • Loading branch information
takaishi authored Sep 5, 2022
2 parents 09b74e0 + bd86137 commit 4453160
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 30 deletions.
3 changes: 1 addition & 2 deletions internal/terraform/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ func (r ResourceChangeData) HeaderSuffix() string {
func (plan *PlanData) Render(w io.Writer) error {
funcMap := template.FuncMap{
"codeFence": func() string {
return "```"
return "````````"
},
}

planTemplate, err := template.New("plan").Funcs(funcMap).Parse(planTemplateBody)
if err != nil {
return fmt.Errorf("invalid template text: %w", err)
Expand Down
1 change: 1 addition & 0 deletions internal/terraform/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func Test_render(t *testing.T) {
{name: "all_types_mixed", wantErr: false},
{name: "aws_sample", wantErr: false},
{name: "iam_policy", wantErr: false},
{name: "include_code_fence", wantErr: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
16 changes: 8 additions & 8 deletions test/testdata/all_types_mixed/expected.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- random_id.test4
<details><summary>Change details</summary>

```diff
````````diff
# env_variable.test2 will be updated in-place
@@ -1,5 +1,5 @@
{
Expand All @@ -18,9 +18,9 @@
+ "name": "test2_changed",
"value": ""
}
```
````````

```diff
````````diff
# env_variable.test3 will be destroyed
@@ -1,5 +1 @@
-{
Expand All @@ -29,18 +29,18 @@
- "value": ""
-}
+null
```
````````

```diff
````````diff
# env_variable.test5 will be created
@@ -1 +1,3 @@
-null
+{
+ "name": "test5"
+}
```
````````

```diff
````````diff
# random_id.test4 will be replaced
@@ -1,10 +1,5 @@
{
Expand All @@ -54,6 +54,6 @@
"keepers": null,
"prefix": null
}
```
````````

</details>
20 changes: 10 additions & 10 deletions test/testdata/aws_sample/expected.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- aws_security_group.admin
<details><summary>Change details</summary>

```diff
````````diff
# aws_instance.test will be destroyed
@@ -1,92 +1 @@
-{
Expand Down Expand Up @@ -106,9 +106,9 @@
- ]
-}
+null
```
````````

```diff
````````diff
# aws_route_table.public-route will be created
@@ -1 +1,22 @@
-null
Expand All @@ -134,19 +134,19 @@
+ "timeouts": null,
+ "vpc_id": "vpc-0c08ee65bf93a360f"
+}
```
````````

```diff
````````diff
# aws_route_table_association.puclic-a will be created
@@ -1 +1,4 @@
-null
+{
+ "gateway_id": null,
+ "subnet_id": "subnet-0342dca4d2a611266"
+}
```
````````

```diff
````````diff
# aws_security_group.admin will be replaced
@@ -1,6 +1,5 @@
{
Expand Down Expand Up @@ -177,9 +177,9 @@
"timeouts": null,
"vpc_id": "vpc-0c08ee65bf93a360f"
}
```
````````

```diff
````````diff
# aws_subnet.public-a will be updated in-place
@@ -18,10 +18,10 @@
"owner_id": "999999999999",
Expand All @@ -194,6 +194,6 @@
},
"timeouts": null,
"vpc_id": "vpc-0c08ee65bf93a360f"
```
````````

</details>
4 changes: 2 additions & 2 deletions test/testdata/iam_policy/expected.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- aws_iam_policy.test_policy
<details><summary>Change details</summary>

```diff
````````diff
# aws_iam_policy.test_policy will be updated in-place
@@ -12,7 +12,8 @@
"Action": [
Expand All @@ -15,6 +15,6 @@
],
"Resource": "*"
}
```
````````

</details>
19 changes: 19 additions & 0 deletions test/testdata/include_code_fence/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### 0 to add, 1 to change, 0 to destroy, 0 to replace.
- change
- env_variable.test1
<details><summary>Change details</summary>

````````diff
# env_variable.test1 will be updated in-place
@@ -7,7 +7,7 @@
",
"name": "
```
- test1
+ test2
```

",
````````

</details>
22 changes: 22 additions & 0 deletions test/testdata/include_code_fence/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
terraform {
required_providers {
env = {
source = "tchupp/env"
version = "0.0.2"
}
}
}

provider "env" {
# Configuration options
}

resource "env_variable" "test1" {
name = <<EOF
```
test2
```
EOF
}
Binary file added test/testdata/include_code_fence/plan.txt
Binary file not shown.
1 change: 1 addition & 0 deletions test/testdata/include_code_fence/show.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"format_version":"1.0","terraform_version":"1.1.8","planned_values":{"root_module":{"resources":[{"address":"env_variable.test1","mode":"managed","type":"env_variable","name":"test1","provider_name":"registry.terraform.io/tchupp/env","schema_version":0,"values":{"id":"\n```\ntest1\n```\n\n","name":"\n```\ntest2\n```\n\n","value":""},"sensitive_values":{}}]}},"resource_changes":[{"address":"env_variable.test1","mode":"managed","type":"env_variable","name":"test1","provider_name":"registry.terraform.io/tchupp/env","change":{"actions":["update"],"before":{"id":"\n```\ntest1\n```\n\n","name":"\n```\ntest1\n```\n\n","value":""},"after":{"id":"\n```\ntest1\n```\n\n","name":"\n```\ntest2\n```\n\n","value":""},"after_unknown":{},"before_sensitive":{"value":true},"after_sensitive":{"value":true}}}],"prior_state":{"format_version":"1.0","terraform_version":"1.1.8","values":{"root_module":{"resources":[{"address":"env_variable.test1","mode":"managed","type":"env_variable","name":"test1","provider_name":"registry.terraform.io/tchupp/env","schema_version":0,"values":{"id":"\n```\ntest1\n```\n\n","name":"\n```\ntest1\n```\n\n","value":""},"sensitive_values":{}}]}}},"configuration":{"provider_config":{"env":{"name":"env","version_constraint":"0.0.2"}},"root_module":{"resources":[{"address":"env_variable.test1","mode":"managed","type":"env_variable","name":"test1","provider_config_key":"env","expressions":{"name":{"constant_value":"\n```\ntest2\n```\n\n"}},"schema_version":0}]}}}
27 changes: 27 additions & 0 deletions test/testdata/include_code_fence/terraform.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": 4,
"terraform_version": "1.1.8",
"serial": 1,
"lineage": "562fda8d-ad02-efe3-9568-b6dd139ef8f9",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "env_variable",
"name": "test1",
"provider": "provider[\"registry.terraform.io/tchupp/env\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"id": "\n```\ntest1\n```\n\n",
"name": "\n```\ntest1\n```\n\n",
"value": ""
},
"sensitive_attributes": [],
"private": "bnVsbA=="
}
]
}
]
}
4 changes: 2 additions & 2 deletions test/testdata/single_add/expected.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
- null_resource.foo
<details><summary>Change details</summary>

```diff
````````diff
# null_resource.foo will be created
@@ -1 +1,3 @@
-null
+{
+ "triggers": null
+}
```
````````

</details>
4 changes: 2 additions & 2 deletions test/testdata/single_change/expected.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- env_variable.test1
<details><summary>Change details</summary>

```diff
````````diff
# env_variable.test1 will be updated in-place
@@ -1,5 +1,5 @@
{
Expand All @@ -12,6 +12,6 @@
+ "name": "test1_changed",
"value": ""
}
```
````````

</details>
4 changes: 2 additions & 2 deletions test/testdata/single_destroy/expected.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
- null_resource.foo
<details><summary>Change details</summary>

```diff
````````diff
# null_resource.foo will be destroyed
@@ -1,4 +1 @@
-{
- "id": "7047514762471223910",
- "triggers": null
-}
+null
```
````````

</details>
4 changes: 2 additions & 2 deletions test/testdata/single_replace/expected.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- random_id.test
<details><summary>Change details</summary>

```diff
````````diff
# random_id.test will be replaced
@@ -1,10 +1,5 @@
{
Expand All @@ -17,6 +17,6 @@
"keepers": null,
"prefix": null
}
```
````````

</details>

0 comments on commit 4453160

Please sign in to comment.