Skip to content

Commit ac50438

Browse files
authored
85: Add resouce count to change summary (#91)
* 85: Add resouce count to change summary Update for issue #85 to add the number of changed resources or outputs to the summary reports. Signed-off-by: Tyler Fitch <github@tfitch.com> * 85: Test fixes following merge from main The testing changed in a recent commit and this gets the resource count validation to be in place with the new formatting validation. Signed-off-by: Tyler Fitch <github@tfitch.com> --------- Signed-off-by: Tyler Fitch <github@tfitch.com>
1 parent 4732eb4 commit ac50438

File tree

7 files changed

+53
-51
lines changed

7 files changed

+53
-51
lines changed

testdata/basic.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<th>RESOURCE</th>
55
</tr>
66
<tr>
7-
<td>add</td>
7+
<td>add (7)</td>
88
<td>
99
<ul>
1010
<li><code>github_repository.terraform_plan_summary</code></li>
@@ -24,7 +24,7 @@
2424
<th>OUTPUT</th>
2525
</tr>
2626
<tr>
27-
<td>add</td>
27+
<td>add (1)</td>
2828
<td>
2929
<ul>
3030
<li><code>terraform_plan_summary_repository_name</code></li>

testdata/basic.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
| CHANGE | RESOURCE |
2-
|--------|------------------------------------------------------------------------|
3-
| add | `github_repository.terraform_plan_summary` |
4-
| | `module.github["demo-repository"].github_branch.development` |
5-
| | `module.github["demo-repository"].github_branch.main` |
6-
| | `module.github["demo-repository"].github_repository.repository` |
7-
| | `module.github["terraform-plan-summary"].github_branch.development` |
8-
| | `module.github["terraform-plan-summary"].github_branch.main` |
9-
| | `module.github["terraform-plan-summary"].github_repository.repository` |
1+
| CHANGE | RESOURCE |
2+
|---------|------------------------------------------------------------------------|
3+
| add (7) | `github_repository.terraform_plan_summary` |
4+
| | `module.github["demo-repository"].github_branch.development` |
5+
| | `module.github["demo-repository"].github_branch.main` |
6+
| | `module.github["demo-repository"].github_repository.repository` |
7+
| | `module.github["terraform-plan-summary"].github_branch.development` |
8+
| | `module.github["terraform-plan-summary"].github_branch.main` |
9+
| | `module.github["terraform-plan-summary"].github_repository.repository` |
1010

11-
| CHANGE | OUTPUT |
12-
|--------|------------------------------------------|
13-
| add | `terraform_plan_summary_repository_name` |
11+
| CHANGE | OUTPUT |
12+
|---------|------------------------------------------|
13+
| add (1) | `terraform_plan_summary_repository_name` |

writer/html_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestHTMLWriter(t *testing.T) {
5252
<th>RESOURCE</th>
5353
</tr>
5454
<tr>
55-
<td>update</td>
55+
<td>update (1)</td>
5656
<td>
5757
<ul>
5858
<li><code>aws_instance.example</code></li>
@@ -74,7 +74,7 @@ func TestHTMLWriter(t *testing.T) {
7474
<th>OUTPUT</th>
7575
</tr>
7676
<tr>
77-
<td>output_key</td>
77+
<td>output_key (1)</td>
7878
<td>
7979
<ul>
8080
<li><code>output_value</code></li>

writer/table.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ func (t TableWriter) Write(writer io.Writer) error {
2222

2323
for _, change := range tableOrder {
2424
changedResources := t.changes[change]
25+
resourceCount := len(changedResources)
2526

2627
for _, changedResource := range changedResources {
2728
if t.mdEnabled {
28-
tableString = append(tableString, []string{change, fmt.Sprintf("`%s`", changedResource.Address)})
29+
tableString = append(tableString, []string{fmt.Sprintf("%s (%d)", change, resourceCount), fmt.Sprintf("`%s`", changedResource.Address)})
2930
} else {
30-
tableString = append(tableString, []string{change, changedResource.Address})
31+
tableString = append(tableString, []string{fmt.Sprintf("%s (%d)", change, resourceCount), changedResource.Address})
3132
}
3233
}
3334
}
@@ -62,11 +63,12 @@ func (t TableWriter) Write(writer io.Writer) error {
6263
tableString = make([][]string, 0, 4)
6364
for _, change := range tableOrder {
6465
changedOutputs := t.outputChanges[change]
66+
outputCount := len(changedOutputs)
6567
for _, changedOutput := range changedOutputs {
6668
if t.mdEnabled {
67-
tableString = append(tableString, []string{change, fmt.Sprintf("`%s`", changedOutput)})
69+
tableString = append(tableString, []string{fmt.Sprintf("%s (%d)", change, outputCount), fmt.Sprintf("`%s`", changedOutput)})
6870
} else {
69-
tableString = append(tableString, []string{change, changedOutput})
71+
tableString = append(tableString, []string{fmt.Sprintf("%s (%d)", change, outputCount), changedOutput})
7072
}
7173
}
7274
}

writer/table_test.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,26 @@ func TestTableWriter_Write_NoMarkdown(t *testing.T) {
4646
err := tw.Write(&output)
4747
assert.NoError(t, err)
4848

49-
expectedOutput := `+--------+--------------------------------------------------+
50-
| CHANGE | RESOURCE |
51-
+--------+--------------------------------------------------+
52-
| add | aws_instance.example1 |
53-
+--------+--------------------------------------------------+
54-
| update | aws_instance.example3 |
55-
+ +--------------------------------------------------+
56-
| | aws_instance.example4.tag["Custom Instance Tag"] |
57-
+--------+--------------------------------------------------+
58-
| delete | aws_instance.example2 |
59-
+--------+--------------------------------------------------+
60-
| moved | aws_instance.old to aws_instance.new |
61-
+--------+--------------------------------------------------+
62-
+--------+--------------------------------------------------------+
63-
| CHANGE | OUTPUT |
64-
+--------+--------------------------------------------------------+
65-
| update | output.example |
66-
+ +--------------------------------------------------------+
67-
| | output.long_resource_name.this["Custom/Resource Name"] |
68-
+--------+--------------------------------------------------------+
49+
expectedOutput := `+------------+--------------------------------------------------+
50+
| CHANGE | RESOURCE |
51+
+------------+--------------------------------------------------+
52+
| add (1) | aws_instance.example1 |
53+
+------------+--------------------------------------------------+
54+
| update (2) | aws_instance.example3 |
55+
+ +--------------------------------------------------+
56+
| | aws_instance.example4.tag["Custom Instance Tag"] |
57+
+------------+--------------------------------------------------+
58+
| delete (1) | aws_instance.example2 |
59+
+------------+--------------------------------------------------+
60+
| moved | aws_instance.old to aws_instance.new |
61+
+------------+--------------------------------------------------+
62+
+------------+--------------------------------------------------------+
63+
| CHANGE | OUTPUT |
64+
+------------+--------------------------------------------------------+
65+
| update (2) | output.example |
66+
+ +--------------------------------------------------------+
67+
| | output.long_resource_name.this["Custom/Resource Name"] |
68+
+------------+--------------------------------------------------------+
6969
`
7070

7171
assert.Equal(t, expectedOutput, output.String())
@@ -96,16 +96,16 @@ func TestTableWriter_Write_WithMarkdown(t *testing.T) {
9696
err := tw.Write(&output)
9797
assert.NoError(t, err)
9898

99-
expectedOutput := `| CHANGE | RESOURCE |
100-
|--------|------------------------------------------|
101-
| add | ` + "`aws_instance.example1`" + ` |
102-
| delete | ` + "`aws_instance.example2`" + ` |
103-
| moved | ` + "`aws_instance.old` to `aws_instance.new`" + ` |
99+
expectedOutput := `| CHANGE | RESOURCE |
100+
|------------|------------------------------------------|
101+
| add (1) | ` + "`aws_instance.example1`" + ` |
102+
| delete (1) | ` + "`aws_instance.example2`" + ` |
103+
| moved | ` + "`aws_instance.old` to `aws_instance.new`" + ` |
104104
105-
| CHANGE | OUTPUT |
106-
|--------|----------------------------------------------------------|
107-
| update | ` + "`output.example`" + ` |
108-
| | ` + "`output.long_resource_name.this[\"Custom/Resource Name\"]`" + ` |
105+
| CHANGE | OUTPUT |
106+
|------------|----------------------------------------------------------|
107+
| update (2) | ` + "`output.example`" + ` |
108+
| | ` + "`output.long_resource_name.this[\"Custom/Resource Name\"]`" + ` |
109109
`
110110

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

writer/templates/outputChanges.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<th>OUTPUT</th>
55
</tr>{{ range $change, $outputs := .OutputChanges }}{{ $length := len $outputs }}{{ if gt $length 0 }}
66
<tr>
7-
<td>{{ $change }}</td>
7+
<td>{{ $change }} ({{ len $outputs }})</td>
88
<td>
99
<ul>{{ range $i, $o := $outputs }}
1010
<li><code>{{ $o }}</code></li>{{ end }}

writer/templates/resourceChanges.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<th>RESOURCE</th>
55
</tr>{{ range $change, $resources := .ResourceChanges }}{{ $length := len $resources }}{{ if gt $length 0 }}
66
<tr>
7-
<td>{{ $change }}</td>
7+
<td>{{ $change }} ({{ len $resources }})</td>
88
<td>
99
<ul>{{ range $i, $r := $resources }}{{ if eq $change "moved" }}
1010
<li><code>{{ $r.PreviousAddress }}</code> to <code>{{ $r.Address }}</code></li>{{ else }}

0 commit comments

Comments
 (0)