Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dineshba/tf-summarize
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.3.13
Choose a base ref
...
head repository: dineshba/tf-summarize
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.3.14
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Nov 30, 2024

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

    wobondar authored Nov 30, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    c0cac23 View commit details
Showing with 39 additions and 15 deletions.
  1. +2 −0 writer/table.go
  2. +37 −15 writer/table_test.go
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())