1 /* 2 Copyright 2021 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 testing 18 19 import ( 20 "k8s.io/apimachinery/pkg/runtime" 21 "k8s.io/apimachinery/pkg/watch" 22 restclient "k8s.io/client-go/rest" 23 ) 24 25 type FakeClient interface { 26 // Tracker gives access to the ObjectTracker internal to the fake client. 27 Tracker() ObjectTracker 28 29 // AddReactor appends a reactor to the end of the chain. 30 AddReactor(verb, resource string, reaction ReactionFunc) 31 32 // PrependReactor adds a reactor to the beginning of the chain. 33 PrependReactor(verb, resource string, reaction ReactionFunc) 34 35 // AddWatchReactor appends a reactor to the end of the chain. 36 AddWatchReactor(resource string, reaction WatchReactionFunc) 37 38 // PrependWatchReactor adds a reactor to the beginning of the chain. 39 PrependWatchReactor(resource string, reaction WatchReactionFunc) 40 41 // AddProxyReactor appends a reactor to the end of the chain. 42 AddProxyReactor(resource string, reaction ProxyReactionFunc) 43 44 // PrependProxyReactor adds a reactor to the beginning of the chain. 45 PrependProxyReactor(resource string, reaction ProxyReactionFunc) 46 47 // Invokes records the provided Action and then invokes the ReactionFunc that 48 // handles the action if one exists. defaultReturnObj is expected to be of the 49 // same type a normal call would return. 50 Invokes(action Action, defaultReturnObj runtime.Object) (runtime.Object, error) 51 52 // InvokesWatch records the provided Action and then invokes the ReactionFunc 53 // that handles the action if one exists. 54 InvokesWatch(action Action) (watch.Interface, error) 55 56 // InvokesProxy records the provided Action and then invokes the ReactionFunc 57 // that handles the action if one exists. 58 InvokesProxy(action Action) restclient.ResponseWrapper 59 60 // ClearActions clears the history of actions called on the fake client. 61 ClearActions() 62 63 // Actions returns a chronologically ordered slice fake actions called on the 64 // fake client. 65 Actions() []Action 66 } 67