Skip to content

Commit ea5d6a9

Browse files
committed
fix: export report entri fields
1 parent 602881e commit ea5d6a9

File tree

3 files changed

+78
-71
lines changed

3 files changed

+78
-71
lines changed

diff/diff.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,21 @@ func generateReport(oldIndex, newIndex map[string]*manifest.MappingResult, newOw
100100
doDiff(&report, key, nil, newContent, options)
101101
}
102102

103-
seenAnyChanges := len(report.entries) > 0
103+
seenAnyChanges := len(report.Entries) > 0
104104

105105
report, err := doSuppress(report, options.SuppressedOutputLineRegex)
106106

107107
return seenAnyChanges, &report, err
108108
}
109109

110110
func doSuppress(report Report, suppressedOutputLineRegex []string) (Report, error) {
111-
if len(report.entries) == 0 || len(suppressedOutputLineRegex) == 0 {
111+
if len(report.Entries) == 0 || len(suppressedOutputLineRegex) == 0 {
112112
return report, nil
113113
}
114114

115115
filteredReport := Report{}
116116
filteredReport.format = report.format
117-
filteredReport.entries = []ReportEntry{}
117+
filteredReport.Entries = []ReportEntry{}
118118

119119
var suppressOutputRegexes []*regexp.Regexp
120120

@@ -127,11 +127,11 @@ func doSuppress(report Report, suppressedOutputLineRegex []string) (Report, erro
127127
suppressOutputRegexes = append(suppressOutputRegexes, regex)
128128
}
129129

130-
for _, entry := range report.entries {
130+
for _, entry := range report.Entries {
131131
var diffs []difflib.DiffRecord
132132

133133
DIFFS:
134-
for _, diff := range entry.diffs {
134+
for _, diff := range entry.Diffs {
135135
for _, suppressOutputRegex := range suppressOutputRegexes {
136136
if suppressOutputRegex.MatchString(diff.Payload) {
137137
continue DIFFS
@@ -155,11 +155,11 @@ func doSuppress(report Report, suppressedOutputLineRegex []string) (Report, erro
155155
switch {
156156
case containsDiff:
157157
diffRecords = diffs
158-
case entry.changeType == "MODIFY":
159-
entry.changeType = "MODIFY_SUPPRESSED"
158+
case entry.ChangeType == "MODIFY":
159+
entry.ChangeType = "MODIFY_SUPPRESSED"
160160
}
161161

162-
filteredReport.addEntry(entry.key, entry.suppressedKinds, entry.kind, entry.context, diffRecords, entry.changeType)
162+
filteredReport.addEntry(entry.Key, entry.SuppressedKinds, entry.Kind, entry.Context, diffRecords, entry.ChangeType)
163163
}
164164

165165
return filteredReport, nil

diff/diff_test.go

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ func TestManifests(t *testing.T) {
172172

173173
specBeta := map[string]*manifest.MappingResult{
174174
"default, nginx, Deployment (apps)": {
175-
176175
Name: "default, nginx, Deployment (apps)",
177176
Kind: "Deployment",
178177
Content: `
@@ -181,11 +180,11 @@ kind: Deployment
181180
metadata:
182181
name: nginx
183182
`,
184-
}}
183+
},
184+
}
185185

186186
specRelease := map[string]*manifest.MappingResult{
187187
"default, nginx, Deployment (apps)": {
188-
189188
Name: "default, nginx, Deployment (apps)",
190189
Kind: "Deployment",
191190
Content: `
@@ -194,11 +193,11 @@ kind: Deployment
194193
metadata:
195194
name: nginx
196195
`,
197-
}}
196+
},
197+
}
198198

199199
specReleaseSpec := map[string]*manifest.MappingResult{
200200
"default, nginx, Deployment (apps)": {
201-
202201
Name: "default, nginx, Deployment (apps)",
203202
Kind: "Deployment",
204203
Content: `
@@ -209,11 +208,11 @@ metadata:
209208
spec:
210209
replicas: 3
211210
`,
212-
}}
211+
},
212+
}
213213

214214
specReleaseRenamed := map[string]*manifest.MappingResult{
215215
"default, nginx-renamed, Deployment (apps)": {
216-
217216
Name: "default, nginx-renamed, Deployment (apps)",
218217
Kind: "Deployment",
219218
Content: `
@@ -224,11 +223,11 @@ metadata:
224223
spec:
225224
replicas: 3
226225
`,
227-
}}
226+
},
227+
}
228228

229229
specReleaseRenamedAndUpdated := map[string]*manifest.MappingResult{
230230
"default, nginx-renamed, Deployment (apps)": {
231-
232231
Name: "default, nginx-renamed, Deployment (apps)",
233232
Kind: "Deployment",
234233
Content: `
@@ -239,11 +238,11 @@ metadata:
239238
spec:
240239
replicas: 1
241240
`,
242-
}}
241+
},
242+
}
243243

