mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-25 22:51:40 +00:00
Merge pull request #100940 from markusthoemmes/fake-client-interface
Implement a FakeClient interface Kubernetes-commit: 8da9d2ff55ad98a685978dd690d66dfb4eb9c1fd
This commit is contained in:
commit
9a82c6a51a
4
Godeps/Godeps.json
generated
4
Godeps/Godeps.json
generated
@ -476,11 +476,11 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api",
|
||||
"Rev": "13f29098a509"
|
||||
"Rev": "8c6483ecf45e"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery",
|
||||
"Rev": "fda713515979"
|
||||
"Rev": "96c076bf1d97"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo",
|
||||
|
@ -115,12 +115,15 @@ type dynamicResourceClient struct {
|
||||
listKind string
|
||||
}
|
||||
|
||||
var (
|
||||
_ dynamic.Interface = &FakeDynamicClient{}
|
||||
_ testing.FakeClient = &FakeDynamicClient{}
|
||||
)
|
||||
|
||||
func (c *FakeDynamicClient) Tracker() testing.ObjectTracker {
|
||||
return c.tracker
|
||||
}
|
||||
|
||||
var _ dynamic.Interface = &FakeDynamicClient{}
|
||||
|
||||
func (c *FakeDynamicClient) Resource(resource schema.GroupVersionResource) dynamic.NamespaceableResourceInterface {
|
||||
return &dynamicResourceClient{client: c, resource: resource, listKind: c.gvrToListKind[resource]}
|
||||
}
|
||||
|
8
go.mod
8
go.mod
@ -28,8 +28,8 @@ require (
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d
|
||||
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
|
||||
google.golang.org/protobuf v1.25.0
|
||||
k8s.io/api v0.0.0-20210518101607-13f29098a509
|
||||
k8s.io/apimachinery v0.0.0-20210518100456-fda713515979
|
||||
k8s.io/api v0.0.0-20210506172159-8c6483ecf45e
|
||||
k8s.io/apimachinery v0.0.0-20210518100457-96c076bf1d97
|
||||
k8s.io/klog/v2 v2.8.0
|
||||
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.1.1
|
||||
@ -37,6 +37,6 @@ require (
|
||||
)
|
||||
|
||||
replace (
|
||||
k8s.io/api => k8s.io/api v0.0.0-20210518101607-13f29098a509
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210518100456-fda713515979
|
||||
k8s.io/api => k8s.io/api v0.0.0-20210506172159-8c6483ecf45e
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210518100457-96c076bf1d97
|
||||
)
|
||||
|
8
go.sum
8
go.sum
@ -426,10 +426,10 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
k8s.io/api v0.0.0-20210518101607-13f29098a509 h1:+1GipftN626FJVaUP8O0o0pgeqGunyS22Ng4hZYulvI=
|
||||
k8s.io/api v0.0.0-20210518101607-13f29098a509/go.mod h1:IgKLK42qxUHnMxdcdbEBFOo+TfTANemQTLg3gcGe8/M=
|
||||
k8s.io/apimachinery v0.0.0-20210518100456-fda713515979 h1:qjGp8QxGJZSGSMQw31AFuI2za6IEfDmdJ5/cY+Eeas8=
|
||||
k8s.io/apimachinery v0.0.0-20210518100456-fda713515979/go.mod h1:fBRSkoylGO2QUTae8Wb2wac6pZ83/r+tL6HFSXGbzfs=
|
||||
k8s.io/api v0.0.0-20210506172159-8c6483ecf45e h1:qHyhF6qKQVHrfQmOto8W6vEj7OASwoH8x1+p0l/81Dk=
|
||||
k8s.io/api v0.0.0-20210506172159-8c6483ecf45e/go.mod h1:IgKLK42qxUHnMxdcdbEBFOo+TfTANemQTLg3gcGe8/M=
|
||||
k8s.io/apimachinery v0.0.0-20210518100457-96c076bf1d97 h1:hKyy5Pr8MoGjcqM5AYHQjpizciRmC8dz4N3XG4LZwuQ=
|
||||
k8s.io/apimachinery v0.0.0-20210518100457-96c076bf1d97/go.mod h1:fBRSkoylGO2QUTae8Wb2wac6pZ83/r+tL6HFSXGbzfs=
|
||||
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
|
||||
k8s.io/klog/v2 v2.8.0 h1:Q3gmuM9hKEjefWFFYF0Mat+YyFJvsUyYuwyNNJ5C9Ts=
|
||||
|
@ -158,7 +158,10 @@ func (c *Clientset) Tracker() testing.ObjectTracker {
|
||||
return c.tracker
|
||||
}
|
||||
|
||||
var _ clientset.Interface = &Clientset{}
|
||||
var (
|
||||
_ clientset.Interface = &Clientset{}
|
||||
_ testing.FakeClient = &Clientset{}
|
||||
)
|
||||
|
||||
// AdmissionregistrationV1 retrieves the AdmissionregistrationV1Client
|
||||
func (c *Clientset) AdmissionregistrationV1() admissionregistrationv1.AdmissionregistrationV1Interface {
|
||||
|
66
testing/interface.go
Normal file
66
testing/interface.go
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package testing
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
type FakeClient interface {
|
||||
// Tracker gives access to the ObjectTracker internal to the fake client.
|
||||
Tracker() ObjectTracker
|
||||
|
||||
// AddReactor appends a reactor to the end of the chain.
|
||||
AddReactor(verb, resource string, reaction ReactionFunc)
|
||||
|
||||
// PrependReactor adds a reactor to the beginning of the chain.
|
||||
PrependReactor(verb, resource string, reaction ReactionFunc)
|
||||
|
||||
// AddWatchReactor appends a reactor to the end of the chain.
|
||||
AddWatchReactor(resource string, reaction WatchReactionFunc)
|
||||
|
||||
// PrependWatchReactor adds a reactor to the beginning of the chain.
|
||||
PrependWatchReactor(resource string, reaction WatchReactionFunc)
|
||||
|
||||
// AddProxyReactor appends a reactor to the end of the chain.
|
||||
AddProxyReactor(resource string, reaction ProxyReactionFunc)
|
||||
|
||||
// PrependProxyReactor adds a reactor to the beginning of the chain.
|
||||
PrependProxyReactor(resource string, reaction ProxyReactionFunc)
|
||||
|
||||
// Invokes records the provided Action and then invokes the ReactionFunc that
|
||||
// handles the action if one exists. defaultReturnObj is expected to be of the
|
||||
// same type a normal call would return.
|
||||
Invokes(action Action, defaultReturnObj runtime.Object) (runtime.Object, error)
|
||||
|
||||
// InvokesWatch records the provided Action and then invokes the ReactionFunc
|
||||
// that handles the action if one exists.
|
||||
InvokesWatch(action Action) (watch.Interface, error)
|
||||
|
||||
// InvokesProxy records the provided Action and then invokes the ReactionFunc
|
||||
// that handles the action if one exists.
|
||||
InvokesProxy(action Action) restclient.ResponseWrapper
|
||||
|
||||
// ClearActions clears the history of actions called on the fake client.
|
||||
ClearActions()
|
||||
|
||||
// Actions returns a chronologically ordered slice fake actions called on the
|
||||
// fake client.
|
||||
Actions() []Action
|
||||
}
|
Loading…
Reference in New Issue
Block a user