-
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 (#520) * error handler fix * rename changelog/version name
- Loading branch information
Showing
4 changed files
with
129 additions
and
8 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
changelog/v0.29.12-portal/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,4 @@ | ||
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. |
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))), | ||
)) | ||
} |