1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package controllertest 18 19 import ( 20 "sync" 21 "time" 22 23 "k8s.io/apimachinery/pkg/runtime" 24 "k8s.io/apimachinery/pkg/runtime/schema" 25 "k8s.io/client-go/util/workqueue" 26 ) 27 28 var _ runtime.Object = &ErrorType{} 29 30 // ErrorType implements runtime.Object but isn't registered in any scheme and should cause errors in tests as a result. 31 type ErrorType struct{} 32 33 // GetObjectKind implements runtime.Object. 34 func (ErrorType) GetObjectKind() schema.ObjectKind { return nil } 35 36 // DeepCopyObject implements runtime.Object. 37 func (ErrorType) DeepCopyObject() runtime.Object { return nil } 38 39 var _ workqueue.RateLimitingInterface = &Queue{} 40 41 // Queue implements a RateLimiting queue as a non-ratelimited queue for testing. 42 // This helps testing by having functions that use a RateLimiting queue synchronously add items to the queue. 43 type Queue struct { 44 workqueue.Interface 45 AddedRateLimitedLock sync.Mutex 46 AddedRatelimited []any 47 } 48 49 // AddAfter implements RateLimitingInterface. 50 func (q *Queue) AddAfter(item interface{}, duration time.Duration) { 51 q.Add(item) 52 } 53 54 // AddRateLimited implements RateLimitingInterface. TODO(community): Implement this. 55 func (q *Queue) AddRateLimited(item interface{}) { 56 q.AddedRateLimitedLock.Lock() 57 q.AddedRatelimited = append(q.AddedRatelimited, item) 58 q.AddedRateLimitedLock.Unlock() 59 q.Add(item) 60 } 61 62 // Forget implements RateLimitingInterface. TODO(community): Implement this. 63 func (q *Queue) Forget(item interface{}) {} 64 65 // NumRequeues implements RateLimitingInterface. TODO(community): Implement this. 66 func (q *Queue) NumRequeues(item interface{}) int { 67 return 0 68 } 69