From 7d0248dd596a063428d20959631867451cc84064 Mon Sep 17 00:00:00 2001 From: wobondar Date: Fri, 29 Nov 2024 20:23:39 +0000 Subject: [PATCH] fix: markdown multiline wrapping caused to break formatting (#82) --- writer/table.go | 2 ++ writer/table_test.go | 52 +++++++++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/writer/table.go b/writer/table.go index 33c2b0d..8179a90 100644 --- a/writer/table.go +++ b/writer/table.go @@ -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 { diff --git a/writer/table_test.go b/writer/table_test.go index d975d9f..65043d7 100644 --- a/writer/table_test.go +++ b/writer/table_test.go @@ -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())