Skip to content

Commit 9126a8e

Browse files
committed
feat: change output if all diff output is suppressed
1 parent 53a039d commit 9126a8e

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

diff/diff.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ func doSuppress(report Report, suppressedOutputLineRegex []string) (Report, erro
141141
if containsDiff {
142142
filteredReport.addEntry(entry.key, entry.suppressedKinds, entry.kind, entry.context, diffs, entry.changeType)
143143
} else {
144-
filteredReport.addEntry(entry.key, entry.suppressedKinds, entry.kind, entry.context, []difflib.DiffRecord{}, entry.changeType)
144+
if entry.changeType == "MODIFY" {
145+
filteredReport.addEntry(entry.key, entry.suppressedKinds, entry.kind, entry.context, []difflib.DiffRecord{}, "MODIFY_SUPPRESSED")
146+
} else {
147+
filteredReport.addEntry(entry.key, entry.suppressedKinds, entry.kind, entry.context, []difflib.DiffRecord{}, entry.changeType)
148+
}
145149
}
146150
}
147151

diff/diff_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,30 @@ annotations:
298298
var buf1 bytes.Buffer
299299
diffOptions := Options{"diff", 10, false, true, []string{}, 0.0, []string{"apiVersion"}}
300300

301-
if changesSeen := Manifests(specBeta, specRelease, &diffOptions, &buf1); !changesSeen {
301+
if changesSeen := Manifests(specBeta, specReleaseSpec, &diffOptions, &buf1); !changesSeen {
302302
t.Error("Unexpected return value from Manifests: Expected the return value to be `true` to indicate that it has seen any change(s), but was `false`")
303303
}
304304

305305
require.Equal(t, `default, nginx, Deployment (apps) has changed:
306+
307+
kind: Deployment
308+
metadata:
309+
name: nginx
310+
+ spec:
311+
+ replicas: 3
312+
313+
`, buf1.String())
314+
})
315+
316+
t.Run("OnChangeWithSuppressAll", func(t *testing.T) {
317+
var buf1 bytes.Buffer
318+
diffOptions := Options{"diff", 10, false, true, []string{}, 0.0, []string{"apiVersion"}}
319+
320+
if changesSeen := Manifests(specBeta, specRelease, &diffOptions, &buf1); !changesSeen {
321+
t.Error("Unexpected return value from Manifests: Expected the return value to be `true` to indicate that it has seen any change(s), but was `false`")
322+
}
323+
324+
require.Equal(t, `default, nginx, Deployment (apps) has changed, but diff is empty after suppression.
306325
`, buf1.String())
307326
})
308327

diff/report.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ func setupDiffReport(r *Report) {
144144
r.format.changestyles["REMOVE"] = ChangeStyle{color: "red", message: "has been removed:"}
145145
r.format.changestyles["MODIFY"] = ChangeStyle{color: "yellow", message: "has changed:"}
146146
r.format.changestyles["OWNERSHIP"] = ChangeStyle{color: "magenta", message: "changed ownership:"}
147+
r.format.changestyles["MODIFY_SUPPRESSED"] = ChangeStyle{color: "gray", message: "has changed, but diff is empty after suppression."}
147148
}
148149

149150
// print report for default output: diff
@@ -162,15 +163,17 @@ func setupSimpleReport(r *Report) {
162163
r.format.changestyles["REMOVE"] = ChangeStyle{color: "red", message: "to be removed."}
163164
r.format.changestyles["MODIFY"] = ChangeStyle{color: "yellow", message: "to be changed."}
164165
r.format.changestyles["OWNERSHIP"] = ChangeStyle{color: "magenta", message: "to change ownership."}
166+
r.format.changestyles["MODIFY_SUPPRESSED"] = ChangeStyle{color: "gray", message: "has changed, but diff is empty after suppression."}
165167
}
166168

167169
// print report for simple output
168170
func printSimpleReport(r *Report, to io.Writer) {
169171
var summary = map[string]int{
170-
"ADD": 0,
171-
"REMOVE": 0,
172-
"MODIFY": 0,
173-
"OWNERSHIP": 0,
172+
"ADD": 0,
173+
"REMOVE": 0,
174+
"MODIFY": 0,
175+
"OWNERSHIP": 0,
176+
"MODIFY_SUPPRESSED": 0,
174177
}
175178
for _, entry := range r.entries {
176179
_, _ = fmt.Fprintf(to, ansi.Color("%s %s", r.format.changestyles[entry.changeType].color)+"\n",
@@ -206,6 +209,7 @@ func setupJSONReport(r *Report) {
206209
r.format.changestyles["REMOVE"] = ChangeStyle{color: "red", message: ""}
207210
r.format.changestyles["MODIFY"] = ChangeStyle{color: "yellow", message: ""}
208211
r.format.changestyles["OWNERSHIP"] = ChangeStyle{color: "magenta", message: ""}
212+
r.format.changestyles["MODIFY_SUPPRESSED"] = ChangeStyle{color: "gray", message: ""}
209213
}
210214

211215
// setup report for template output
@@ -237,6 +241,7 @@ func setupTemplateReport(r *Report) {
237241
r.format.changestyles["REMOVE"] = ChangeStyle{color: "red", message: ""}
238242
r.format.changestyles["MODIFY"] = ChangeStyle{color: "yellow", message: ""}
239243
r.format.changestyles["OWNERSHIP"] = ChangeStyle{color: "magenta", message: ""}
244+
r.format.changestyles["MODIFY_SUPPRESSED"] = ChangeStyle{color: "gray", message: ""}
240245
}
241246

242247
// report with template output will only have access to ReportTemplateSpec.

0 commit comments

Comments
 (0)