k8s.io/client-go@v0.31.1/tools/cache/fake_custom_store.go (about) 1 /* 2 Copyright 2016 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 cache 18 19 // FakeCustomStore lets you define custom functions for store operations. 20 type FakeCustomStore struct { 21 AddFunc func(obj interface{}) error 22 UpdateFunc func(obj interface{}) error 23 DeleteFunc func(obj interface{}) error 24 ListFunc func() []interface{} 25 ListKeysFunc func() []string 26 GetFunc func(obj interface{}) (item interface{}, exists bool, err error) 27 GetByKeyFunc func(key string) (item interface{}, exists bool, err error) 28 ReplaceFunc func(list []interface{}, resourceVersion string) error 29 ResyncFunc func() error 30 } 31 32 // Add calls the custom Add function if defined 33 func (f *FakeCustomStore) Add(obj interface{}) error { 34 if f.AddFunc != nil { 35 return f.AddFunc(obj) 36 } 37 return nil 38 } 39 40 // Update calls the custom Update function if defined 41 func (f *FakeCustomStore) Update(obj interface{}) error { 42 if f.UpdateFunc != nil { 43 return f.UpdateFunc(obj) 44 } 45 return nil 46 } 47 48 // Delete calls the custom Delete function if defined 49 func (f *FakeCustomStore) Delete(obj interface{}) error { 50 if f.DeleteFunc != nil { 51 return f.DeleteFunc(obj) 52 } 53 return nil 54 } 55 56 // List calls the custom List function if defined 57 func (f *FakeCustomStore) List() []interface{} { 58 if f.ListFunc != nil { 59 return f.ListFunc() 60 } 61 return nil 62 } 63 64 // ListKeys calls the custom ListKeys function if defined 65 func (f *FakeCustomStore) ListKeys() []string { 66 if f.ListKeysFunc != nil { 67 return f.ListKeysFunc() 68 } 69 return nil 70 } 71 72 // Get calls the custom Get function if defined 73 func (f *FakeCustomStore) Get(obj interface{}) (item interface{}, exists bool, err error) { 74 if f.GetFunc != nil { 75 return f.GetFunc(obj) 76 } 77 return nil, false, nil 78 } 79 80 // GetByKey calls the custom GetByKey function if defined 81 func (f *FakeCustomStore) GetByKey(key string) (item interface{}, exists bool, err error) { 82 if f.GetByKeyFunc != nil { 83 return f.GetByKeyFunc(key) 84 } 85 return nil, false, nil 86 } 87 88 // Replace calls the custom Replace function if defined 89 func (f *FakeCustomStore) Replace(list []interface{}, resourceVersion string) error { 90 if f.ReplaceFunc != nil { 91 return f.ReplaceFunc(list, resourceVersion) 92 } 93 return nil 94 } 95 96 // Resync calls the custom Resync function if defined 97 func (f *FakeCustomStore) Resync() error { 98 if f.ResyncFunc != nil { 99 return f.ResyncFunc() 100 } 101 return nil 102 }