244244
specReleaseRenamedAndAdded := map[string]*manifest.MappingResult{
245245
"default, nginx-renamed, Deployment (apps)": {
246-
247246
Name: "default, nginx-renamed, Deployment (apps)",
248247
Kind: "Deployment",
249248
Content: `
@@ -257,11 +256,11 @@ spec:
257256
matchLabels:
258257
app: nginx-renamed
259258
`,
260-
}}
259+
},
260+
}
261261

262262
specReleaseKeep := map[string]*manifest.MappingResult{
263263
"default, nginx, Deployment (apps)": {
264-
265264
Name: "default, nginx, Deployment (apps)",
266265
Kind: "Deployment",
267266
Content: `
@@ -273,7 +272,8 @@ annotations:
273272
helm.sh/resource-policy: keep
274273
`,
275274
ResourcePolicy: "keep",
276-
}}
275+
},
276+
}
277277

278278
t.Run("OnChange", func(t *testing.T) {
279279
var buf1 bytes.Buffer
@@ -603,7 +603,8 @@ data:
603603
key2: dmFsdWUy
604604
key3: dmFsdWUz
605605
`,
606-
}}
606+
},
607+
}
607608

608609
specSecretWithByteDataChanged := map[string]*manifest.MappingResult{
609610
"default, foobar, Secret (v1)": {
@@ -620,7 +621,8 @@ data:
620621
key2: dmFsdWUy
621622
key4: dmFsdWU0
622623
`,
623-
}}
624+
},
625+
}
624626

625627
specSecretWithStringData := map[string]*manifest.MappingResult{
626628
"default, foobar, Secret (v1)": {
@@ -637,7 +639,8 @@ stringData:
637639
key2: value2
638640
key3: value3
639641
`,
640-
}}
642+
},
643+
}
641644

642645
specSecretWithStringDataChanged := map[string]*manifest.MappingResult{
643646
"default, foobar, Secret (v1)": {
@@ -654,17 +657,18 @@ stringData:
654657
key2: value2
655658
key4: value4
656659
`,
657-
}}
660+
},
661+
}
658662

