fake

package
v1.17.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConflictHandler added in v1.15.1

func NewConflictHandler() conflict.Handler

NewConflictHandler initiates a fake implementation of conflict.Handler.

func NewDiscoveryClient

func NewDiscoveryClient(gvks ...schema.GroupVersionKind) discoveryutil.ServerResourcer

NewDiscoveryClient returns a discoveryClient that reports types available to the API Server with no errors

Does not report the scope of each GVK as no tests requiring a discoveryClient use scope information.

func NewDiscoveryClientWithError added in v1.15.1

func NewDiscoveryClientWithError(wantedErr error, gvks ...schema.GroupVersionKind) discoveryutil.ServerResourcer

NewDiscoveryClientWithError returns a discoveryClient that reports types available to the API Server with no errors, or ErrGroupDiscoveryFailed error with the specified wantedErr

Does not report the scope of each GVK as no tests requiring a discoveryClient use scope information.

func NewErrorClient

func NewErrorClient(err error) client.Client

NewErrorClient returns a Client that always returns an error.

func NewFightHandler added in v1.15.1

func NewFightHandler() fight.Handler

NewFightHandler initiates a fake implementation of fight.Handler.

func RealNow added in v1.16.0

func RealNow() metav1.Time

RealNow is the default Now function used by NewClient.

func StartWatchSupervisor added in v1.16.0

func StartWatchSupervisor(t *testing.T, supervisor *WatchSupervisor)

StartWatchSupervisor starts a watchSupervisor and stops it in test cleanup.

func StartWatcher added in v1.16.0

func StartWatcher(t *testing.T, watcher *Watcher)

StartWatcher starts a watchSupervisor and stops it in test cleanup.

Types

type Applier added in v1.15.1

type Applier struct {
	Client      *Client
	CreateError status.Error
	UpdateError status.Error
	DeleteError status.Error
}

Applier implements a fake reconcile.Applier for use in testing.

reconcile.Applier not imported due to import cycle considerations.

func (*Applier) Create added in v1.15.1

Create implements reconcile.Applier.

func (*Applier) Delete added in v1.15.1

Delete implements reconcile.Applier.

func (*Applier) GetClient added in v1.15.1

func (a *Applier) GetClient() client.Client

GetClient implements reconcile.Applier.

func (*Applier) RemoveNomosMeta added in v1.15.1

func (a *Applier) RemoveNomosMeta(ctx context.Context, intent *unstructured.Unstructured, _ string) status.Error

RemoveNomosMeta implements reconcile.Applier.

func (*Applier) Update added in v1.15.1

func (a *Applier) Update(ctx context.Context, intendedState, _ *unstructured.Unstructured) status.Error

Update implements reconcile.Applier.

type Cache added in v1.16.0

type Cache struct {
	*Client
	// contains filtered or unexported fields
}

Cache is a fake implementation of cache.Cache.

func NewCache added in v1.16.0

func NewCache(fakeClient *Client, opts CacheOptions) *Cache

NewCache constructs a new Cache

func (*Cache) Get added in v1.16.0

func (c *Cache) Get(ctx context.Context, key client.ObjectKey, out client.Object, opts ...client.GetOption) error

Get implements client.Reader.Get.

func (*Cache) GetInformer added in v1.16.0

func (c *Cache) GetInformer(ctx context.Context, obj client.Object) (cache.Informer, error)

GetInformer constructs or retrieves from cache an informer to watch the specified resource.

func (*Cache) GetInformerForKind added in v1.16.0

func (c *Cache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind) (cache.Informer, error)

GetInformerForKind returns the informer for the GroupVersionKind.

func (*Cache) HasSyncedFuncs added in v1.16.0

func (c *Cache) HasSyncedFuncs() []k8scache.InformerSynced

HasSyncedFuncs returns all the HasSynced functions for the informers in this map.

func (*Cache) IndexField added in v1.16.0

func (c *Cache) IndexField(ctx context.Context, obj client.Object, field string, extractValue client.IndexerFunc) error

IndexField adds an indexer to the underlying cache, using extraction function to get value(s) from the given field. This index can then be used by passing a field selector to List. For one-to-one compatibility with "normal" field selectors, only return one value. The values may be anything. They will automatically be prefixed with the namespace of the given object, if present. The objects passed are guaranteed to be objects of the correct type.

