2 Copyright 2016 The Kubernetes Authors.
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
19 // FakeStore 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{}, resourceVerion string) error
29 ResyncFunc func() error
32 // Add calls the custom Add function if defined
33 func (f *FakeCustomStore) Add(obj interface{}) error {
40 // Update calls the custom Update function if defined
41 func (f *FakeCustomStore) Update(obj interface{}) error {
42 if f.UpdateFunc != nil {
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)
56 // List calls the custom List function if defined
57 func (f *FakeCustomStore) List() []interface{} {
58 if f.ListFunc != nil {
64 // ListKeys calls the custom ListKeys function if defined
65 func (f *FakeCustomStore) ListKeys() []string {
66 if f.ListKeysFunc != nil {
67 return f.ListKeysFunc()
72 // Get calls the custom Get function if defined
73 func (f *FakeCustomStore) Get(obj interface{}) (item interface{}, exists bool, err error) {
77 return nil, false, nil
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)
85 return nil, false, nil
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)
96 // Resync calls the custom Resync function if defined
97 func (f *FakeCustomStore) Resync() error {
98 if f.ResyncFunc != nil {