generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate codebase from EC to eventing-manager
- Loading branch information
Showing
59 changed files
with
7,543 additions
and
192 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,50 @@ | ||
package errors | ||
|
||
import "golang.org/x/xerrors" | ||
|
||
// skippable is an interface of error types that can be skipped. | ||
type skippable interface { | ||
skip() | ||
} | ||
|
||
// IsSkippable returns true if the error is skippable, otherwise returns false. | ||
func IsSkippable(err error) bool { | ||
if err == nil { | ||
return true | ||
} | ||
_, ok := err.(skippable) | ||
return ok | ||
} | ||
|
||
// skippableError is an implementation of a skippable reconcile error. | ||
type skippableError struct { | ||
err error | ||
} | ||
|
||
var ( | ||
// Perform compile-time checks. | ||
_ error = &skippableError{} | ||
_ skippable = &skippableError{} | ||
_ xerrors.Wrapper = &skippableError{} | ||
) | ||
|
||
// NewSkippable returns a new skippable error. | ||
func NewSkippable(err error) error { | ||
return &skippableError{err: err} | ||
} | ||
|
||
// Error implements the error interface. | ||
func (e *skippableError) Error() string { | ||
if e.err == nil { | ||
return "" | ||
} | ||
return e.err.Error() | ||
} | ||
|
||
// skip implements the skippable interface. | ||
func (*skippableError) skip() {} | ||
|
||
// Unwrap implements the Wrapper interface. | ||
func (e *skippableError) Unwrap() error { | ||
return e.err | ||
} |
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,68 @@ | ||
package errors_test | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
ctrlserrors "github.com/kyma-project/eventing-manager/internal/controller/errors" | ||
) | ||
|
||
func Test_NewSkippable(t *testing.T) { | ||
testCases := []struct { | ||
error error | ||
}{ | ||
{error: ctrlserrors.NewSkippable(nil)}, | ||
{error: ctrlserrors.NewSkippable(ctrlserrors.NewSkippable(nil))}, | ||
{error: ctrlserrors.NewSkippable(fmt.Errorf("some error"))}, | ||
{error: ctrlserrors.NewSkippable(ctrlserrors.NewSkippable(fmt.Errorf("some error")))}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
skippableErr := ctrlserrors.NewSkippable(tc.error) | ||
if skippableErr == nil { | ||
t.Errorf("test NewSkippable retuned nil error") | ||
continue | ||
} | ||
if err := errors.Unwrap(skippableErr); tc.error != err { | ||
t.Errorf("test NewSkippable failed, want: %#v but got: %#v", tc.error, err) | ||
} | ||
} | ||
} | ||
|
||
func Test_IsSkippable(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
givenError error | ||
wantSkippable bool | ||
}{ | ||
{ | ||
name: "nil error, should be skipped", | ||
givenError: nil, | ||
wantSkippable: true, | ||
}, | ||
{ | ||
name: "skippable error, should be skipped", | ||
givenError: ctrlserrors.NewSkippable(fmt.Errorf("some errore")), | ||
wantSkippable: true, | ||
}, | ||
{ | ||
name: "not-skippable error, should not be skipped", | ||
givenError: fmt.Errorf("some error"), | ||
wantSkippable: false, | ||
}, | ||
{ | ||
name: "not-skippable error which wraps a skippable error, should not be skipped", | ||
givenError: fmt.Errorf("some error %w", ctrlserrors.NewSkippable(fmt.Errorf("some error"))), | ||
wantSkippable: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
if gotSkippable := ctrlserrors.IsSkippable(tc.givenError); tc.wantSkippable != gotSkippable { | ||
t.Errorf("test skippable failed, want: %v but got: %v", tc.wantSkippable, gotSkippable) | ||
} | ||
}) | ||
} | ||
} |
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
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
Oops, something went wrong.