func (*Cache) List added in v1.16.0

func (c *Cache) List(ctx context.Context, out client.ObjectList, opts ...client.ListOption) error

List implements client.Reader.List.

func (*Cache) Start added in v1.16.0

func (c *Cache) Start(ctx context.Context) error

Start the cache, including any previously requested informers. New informers requested after start will be started immediately.

func (*Cache) WaitForCacheSync added in v1.16.0

func (c *Cache) WaitForCacheSync(ctx context.Context) bool

WaitForCacheSync returns true when the cached informers are all synced. Returns false if the context is done first.

type CacheOptions added in v1.16.0

type CacheOptions struct {
	// Namespace restricts the cache's ListWatch to the desired namespace
	// Default watches all namespaces
	Namespace string

	// ResyncPeriod is how often the objects are retrieved to re-synchronize,
	// in case any events were missed.
	// If zero or less, re-sync is disabled.
	ResyncPeriod time.Duration
}

CacheOptions are the optional arguments for creating a new Cache object.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a fake implementation of client.Client.

Known Unimplemented features (update as discovered/added): - DeletePropagationBackground (performs foreground instead) - DeletePropagationOrphan (returns error if used) - ListOptions.Limit & Continue (ignored - all objects are returned) - Status().Patch

func NewClient

func NewClient(t *testing.T, scheme *runtime.Scheme, objs ...client.Object) *Client

NewClient instantiates a new fake.Client pre-populated with the specified objects.

Calls t.Fatal if unable to properly instantiate Client.

func (*Client) Applier

func (c *Client) Applier() reconcile.Applier

Applier returns a fake.Applier wrapping this fake.Client. Callers using the resulting Applier will read from/write to the original fake.Client.

func (*Client) Check

func (c *Client) Check(t *testing.T, wants ...client.Object)

Check reports an error to `t` if the passed objects in wants do not match the expected set of objects in the fake.Client, and only the passed updates to Status fields were recorded.

func (*Client) Codecs added in v1.16.0

func (c *Client) Codecs() serializer.CodecFactory

Codecs returns the CodecFactory.

func (*Client) Create

func (c *Client) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error

Create implements client.Client.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error

Delete implements client.Client.

func (*Client) DeleteAllOf

func (c *Client) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error

DeleteAllOf implements client.Client.

func (*Client) Get

func (c *Client) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error

Get implements client.Client.

func (*Client) List

func (c *Client) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

List implements client.Client.

Does not paginate results.

func (*Client) Patch

func (c *Client) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error

Patch implements client.Client.

func (*Client) RESTMapper

func (c *Client) RESTMapper() meta.RESTMapper

RESTMapper returns the RESTMapper.

func (*Client) Scheme

func (c *Client) Scheme() *runtime.Scheme

Scheme implements client.Client.

func (*Client) Status

func (c *Client) Status() client.SubResourceWriter

Status implements client.Client.

func (*Client) Storage added in v1.16.0

func (c *Client) Storage() *MemoryStorage

Storage returns the backing Storage layer

func (*Client) SubResource added in v1.16.0

func (c *Client) SubResource(subResource string) client.SubResourceClient

SubResource implements client.Client

func (*Client) Update

func (c *Client) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

Update implements client.Client.

func (*Client) Watch added in v1.16.0

func (c *Client) Watch(ctx context.Context, exampleList client.ObjectList, opts ...client.ListOption) (watch.Interface, error)

Watch implements client.WithWatch.

type ClientSet added in v1.16.0

type ClientSet struct {
	// Client is a fake implementation of client.Client.
	Client *Client
	// DynamicClient is a fake implementation of dynamic.Interface.
	DynamicClient *DynamicClient
	// Storage is the in-memory storage backing both the Client & DynamicClient.
	Storage *MemoryStorage
}

ClientSet is a wrapper that contains a client.Client & dynamic.Interface with the same backing MemoryStorage. This enables usage of both client types in the same tests.

func NewClientSet added in v1.16.0

func NewClientSet(t *testing.T, scheme *runtime.Scheme) *ClientSet

