Skip to content

Commit c0cac23

Browse files
authored
fix: markdown multiline wrapping caused to break formatting (#82) (#83)
1 parent eac0f29 commit c0cac23

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

writer/table.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (t TableWriter) Write(writer io.Writer) error {
3232
table := tablewriter.NewWriter(writer)
3333
table.SetHeader([]string{"Change", "Resource"})
3434
table.SetAutoMergeCells(true)
35+
table.SetAutoWrapText(false)
3536
table.AppendBulk(tableString)
3637

3738
if t.mdEnabled {
@@ -59,6 +60,7 @@ func (t TableWriter) Write(writer io.Writer) error {
5960
table = tablewriter.NewWriter(writer)
6061
table.SetHeader([]string{"Change", "Output"})
6162
table.SetAutoMergeCells(true)
63+
table.SetAutoWrapText(false)
6264
table.AppendBulk(tableString)
6365

6466
if t.mdEnabled {

writer/table_test.go

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,28 @@ import (
66

77
"github.com/dineshba/tf-summarize/terraformstate"
88
"github.com/stretchr/testify/assert"
9+
10+
. "github.com/hashicorp/terraform-json"
911
)
1012

1113
func TestTableWriter_Write_NoMarkdown(t *testing.T) {
1214
changes := createMockChanges()
1315

16+
changes["update"] = terraformstate.ResourceChanges{
17+
{
18+
Address: "aws_instance.example3",
19+
Change: &Change{Actions: Actions{ActionUpdate}},
20+
},
21+
{
22+
Address: "aws_instance.example4.tag[\"Custom Instance Tag\"]",
23+
Change: &Change{Actions: Actions{ActionUpdate}},
24+
},
25+
}
26+
1427
outputChanges := map[string][]string{
1528
"update": {
1629
"output.example",
30+
"output.long_resource_name.this[\"Custom/Resource Name\"]",
1731
},
1832
}
1933

@@ -22,18 +36,24 @@ func TestTableWriter_Write_NoMarkdown(t *testing.T) {
2236
err := tw.Write(&output)
2337
assert.NoError(t, err)
2438

25-
expectedOutput := `+--------+-----------------------+
26-
| CHANGE | RESOURCE |
27-
+--------+-----------------------+
28-
| add | aws_instance.example1 |
29-
+--------+-----------------------+
30-
| delete | aws_instance.example2 |
31-
+--------+-----------------------+
32-
+--------+----------------+
33-
| CHANGE | OUTPUT |
34-
+--------+----------------+
35-
| update | output.example |
36-
+--------+----------------+
39+
expectedOutput := `+--------+--------------------------------------------------+
40+
| CHANGE | RESOURCE |
41+
+--------+--------------------------------------------------+
42+
| add | aws_instance.example1 |
43+
+--------+--------------------------------------------------+
44+
| update | aws_instance.example3 |
45+
+ +--------------------------------------------------+
46+
| | aws_instance.example4.tag["Custom Instance Tag"] |
47+
+--------+--------------------------------------------------+
48+
| delete | aws_instance.example2 |
49+
+--------+--------------------------------------------------+
50+
+--------+--------------------------------------------------------+
51+
| CHANGE | OUTPUT |
52+
+--------+--------------------------------------------------------+
53+
| update | output.example |
54+
+ +--------------------------------------------------------+
55+
| | output.long_resource_name.this["Custom/Resource Name"] |
56+
+--------+--------------------------------------------------------+
3757
`
3858

3959
assert.Equal(t, expectedOutput, output.String())
@@ -45,6 +65,7 @@ func TestTableWriter_Write_WithMarkdown(t *testing.T) {
4565
outputChanges := map[string][]string{
4666
"update": {
4767
"output.example",
68+
"output.long_resource_name.this[\"Custom/Resource Name\"]",
4869
},
4970
}
5071

@@ -58,9 +79,10 @@ func TestTableWriter_Write_WithMarkdown(t *testing.T) {
5879
| add | ` + "`aws_instance.example1`" + ` |
5980
| delete | ` + "`aws_instance.example2`" + ` |
6081
61-
| CHANGE | OUTPUT |
62-
|--------|------------------|
63-
| update | ` + "`output.example`" + ` |
82+
| CHANGE | OUTPUT |
83+
|--------|----------------------------------------------------------|
84+
| update | ` + "`output.example`" + ` |
85+
| | ` + "`output.long_resource_name.this[\"Custom/Resource Name\"]`" + ` |
6486
`
6587

6688
assert.Equal(t, expectedOutput, output.String())

0 commit comments

Comments
 (0)