Documentation ¶
Overview ¶
Package fake provides a fake client for testing.
A fake client is backed by its simple object store indexed by GroupVersionResource. You can create a fake client with optional objects.
client := NewFakeClientWithScheme(scheme, initObjs...) // initObjs is a slice of runtime.Object
You can invoke the methods defined in the Client interface.
When in doubt, it's almost always better not to use this package and instead use envtest.Environment with a real client and API server.
WARNING: ⚠️ Current Limitations / Known Issues with the fake Client ⚠️
- This client does not have a way to inject specific errors to test handled vs. unhandled errors.
- There is some support for sub resources which can cause issues with tests if you're trying to update e.g. metadata and status in the same reconcile.
- No OpeanAPI validation is performed when creating or updating objects.
- ObjectMeta's `Generation` and `ResourceVersion` don't behave properly, Patch or Update
operations that rely on these fields will fail, or give false positives.
Index ¶
- func NewFakeClient(initObjs ...runtime.Object) client.Clientdeprecated
- func NewFakeClientWithScheme(clientScheme *runtime.Scheme, initObjs ...runtime.Object) client.Clientdeprecated
- type ClientBuilder
- func (f *ClientBuilder) Build() client.Client
- func (f *ClientBuilder) WithLists(initLists ...client.ObjectList) *ClientBuilder
- func (f *ClientBuilder) WithObjects(initObjs ...client.Object) *ClientBuilder
- func (f *ClientBuilder) WithRuntimeObjects(initRuntimeObjs ...runtime.Object) *ClientBuilder
- func (f *ClientBuilder) WithScheme(scheme *runtime.Scheme) *ClientBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFakeClient
deprecated
func NewFakeClientWithScheme
deprecated
added in
v0.1.8
Types ¶
type ClientBuilder ¶ added in v0.8.5
type ClientBuilder struct {
// contains filtered or unexported fields
}
ClientBuilder builds a fake client.
func NewClientBuilder ¶ added in v0.8.5
func NewClientBuilder() *ClientBuilder
NewClientBuilder returns a new builder to create a fake client.
func (*ClientBuilder) Build ¶ added in v0.8.5
func (f *ClientBuilder) Build() client.Client
Build builds and returns a new fake client.
func (*ClientBuilder) WithLists ¶ added in v0.8.5
func (f *ClientBuilder) WithLists(initLists ...client.ObjectList) *ClientBuilder
WithLists can be optionally used to initialize this fake client with client.ObjectList(s).
func (*ClientBuilder) WithObjects ¶ added in v0.8.5
func (f *ClientBuilder) WithObjects(initObjs ...client.Object) *ClientBuilder
WithObjects can be optionally used to initialize this fake client with client.Object(s).
func (*ClientBuilder) WithRuntimeObjects ¶ added in v0.8.5
func (f *ClientBuilder) WithRuntimeObjects(initRuntimeObjs ...runtime.Object) *ClientBuilder
WithRuntimeObjects can be optionally used to initialize this fake client with runtime.Object(s).
func (*ClientBuilder) WithScheme ¶ added in v0.8.5
func (f *ClientBuilder) WithScheme(scheme *runtime.Scheme) *ClientBuilder
WithScheme sets this builder's internal scheme. If not set, defaults to client-go's global scheme.Scheme.