11package runtime
22
33import (
4+ errmetrics "sigs.k8s.io/aws-load-balancer-controller/pkg/error"
45 "testing"
56 "time"
67
@@ -15,6 +16,12 @@ func TestHandleReconcileError(t *testing.T) {
1516 type args struct {
1617 err error
1718 }
19+
20+ otherErrType := errors .New ("some error" )
21+ wrappedOtherErrorType := & errmetrics.ErrorWithMetrics {
22+ Err : otherErrType ,
23+ ResourceType : "foo" ,
24+ }
1825 tests := []struct {
1926 name string
2027 args args
@@ -29,6 +36,14 @@ func TestHandleReconcileError(t *testing.T) {
2936 want : ctrl.Result {},
3037 wantErr : nil ,
3138 },
39+ {
40+ name : "input err is nil" ,
41+ args : args {
42+ err : & errmetrics.ErrorWithMetrics {},
43+ },
44+ want : ctrl.Result {},
45+ wantErr : nil ,
46+ },
3247 {
3348 name : "input err is RequeueNeededAfter" ,
3449 args : args {
@@ -49,20 +64,53 @@ func TestHandleReconcileError(t *testing.T) {
4964 },
5065 wantErr : nil ,
5166 },
67+ {
68+ name : "input err is ErrorWithMetrics and is RequeueNeededAfter" ,
69+ args : args {
70+ err : & errmetrics.ErrorWithMetrics {
71+ Err : NewRequeueNeededAfter ("some error" , 3 * time .Second ),
72+ },
73+ },
74+ want : ctrl.Result {
75+ RequeueAfter : 3 * time .Second ,
76+ },
77+ wantErr : nil ,
78+ },
79+ {
80+ name : "input err is ErrorWithMetrics and is RequeueNeeded" ,
81+ args : args {
82+ err : & errmetrics.ErrorWithMetrics {
83+ Err : NewRequeueNeeded ("some error" ),
84+ },
85+ },
86+ want : ctrl.Result {
87+ Requeue : true ,
88+ },
89+ wantErr : nil ,
90+ },
5291 {
5392 name : "input err is other error type" ,
5493 args : args {
55- err : errors .New ("some error" ),
94+ err : otherErrType ,
95+ },
96+ want : ctrl.Result {},
97+ wantErr : otherErrType ,
98+ },
99+ {
100+ name : "input err is ErrorWithMetrics with other error type" ,
101+ args : args {
102+ err : wrappedOtherErrorType ,
56103 },
57104 want : ctrl.Result {},
58- wantErr : errors . New ( "some error" ) ,
105+ wantErr : wrappedOtherErrorType ,
59106 },
60107 }
61108 for _ , tt := range tests {
62109 t .Run (tt .name , func (t * testing.T ) {
63110 got , err := HandleReconcileError (tt .args .err , logr .New (& log.NullLogSink {}))
64111 if tt .wantErr != nil {
65112 assert .EqualError (t , err , tt .wantErr .Error ())
113+ assert .Equal (t , err , tt .wantErr )
66114 } else {
67115 assert .NoError (t , err )
68116 assert .Equal (t , tt .want , got )
0 commit comments