-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor AsResult method in shared.go
Signed-off-by: Phoeniix Zhao <[email protected]>
- Loading branch information
1 parent
dc5cf46
commit 900f7cd
Showing
3 changed files
with
48 additions
and
17 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
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,42 @@ | ||
package controller | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
update_errors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
func TestStCtrlErrSet_AsResult(t *testing.T) { | ||
// Test case 1: No errors | ||
errSet := StCtrlErrSet{} | ||
result, err := errSet.AsResult() | ||
assert.NoError(t, err) | ||
assert.Equal(t, ctrl.Result{}, result) | ||
|
||
// Test case 2: Update conflict error | ||
statusErr := update_errors.StatusError{ErrStatus: metav1.Status{ | ||
Code: http.StatusConflict, | ||
Reason: metav1.StatusReasonConflict, | ||
}} | ||
errSet = StCtrlErrSet{ | ||
Update: error(&statusErr), | ||
} | ||
result, err = errSet.AsResult() | ||
assert.NoError(t, err) | ||
assert.Equal(t, ctrl.Result{Requeue: true}, result) | ||
|
||
// Test case 3: Other errors | ||
errSet = StCtrlErrSet{ | ||
Rec: errors.New("reconciliation error"), | ||
Sync: errors.New("sync error"), | ||
Update: errors.New("update status error"), | ||
} | ||
result, err = errSet.AsResult() | ||
assert.Error(t, err) | ||
assert.Equal(t, ctrl.Result{Requeue: true}, result) | ||
} |