@@ -14,9 +14,10 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- package apiutil_test
17
+ package apiutil
18
18
19
19
import (
20
+ "fmt"
20
21
"time"
21
22
22
23
. "github.com/onsi/ginkgo"
@@ -26,8 +27,6 @@ import (
26
27
"golang.org/x/time/rate"
27
28
"k8s.io/apimachinery/pkg/api/meta"
28
29
"k8s.io/apimachinery/pkg/runtime/schema"
29
-
30
- "sigs.k8s.io/controller-runtime/pkg/client/apiutil"
31
30
)
32
31
33
32
var (
@@ -52,7 +51,7 @@ var _ = Describe("Dynamic REST Mapper", func() {
52
51
}
53
52
54
53
lim = rate .NewLimiter (rate .Limit (5 ), 5 )
55
- mapper , err = apiutil . NewDynamicRESTMapper (cfg , apiutil . WithLimiter (lim ), apiutil . WithCustomMapper (func () (meta.RESTMapper , error ) {
54
+ mapper , err = NewDynamicRESTMapper (cfg , WithLimiter (lim ), WithCustomMapper (func () (meta.RESTMapper , error ) {
56
55
baseMapper := meta .NewDefaultRESTMapper (nil )
57
56
addToMapper (baseMapper )
58
57
@@ -146,11 +145,28 @@ var _ = Describe("Dynamic REST Mapper", func() {
146
145
By ("ensuring that it was only refreshed once" )
147
146
Expect (count ).To (Equal (1 ))
148
147
})
149
- }
150
148
151
- PIt ("should lazily initialize if the lazy option is used" , func () {
152
-
153
- })
149
+ It ("should lazily initialize if the lazy option is used" , func () {
150
+ var err error
151
+ var failedOnce bool
152
+ mockErr := fmt .Errorf ("mock failed once" )
153
+ mapper , err = NewDynamicRESTMapper (cfg , WithLazyDiscovery , WithCustomMapper (func () (meta.RESTMapper , error ) {
154
+ // Make newMapper fail once
155
+ if ! failedOnce {
156
+ failedOnce = true
157
+ return nil , mockErr
158
+ }
159
+ baseMapper := meta .NewDefaultRESTMapper (nil )
160
+ addToMapper (baseMapper )
161
+ return baseMapper , nil
162
+ }))
163
+ Expect (err ).NotTo (HaveOccurred ())
164
+ Expect (mapper .(* dynamicRESTMapper ).staticMapper ).To (BeNil ())
165
+
166
+ Expect (callWithTarget ()).To (MatchError (mockErr ))
167
+ Expect (callWithTarget ()).To (Succeed ())
168
+ })
169
+ }
154
170
155
171
Describe ("KindFor" , func () {
156
172
mapperTest (func () error {
0 commit comments