659663
t.Run("OnChangeSecretWithByteData", func(t *testing.T) {
660664
var buf1 bytes.Buffer
661-
diffOptions := Options{"diff", 10, false, false, false, []string{}, 0.5, []string{}} //NOTE: ShowSecrets = false
665+
diffOptions := Options{"diff", 10, false, false, false, []string{}, 0.5, []string{}} // NOTE: ShowSecrets = false
662666

663667
if changesSeen := Manifests(specSecretWithByteData, specSecretWithByteDataChanged, &diffOptions, &buf1); !changesSeen {
664668
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`")
665669
}
666670

667-
//TODO: Why is there no empty line between the header and the start of the diff, like in the other diffs?
671+
// TODO: Why is there no empty line between the header and the start of the diff, like in the other diffs?
668672
require.Equal(t, `default, foobar, Secret (v1) has changed:
669673
apiVersion: v1
670674
kind: Secret
@@ -683,7 +687,7 @@ stringData:
683687

684688
t.Run("OnChangeSecretWithStringData", func(t *testing.T) {
685689
var buf1 bytes.Buffer
686-
diffOptions := Options{"diff", 10, false, false, false, []string{}, 0.5, []string{}} //NOTE: ShowSecrets = false
690+
diffOptions := Options{"diff", 10, false, false, false, []string{}, 0.5, []string{}} // NOTE: ShowSecrets = false
687691

688692
if changesSeen := Manifests(specSecretWithStringData, specSecretWithStringDataChanged, &diffOptions, &buf1); !changesSeen {
689693
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`")
@@ -722,53 +726,53 @@ func TestDoSuppress(t *testing.T) {
722726
{
723727
name: "simple",
724728
input: Report{
725-
entries: []ReportEntry{
729+
Entries: []ReportEntry{
726730
{
727-
diffs: diffStrings("hello: world", "hello: world2", false),
731+
Diffs: diffStrings("hello: world", "hello: world2", false),
728732
},
729733
},
730734
},
731735
supressRegex: []string{},
732736
expected: Report{
733-
entries: []ReportEntry{
737+
Entries: []ReportEntry{
734738
{
735-
diffs: diffStrings("hello: world", "hello: world2", false),
739+
Diffs: diffStrings("hello: world", "hello: world2", false),
736740
},
737741
},
738742
},
739743
},
740744
{
741745
name: "ignore all",
742746
input: Report{
743-
entries: []ReportEntry{
747+
Entries: []ReportEntry{
744748
{
745-
diffs: diffStrings("hello: world", "hello: world2", false),
749+
Diffs: diffStrings("hello: world", "hello: world2", false),
746750
},
747751
},
748752
},
749753
supressRegex: []string{".*world2?"},
750754
expected: Report{
751-
entries: []ReportEntry{
755+
Entries: []ReportEntry{
752756
{
753-
diffs: []difflib.DiffRecord{},
757+
Diffs: []difflib.DiffRecord{},
754758
},
755759
},
756760
},
757761
},
758762
{
759763
name: "ignore partial",
760764
input: Report{
761-
entries: []ReportEntry{
765+
Entries: []ReportEntry{
762766
{
763-
diffs: diffStrings("hello: world", "hello: world2", false),
767+
Diffs: diffStrings("hello: world", "hello: world2", false),
764768
},
765769
},
766770
},
767771
supressRegex: []string{".*world2"},
768772
expected: Report{
769-
entries: []ReportEntry{
773+
Entries: []ReportEntry{
770774
{
771-
diffs: []difflib.DiffRecord{
775+
Diffs: []difflib.DiffRecord{
772776
{
773777
Payload: "hello: world",
774778
Delta: difflib.LeftOnly,
@@ -803,11 +807,12 @@ metadata:
803807
data:
804808
key1: value1
805809
`,
806-
}}
810+
},
811+
}
807812

808813
t.Run("OnChangeOwnershipWithoutSpecChange", func(t *testing.T) {
809814
var buf1 bytes.Buffer
810-
diffOptions := Options{"diff", 10, false, true, false, []string{}, 0.5, []string{}} //NOTE: ShowSecrets = false
815+
diffOptions := Options{"diff", 10, false, true, false, []string{}, 0.5, []string{}} // NOTE: ShowSecrets = false
811816

812817
newOwnedReleases := map[string]OwnershipDiff{
813818
"default, foobar, ConfigMap (v1)": {
@@ -827,7 +832,7 @@ data:
827832

828833
t.Run("OnChangeOwnershipWithSpecChange", func(t *testing.T) {
829834
var buf1 bytes.Buffer
830-
diffOptions := Options{"diff", 10, false, true, false, []string{}, 0.5, []string{}} //NOTE: ShowSecrets = false
835+
diffOptions := Options{"diff", 10, false, true, false, []string{}, 0.5, []string{}} // NOTE: ShowSecrets = false
831836

832837
specNew := map[string]*manifest.MappingResult{
833838
"default, foobar, ConfigMap (v1)": {
@@ -841,7 +846,8 @@ metadata:
841846
data:
842847
key1: newValue1
843848
`,
844-
}}
849+
},
850+
}
845851

846852
newOwnedReleases := map[string]OwnershipDiff{
847853
"default, foobar, ConfigMap (v1)": {
@@ -869,6 +875,7 @@ default, foobar, ConfigMap (v1) has changed:
869875
`, buf1.String())
870876
})
871877
}
878+
872879
func TestDecodeSecrets(t *testing.T) {
873880
ansi.DisableColors(true)
874881

0 commit comments

Comments
 (0)