Skip to content

Commit

Permalink
pkg webhooks: update new error functions names to IsAdmission prefix;…
Browse files Browse the repository at this point in the history
… NOT API breaking
  • Loading branch information
mihaialexandrescu committed Feb 2, 2023
1 parent c26d16e commit f9542b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions pkg/webhooks/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ func IsAdmissionCantConnect(err error) bool {
return apierrors.IsInternalError(err) && strings.Contains(err.Error(), cantConnectErrorMsg)
}

func IsCantConnectAPIServer(err error) bool {
func IsAdmissionCantConnectAPIServer(err error) bool {
return apierrors.IsInternalError(err) && strings.Contains(err.Error(), cantConnectAPIServerMsg)
}

func IsInvalidReplicationFactor(err error) bool {
return apierrors.IsInvalid(err) && strings.Contains(err.Error(), invalidReplicationFactorErrMsg)
}

func IsOutOfRangeReplicationFactor(err error) bool {
func IsAdmissionOutOfRangeReplicationFactor(err error) bool {
return apierrors.IsInvalid(err) && strings.Contains(err.Error(), outOfRangeReplicationFactorErrMsg)
}

func IsOutOfRangePartitions(err error) bool {
func IsAdmissionOutOfRangePartitions(err error) bool {
return apierrors.IsInvalid(err) && strings.Contains(err.Error(), outOfRangePartitionsErrMsg)
}

func IsInvalidRemovingStorage(err error) bool {
func IsAdmissionInvalidRemovingStorage(err error) bool {
return apierrors.IsInvalid(err) && strings.Contains(err.Error(), unsupportedRemovingStorageMsg)
}

func IsErrorDuringValidation(err error) bool {
func IsAdmissionErrorDuringValidation(err error) bool {
return apierrors.IsInternalError(err) && strings.Contains(err.Error(), errorDuringValidationMsg)
}
20 changes: 10 additions & 10 deletions pkg/webhooks/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestIsInvalidReplicationFactor(t *testing.T) {
}
}

func TestIsCantConnectAPIServer(t *testing.T) {
func TestIsAdmissionCantConnectAPIServer(t *testing.T) {
testCases := []struct {
testName string
err error
Expand All @@ -90,40 +90,40 @@ func TestIsCantConnectAPIServer(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.testName, func(t *testing.T) {
if got := IsCantConnectAPIServer(tc.err); got != tc.want {
if got := IsAdmissionCantConnectAPIServer(tc.err); got != tc.want {
t.Errorf("Check connection to API Server error message. Expected: %t ; Got: %t", tc.want, got)
}
})
}
}

func TestIsOutOfRangeReplicationFactor(t *testing.T) {
func TestIsAdmissionOutOfRangeReplicationFactor(t *testing.T) {
kafkaTopic := banzaicloudv1alpha1.KafkaTopic{ObjectMeta: metav1.ObjectMeta{Name: "test-KafkaTopic"}}
var fieldErrs field.ErrorList
fieldErrs = append(fieldErrs, field.Invalid(field.NewPath("spec").Child("replicationFactor"), "-2", outOfRangeReplicationFactorErrMsg))
err := apierrors.NewInvalid(
kafkaTopic.GetObjectKind().GroupVersionKind().GroupKind(),
kafkaTopic.Name, fieldErrs)

if ok := IsOutOfRangeReplicationFactor(err); !ok {
if ok := IsAdmissionOutOfRangeReplicationFactor(err); !ok {
t.Errorf("Check Out of Range ReplicationFactor error message. Expected: %t ; Got: %t", true, ok)
}
}

func TestIsOutOfRangePartitions(t *testing.T) {
func TestIsAdmissionOutOfRangePartitions(t *testing.T) {
kafkaTopic := banzaicloudv1alpha1.KafkaTopic{ObjectMeta: metav1.ObjectMeta{Name: "test-KafkaTopic"}}
var fieldErrs field.ErrorList
fieldErrs = append(fieldErrs, field.Invalid(field.NewPath("spec").Child("partitions"), "-2", outOfRangePartitionsErrMsg))
err := apierrors.NewInvalid(
kafkaTopic.GetObjectKind().GroupVersionKind().GroupKind(),
kafkaTopic.Name, fieldErrs)

if ok := IsOutOfRangePartitions(err); !ok {
if ok := IsAdmissionOutOfRangePartitions(err); !ok {
t.Errorf("Check Out of Range Partitions error message. Expected: %t ; Got: %t", true, ok)
}
}

func TestIsInvalidRemovingStorage(t *testing.T) {
func TestIsAdmissionInvalidRemovingStorage(t *testing.T) {
testCases := []struct {
testName string
fieldErrs field.ErrorList
Expand Down Expand Up @@ -159,14 +159,14 @@ func TestIsInvalidRemovingStorage(t *testing.T) {
kafkaCluster.GetObjectKind().GroupVersionKind().GroupKind(),
kafkaCluster.Name, tc.fieldErrs)

if got := IsInvalidRemovingStorage(err); got != tc.want {
if got := IsAdmissionInvalidRemovingStorage(err); got != tc.want {
t.Errorf("Check Storage Removal Error message. Expected: %t ; Got: %t", tc.want, got)
}
})
}
}

func TestIsErrorDuringValidation(t *testing.T) {
func TestIsAdmissionErrorDuringValidation(t *testing.T) {
testCases := []struct {
testName string
err error
Expand All @@ -186,7 +186,7 @@ func TestIsErrorDuringValidation(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.testName, func(t *testing.T) {
if got := IsErrorDuringValidation(tc.err); got != tc.want {
if got := IsAdmissionErrorDuringValidation(tc.err); got != tc.want {
t.Errorf("Check overall Error During Validation error message. Expected: %t ; Got: %t", tc.want, got)
}
})
Expand Down

0 comments on commit f9542b3

Please sign in to comment.