NewClientSet builds a new fake.Client & fake.DynamicClient that share a MemoryStorage.

Calls t.Fatal if unable to properly instantiate Client.

type ConflictHandler added in v1.15.1

type ConflictHandler struct{}

ConflictHandler is a fake implementation of conflict.Handler.

func (*ConflictHandler) AddConflictError added in v1.15.1

AddConflictError is a fake implementation of AddConflictError of conflict.Handler.

func (*ConflictHandler) ConflictErrors added in v1.15.1

func (h *ConflictHandler) ConflictErrors() []status.ManagementConflictError

ConflictErrors is a fake implementation of ConflictErrors of conflict.Handler.

func (*ConflictHandler) RemoveAllConflictErrors added in v1.15.1

func (h *ConflictHandler) RemoveAllConflictErrors(schema.GroupVersionKind)

RemoveAllConflictErrors is a fake implementation of RemoveAllConflictErrors of conflict.Handler.

func (*ConflictHandler) RemoveConflictError added in v1.15.1

func (h *ConflictHandler) RemoveConflictError(queue.GVKNN)

RemoveConflictError is a fake implementation of the RemoveConflictError of conflict.Handler.

type DynamicClient added in v1.15.1

type DynamicClient struct {
	*dynamicfake.FakeDynamicClient
	// contains filtered or unexported fields
}

DynamicClient is a fake implementation of dynamic.Interface

func NewDynamicClient added in v1.15.1

func NewDynamicClient(t *testing.T, scheme *runtime.Scheme) *DynamicClient

NewDynamicClient instantiates a new fake.DynamicClient

func (*DynamicClient) Check added in v1.15.1

func (dc *DynamicClient) Check(t *testing.T, wants ...client.Object)

Check reports an error to `t` if the passed objects in wants do not match the expected set of objects in the fake.Client, and only the passed updates to Status fields were recorded.

func (*DynamicClient) Put added in v1.15.1

func (dc *DynamicClient) Put(t *testing.T, obj *unstructured.Unstructured)

Put adds the object to the cache, with metadata validation.

Use for test initialization to simulate exact cluster state. Does not trigger events or garbage collection.

func (*DynamicClient) PutAll added in v1.15.1

func (dc *DynamicClient) PutAll(t *testing.T, objs ...*unstructured.Unstructured)

PutAll loops through the objects and adds them to the cache, with metadata validation.

Use for test initialization to simulate exact cluster state.

func (*DynamicClient) RESTMapper added in v1.17.2

func (dc *DynamicClient) RESTMapper() meta.RESTMapper

RESTMapper returns the backing RESTMapper.

func (*DynamicClient) Scheme added in v1.17.2

func (dc *DynamicClient) Scheme() *runtime.Scheme

Scheme returns the backing Scheme.

func (*DynamicClient) Storage added in v1.17.2

func (dc *DynamicClient) Storage() *MemoryStorage

Storage returns the backing Storage layer

type ErrorClient

type ErrorClient struct {
	// contains filtered or unexported fields
}

ErrorClient is a Client that always returns a specified error.

func (ErrorClient) Create

Create implements client.Client.

func (ErrorClient) Delete

Delete implements client.Client.

func (ErrorClient) DeleteAllOf

DeleteAllOf implements client.Client.

func (ErrorClient) Get

Get implements client.Client.

func (ErrorClient) List

List implements client.Client.

func (ErrorClient) Patch

Patch implements client.Client.

func (ErrorClient) RESTMapper

func (e ErrorClient) RESTMapper() meta.RESTMapper

RESTMapper implements client.Client.

func (ErrorClient) Scheme

func (e ErrorClient) Scheme() *runtime.Scheme

Scheme implements client.Client.

func (ErrorClient) Status

func (e ErrorClient) Status() client.StatusWriter

Status implements client.Client.

func (ErrorClient) SubResource added in v1.16.0

func (e ErrorClient) SubResource(_ string) client.SubResourceClient

SubResource implements client.Client.

func (ErrorClient) Update

Update implements client.Client.

type FightHandler added in v1.15.1

type FightHandler struct{}

FightHandler is a fake implementation of fight.Handler.

func (*FightHandler) AddFightError added in v1.15.1

