Skip to content

Commit

Permalink
fix: markdown multiline wrapping caused to break formatting (#82) (#83)
Browse files Browse the repository at this point in the history
wobondar authored Nov 30, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent eac0f29 commit c0cac23
Showing 2 changed files with 39 additions and 15 deletions.
2 changes: 2 additions & 0 deletions writer/table.go
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ func (t TableWriter) Write(writer io.Writer) error {
table := tablewriter.NewWriter(writer)
table.SetHeader([]string{"Change", "Resource"})
table.SetAutoMergeCells(true)
table.SetAutoWrapText(false)
table.AppendBulk(tableString)

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

if t.mdEnabled {
52 changes: 37 additions & 15 deletions writer/table_test.go
Original file line number Diff line number Diff line change
@@ -6,14 +6,28 @@ import (

"github.com/dineshba/tf-summarize/terraformstate"
"github.com/stretchr/testify/assert"

. "github.com/hashicorp/terraform-json"
)

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

changes["update"] = terraformstate.ResourceChanges{
{
Address: "aws_instance.example3",
Change: &Change{Actions: Actions{ActionUpdate}},
},
{
Address: "aws_instance.example4.tag[\"Custom Instance Tag\"]",
Change: &Change{Actions: Actions{ActionUpdate}},
},
}

outputChanges := map[string][]string{
"update": {
"output.example",
"output.long_resource_name.this[\"Custom/Resource Name\"]",
},
}

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

expectedOutput := `+--------+-----------------------+
| CHANGE | RESOURCE |
+--------+-----------------------+
| add | aws_instance.example1 |
+--------+-----------------------+
| delete | aws_instance.example2 |
+--------+-----------------------+
+--------+----------------+
| CHANGE | OUTPUT |
+--------+----------------+
| update | output.example |
+--------+----------------+
expectedOutput := `+--------+--------------------------------------------------+
| CHANGE | RESOURCE |
+--------+--------------------------------------------------+
| add | aws_instance.example1 |
+--------+--------------------------------------------------+
| update | aws_instance.example3 |
+ +--------------------------------------------------+
| | aws_instance.example4.tag["Custom Instance Tag"] |
+--------+--------------------------------------------------+
| delete | aws_instance.example2 |
+--------+--------------------------------------------------+
+--------+--------------------------------------------------------+
| CHANGE | OUTPUT |
+--------+--------------------------------------------------------+
| update | output.example |
+ +--------------------------------------------------------+
| | output.long_resource_name.this["Custom/Resource Name"] |
+--------+--------------------------------------------------------+
`

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

@@ -58,9 +79,10 @@ func TestTableWriter_Write_WithMarkdown(t *testing.T) {
| add | ` + "`aws_instance.example1`" + ` |
| delete | ` + "`aws_instance.example2`" + ` |
| CHANGE | OUTPUT |
|--------|------------------|
| update | ` + "`output.example`" + ` |
| CHANGE | OUTPUT |
|--------|----------------------------------------------------------|
| update | ` + "`output.example`" + ` |
| | ` + "`output.long_resource_name.this[\"Custom/Resource Name\"]`" + ` |
`

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

0 comments on commit c0cac23

Please sign in to comment.