-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix AppendingErrHandler issue causing errors not to be stored in pass…
…ed down handlers (#516) * use a pointer to allow referencing the original AppendingErrHandler when appending errors * add changelog * Add AppendingErrorHandler unit tests * Add simple pull request template * Update contrib/pkg/output/errhandlers/err_handlers.go Co-authored-by: Marco Schmidt <[email protected]> * ExpectWithOffset err_handlers_test * Update error handler list message * noop --------- Co-authored-by: Marco Schmidt <[email protected]>
- Loading branch information
1 parent
75d0d1f
commit 460ec3f
Showing
5 changed files
with
143 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Description | ||
|
||
Please include a thorough summary of the changes. | ||
|
||
This fixes ... \ This new feature can be used to ... | ||
|
||
# Context | ||
|
||
Summary of issue | ||
|
||
Description and justification of any interesting decisions made |
7 changes: 7 additions & 0 deletions
7
changelog/v0.35.0/fix-AppendErrHandler-not-appending-errors-to-original-object.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
changelog: | ||
- type: FIX | ||
issueLink: https://github.com/solo-io/skv2/issues/517 | ||
description: Fix issue where the AppendErrHandler was not appending errors to the original object. | ||
- type: BREAKING_CHANGE | ||
issueLink: https://github.com/solo-io/skv2/issues/517 | ||
description: Usages of AppendErrHandler will now need to pass it by reference (&). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package errhandlers_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestCodegen(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Error Handlers Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package errhandlers | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/pkg/errors" | ||
v1 "github.com/solo-io/skv2/codegen/test/api/things.test.io/v1" | ||
"github.com/solo-io/skv2/contrib/pkg/output" | ||
"github.com/solo-io/skv2/pkg/ezkube" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var _ = Describe("Error Handlers", func() { | ||
var ( | ||
errorHandler output.ErrorHandler | ||
fakeResource = &v1.Paint{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "fake-name", | ||
Namespace: "fake-ns", | ||
}, | ||
} | ||
) | ||
|
||
Context("AppendingErrHandler", func() { | ||
BeforeEach(func() { | ||
errorHandler = &AppendingErrHandler{} | ||
}) | ||
|
||
DescribeTable("should append errors to the error handler object", func(mutation errorMutation, expects errorExpectation) { | ||
mutation(errorHandler, fakeResource) | ||
expects(errorHandler.(*AppendingErrHandler).Errors(), fakeResource) | ||
}, | ||
Entry("when HandleListError is called", addListError, expectListError), | ||
Entry("when HandleWriteError is called", addWriteError, expectWriteError), | ||
Entry("when HandleDeleteError is called", addDeleteError, expectDeleteError), | ||
Entry("when multiple error handler functions are invoked", func(handler output.ErrorHandler, resource ezkube.Object) { | ||
addListError(handler, resource) | ||
addWriteError(handler, resource) | ||
addDeleteError(handler, resource) | ||
}, func(err error, resource ezkube.Object) { | ||
Expect(err).To(And( | ||
MatchError(ListError(err)), | ||
MatchError(ResourceWriteError(resource, err)), | ||
MatchError(ResourceDeleteError(resource, err)), | ||
)) | ||
}), | ||
) | ||
|
||
It("should not have an error when no errors occur", func() { | ||
errs := errorHandler.(*AppendingErrHandler).Errors() | ||
Expect(errs).NotTo(HaveOccurred()) | ||
}) | ||
}) | ||
}) | ||
|
||
type errorMutation func(handler output.ErrorHandler, resource ezkube.Object) | ||
|
||
func addListError(handler output.ErrorHandler, _ ezkube.Object) { | ||
handler.HandleListError(errors.New("listing resources failed")) | ||
} | ||
func addWriteError(handler output.ErrorHandler, resource ezkube.Object) { | ||
handler.HandleWriteError(resource, errors.New("writing resource failed")) | ||
} | ||
func addDeleteError(handler output.ErrorHandler, resource ezkube.Object) { | ||
handler.HandleDeleteError(resource, errors.New("deleting resource failed")) | ||
} | ||
|
||
// errorExpectation is a function that expects a specific error to occur | ||
type errorExpectation func(err error, resource ezkube.Object) | ||
|
||
func expectListError(err error, resource ezkube.Object) { | ||
ExpectWithOffset(1, err).To(HaveOccurred()) | ||
ExpectWithOffset(1, err).To(And( | ||
MatchError(ListError(err)), | ||
Not(MatchError(ResourceWriteError(resource, err))), | ||
Not(MatchError(ResourceDeleteError(resource, err))), | ||
)) | ||
} | ||
func expectWriteError(err error, resource ezkube.Object) { | ||
ExpectWithOffset(1, err).To(HaveOccurred()) | ||
ExpectWithOffset(1, err).To(And( | ||
MatchError(ResourceWriteError(resource, err)), | ||
Not(MatchError(ListError(err))), | ||
Not(MatchError(ResourceDeleteError(resource, err))), | ||
)) | ||
} | ||
func expectDeleteError(err error, resource ezkube.Object) { | ||
ExpectWithOffset(1, err).To(HaveOccurred()) | ||
ExpectWithOffset(1, err).To(And( | ||
MatchError(ResourceDeleteError(resource, err)), | ||
Not(MatchError(ListError(err))), | ||
Not(MatchError(ResourceWriteError(resource, err))), | ||
)) | ||
} |