func (h *FightHandler) AddFightError(core.ID, status.Error)

AddFightError is a fake implementation of the AddFightError of fight.Handler.

func (*FightHandler) FightErrors added in v1.15.1

func (h *FightHandler) FightErrors() []status.Error

FightErrors is a fake implementation of the FightErrors of fight.Handler.

func (*FightHandler) RemoveFightError added in v1.15.1

func (h *FightHandler) RemoveFightError(core.ID)

RemoveFightError is a fake implementation of the RemoveFightError of fight.Handler.

type MapEntry added in v1.16.0

type MapEntry struct {
	// Informer is the cached informer
	Informer k8scache.SharedIndexInformer

	// CacheReader wraps Informer and implements the CacheReader interface for a single type
	Reader client.Reader
}

MapEntry contains the cached data for an Informer.

type MemoryStorage added in v1.16.0

type MemoryStorage struct {

	// Now is a hook to replace time.Now for testing.
	// Default impl is RealNow.
	Now func() metav1.Time
	// contains filtered or unexported fields
}

MemoryStorage is an in-memory simulation of the Kubernetes APIServer.

Many resource-agnostic features are implemented to facilitate testing controllers and other libraries. No resource-specific controller behaviors are implemented.

func NewInMemoryStorage added in v1.16.0

func NewInMemoryStorage(scheme *runtime.Scheme, watchSupervisor *WatchSupervisor) *MemoryStorage

NewInMemoryStorage constructs a new MemoryStorage

func (*MemoryStorage) Check added in v1.16.0

func (ms *MemoryStorage) Check(t *testing.T, wants ...client.Object)

Check reports a test error if the passed objects (wants) do not match the expected set of objects in storage. Objects will be converted to the scheme-preferred version and minimized before comparison.

func (*MemoryStorage) Create added in v1.16.0

func (ms *MemoryStorage) Create(ctx context.Context, obj client.Object, opts *client.CreateOptions) error

Create an object in storage

func (*MemoryStorage) Delete added in v1.16.0

func (ms *MemoryStorage) Delete(ctx context.Context, obj client.Object, opts *client.DeleteOptions) error

Delete an object in storage

func (*MemoryStorage) DeleteAllOf added in v1.16.0

DeleteAllOf deletes all the objects of the specified resource.

func (*MemoryStorage) Get added in v1.16.0

Get an object from storage

func (*MemoryStorage) List added in v1.16.0

List all the objects in storage that match the resource type and list objects.

func (*MemoryStorage) Patch added in v1.16.0

func (ms *MemoryStorage) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts *client.PatchOptions) error

Patch an object in storage

func (*MemoryStorage) Subresource added in v1.16.0

func (ms *MemoryStorage) Subresource(field string) *SubresourceStorage

Subresource returns a new SubresourceStorage, which can be used to update the sub-resource field, without updating any other fields.

func (*MemoryStorage) TestGet added in v1.16.0

func (ms *MemoryStorage) TestGet(id core.ID) (*unstructured.Unstructured, bool)

TestGet gets an object from storage, without validation or type conversion. Use for testing what exactly is in storage. The object is NOT a copy. Use with caution.

func (*MemoryStorage) TestGetAll added in v1.16.0

func (ms *MemoryStorage) TestGetAll() map[core.ID]*unstructured.Unstructured

TestGetAll gets all objects from storage, without validation or type conversion. Use for testing what exactly is in storage. The map is a copy, but the objects are NOT copies. Use with caution.

func (*MemoryStorage) TestPut added in v1.16.0

func (ms *MemoryStorage) TestPut(obj client.Object) error

TestPut adds or replaces an object in storage without sending events or triggering garbage collection. Use for initializing or replacing what exactly is in storage.

func (*MemoryStorage) TestPutAll added in v1.16.0

func (ms *MemoryStorage) TestPutAll(objs ...client.Object) error

TestPutAll adds or replaces multiple objects in storage without sending events or triggering garbage collection. Use for initializing or replacing what exactly is in storage.

func (*MemoryStorage) Update added in v1.16.0

func (ms *MemoryStorage) Update(ctx context.Context, obj client.Object, opts *client.UpdateOptions) error

