Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: markdown multiline wrapping caused to break formatting (#82) #83

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions writer/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
52 changes: 37 additions & 15 deletions writer/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\"]",
},
}

Expand All @@ -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())
Expand All @@ -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\"]",
},
}

Expand All @@ -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())
Expand Down
Loading