Skip to content

Commit 82544b3

Browse files
committed
A method to return a slice of pointers to encountered errors
Signed-off-by: ZIV NEVO <[email protected]>
1 parent dc43a66 commit 82544b3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pkg/analyzer/policies_synthesizer.go

+10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ func (ps *PoliciesSynthesizer) Errors() []FileProcessingError {
9595
return ps.errors
9696
}
9797

98+
// ErrorPtrs returns a slice of pointers to FileProcessingError with all warnings and errors encountered during processing.
99+
// Might be easier to use than Errors() if the returned slice is to be used as a slice of interfaces.
100+
func (ps *PoliciesSynthesizer) ErrorPtrs() []*FileProcessingError {
101+
ret := make([]*FileProcessingError, len(ps.errors))
102+
for idx := range ps.errors {
103+
ret[idx] = &ps.errors[idx]
104+
}
105+
return ret
106+
}
107+
98108
// PoliciesFromInfos returns a slice of Kubernetes NetworkPolicies that allow only the connections discovered
99109
// while processing K8s resources in the given slice of Info objects.
100110
func (ps *PoliciesSynthesizer) PoliciesFromInfos(infos []*resource.Info) ([]*networking.NetworkPolicy, error) {

pkg/analyzer/policies_synthesizer_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ func TestPoliciesSynthesizerAPIFailFast(t *testing.T) {
153153
require.Len(t, synthesizer.Errors(), 1)
154154
badYaml := &FailedReadingFileError{}
155155
require.True(t, errors.As(synthesizer.Errors()[0].Error(), &badYaml))
156+
require.Len(t, synthesizer.ErrorPtrs(), 1)
157+
require.True(t, errors.As(synthesizer.ErrorPtrs()[0].Error(), &badYaml))
156158
require.Empty(t, netpols)
157159
}
158160

0 commit comments

Comments
 (0)