Update an object in storage

func (*MemoryStorage) Watch added in v1.16.0

func (ms *MemoryStorage) Watch(_ context.Context, exampleList client.ObjectList, opts *client.ListOptions) (watch.Interface, error)

Watch the specified objects. The returned watcher will stream events to the ResultChan until Stop is called.

type SubResourceErrorClient added in v1.16.0

type SubResourceErrorClient struct {
	// contains filtered or unexported fields
}

SubResourceErrorClient is a SubResourceClient that always returns a specified error.

func (SubResourceErrorClient) Create added in v1.16.0

Create implements client.SubResourceWriter

func (SubResourceErrorClient) Get added in v1.16.0

Get implements client.SubResourceReader

func (SubResourceErrorClient) Patch added in v1.16.0

Patch implements client.SubResourceWriter

func (SubResourceErrorClient) Update added in v1.16.0

Update implements client.SubResourceWriter

type SubresourceStorage added in v1.16.0

type SubresourceStorage struct {
	// Storage is the backing store for full resource objects
	Storage *MemoryStorage
	// Field is the sub-resource field managed by this SubresourceStorage
	Field string
}

SubresourceStorage is a wrapper around MemoryStorage that allows modifying a specific top-level field without updating any other fields.

func (*SubresourceStorage) Patch added in v1.16.0

Patch the sub-resource field. All other fields are ignored.

func (*SubresourceStorage) Update added in v1.16.0

Update the sub-resource field. All other fields are ignored.

type UnstructuredFields added in v1.15.1

type UnstructuredFields struct {
	Object *unstructured.Unstructured
}

UnstructuredFields Implements fields.Fields to do field selection on any field in an unstructured object.

func (*UnstructuredFields) Get added in v1.15.1

func (uf *UnstructuredFields) Get(field string) (value string)

Get returns the value for the provided field.

func (*UnstructuredFields) Has added in v1.15.1

func (uf *UnstructuredFields) Has(field string) (exists bool)

Has returns whether the provided field exists.

type WatchSupervisor added in v1.16.0

type WatchSupervisor struct {
	// contains filtered or unexported fields
}

WatchSupervisor supervises watches for all resources in a scheme.

Once started, the supervisor handles fan-out of events to all current watchers. Watches are version-agnostic. Any events for a specific GroupKind will be propagated to all watchers of that GroupKind.

func NewWatchSupervisor added in v1.16.0

func NewWatchSupervisor(scheme *runtime.Scheme) *WatchSupervisor

NewWatchSupervisor constructs a new WatchSupervisor

func (*WatchSupervisor) Done added in v1.16.0

func (ws *WatchSupervisor) Done() <-chan struct{}

Done returns a channel that will be closed when Run has exited.

func (*WatchSupervisor) Run added in v1.16.0

func (ws *WatchSupervisor) Run(ctx context.Context)

Run propagates events to watchers until the context is done.

func (*WatchSupervisor) Send added in v1.16.0

func (ws *WatchSupervisor) Send(ctx context.Context, gk schema.GroupKind, event watch.Event)

Send an event to all watchers of the specified GroupKind. Send will block until consumed by Run for async propagation to all watchers. Event will be ignored if Run is done.

type Watcher added in v1.16.0

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher is a fake implementation of watch.Interface.

func NewWatcher added in v1.16.0

func NewWatcher(supervisor *WatchSupervisor, gk schema.GroupKind, exampleList client.ObjectList, options *client.ListOptions) *Watcher

NewWatcher constructs a new Watcher

func (*Watcher) ResultChan added in v1.16.0

func (fw *Watcher) ResultChan() <-chan watch.Event

ResultChan returns the event channel. The event channel will be closed when the watcher is stopped.

func (*Watcher) Start added in v1.16.0

func (fw *Watcher) Start(ctx context.Context) <-chan struct{}

Start adds the watcher to the supervisor and starts a background goroutine to handle events until the context is done or the Watcher is stopped, then the watcher is removed from the supervisor. Returns a done channel that will be closed event handling had stopped and the watcher has been removed from the supervisor.

func (*Watcher) Stop added in v1.16.0

func (fw *Watcher) Stop()

Stop watching the event channel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL