Skip to content

Commit bd45ab8

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

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

diff/diff.go

+5
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,16 @@ func doSuppress(report Report, suppressedOutputLineRegex []string) (Report, erro
138138
}
139139
}
140140

141+
if !containsDiff && entry.changeType == "MODIFY" {
142+
entry.changeType = "MODIFY_SUPPRESSED"
143+
}
144+
141145
if containsDiff {
142146
filteredReport.addEntry(entry.key, entry.suppressedKinds, entry.kind, entry.context, diffs, entry.changeType)
143147
} else {
144148
filteredReport.addEntry(entry.key, entry.suppressedKinds, entry.kind, entry.context, []difflib.DiffRecord{}, entry.changeType)
145149
}
150+
146151
}
147152

148153
return filteredReport, nil

diff/diff_test.go

+20-1
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

+9-4
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)