client-go: k8s.io/client-go/testing Index | Files

package testing

import "k8s.io/client-go/testing"

Index

Package Files

actions.go fake.go fixture.go

Constants

const FakeWatchBufferSize = 128

FakeWatchBufferSize is the max num of watch event can be buffered in the watch channel. Note that when watch event overflows or exceed this buffer size, manipulations via fake client may be blocked.

func ExtractFromListOptions Uses

func ExtractFromListOptions(opts interface{}) (labelSelector labels.Selector, fieldSelector fields.Selector, resourceVersion string)

type Action Uses

type Action interface {
    GetNamespace() string
    GetVerb() string
    GetResource() schema.GroupVersionResource
    GetSubresource() string
    Matches(verb, resource string) bool
}

type ActionImpl Uses

type ActionImpl struct {
    Namespace   string
    Verb        string
    Resource    schema.GroupVersionResource
    Subresource string
}

func (ActionImpl) GetNamespace Uses

func (a ActionImpl) GetNamespace() string

func (ActionImpl) GetResource Uses

func (a ActionImpl) GetResource() schema.GroupVersionResource

func (ActionImpl) GetSubresource Uses

func (a ActionImpl) GetSubresource() string

func (ActionImpl) GetVerb Uses

func (a ActionImpl) GetVerb() string

func (ActionImpl) Matches Uses

func (a ActionImpl) Matches(verb, resource string) bool

type CreateAction Uses

type CreateAction interface {
    Action
    GetObject() runtime.Object
}

type CreateActionImpl Uses

type CreateActionImpl struct {
    ActionImpl
    Name   string
    Object runtime.Object
}

func NewCreateAction Uses

func NewCreateAction(resource schema.GroupVersionResource, namespace string, object runtime.Object) CreateActionImpl

func NewCreateSubresourceAction Uses

func NewCreateSubresourceAction(resource schema.GroupVersionResource, name, subresource string, namespace string, object runtime.Object) CreateActionImpl

func NewRootCreateAction Uses

func NewRootCreateAction(resource schema.GroupVersionResource, object runtime.Object) CreateActionImpl

func (CreateActionImpl) GetObject Uses

func (a CreateActionImpl) GetObject() runtime.Object

type DeleteAction Uses

type DeleteAction interface {
    Action
    GetName() string
}

type DeleteActionImpl Uses

type DeleteActionImpl struct {
    ActionImpl
    Name string
}

func NewDeleteAction Uses

func NewDeleteAction(resource schema.GroupVersionResource, namespace, name string) DeleteActionImpl

func NewRootDeleteAction Uses

func NewRootDeleteAction(resource schema.GroupVersionResource, name string) DeleteActionImpl

func (DeleteActionImpl) GetName Uses

func (a DeleteActionImpl) GetName() string

type DeleteCollectionAction Uses

type DeleteCollectionAction interface {
    Action
    GetListRestrictions() ListRestrictions
}

type DeleteCollectionActionImpl Uses

type DeleteCollectionActionImpl struct {
    ActionImpl
    ListRestrictions ListRestrictions
}

func NewDeleteCollectionAction Uses

func NewDeleteCollectionAction(resource schema.GroupVersionResource, namespace string, opts interface{}) DeleteCollectionActionImpl

func NewRootDeleteCollectionAction Uses

func NewRootDeleteCollectionAction(resource schema.GroupVersionResource, opts interface{}) DeleteCollectionActionImpl

func (DeleteCollectionActionImpl) GetListRestrictions Uses

func (a DeleteCollectionActionImpl) GetListRestrictions() ListRestrictions

type Fake Uses

type Fake struct {
    sync.RWMutex

    // ReactionChain is the list of reactors that will be attempted for every
    // request in the order they are tried.
    ReactionChain []Reactor
    // WatchReactionChain is the list of watch reactors that will be attempted
    // for every request in the order they are tried.
    WatchReactionChain []WatchReactor
    // ProxyReactionChain is the list of proxy reactors that will be attempted
    // for every request in the order they are tried.
    ProxyReactionChain []ProxyReactor

    Resources []*metav1.APIResourceList
    // contains filtered or unexported fields
}

Fake implements client.Interface. Meant to be embedded into a struct to get a default implementation. This makes faking out just the method you want to test easier.

func (*Fake) Actions Uses

func (c *Fake) Actions() []Action

Actions returns a chronologically ordered slice fake actions called on the fake client.

func (*Fake) AddProxyReactor Uses

func (c *Fake) AddProxyReactor(resource string, reaction ProxyReactionFunc)

AddProxyReactor appends a reactor to the end of the chain.

func (*Fake) AddReactor Uses

func (c *Fake) AddReactor(verb, resource string, reaction ReactionFunc)

AddReactor appends a reactor to the end of the chain.

func (*Fake) AddWatchReactor Uses

func (c *Fake) AddWatchReactor(resource string, reaction WatchReactionFunc)

AddWatchReactor appends a reactor to the end of the chain.

func (*Fake) ClearActions Uses

func (c *Fake) ClearActions()

ClearActions clears the history of actions called on the fake client.

func (*Fake) Invokes Uses

func (c *Fake) Invokes(action Action, defaultReturnObj runtime.Object) (runtime.Object, error)

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.

func (*Fake) InvokesProxy Uses

func (c *Fake) InvokesProxy(action Action) restclient.ResponseWrapper

InvokesProxy records the provided Action and then invokes the ReactionFunc that handles the action if one exists.

func (*Fake) InvokesWatch Uses

func (c *Fake) InvokesWatch(action Action) (watch.Interface, error)

InvokesWatch records the provided Action and then invokes the ReactionFunc that handles the action if one exists.

func (*Fake) PrependProxyReactor Uses

func (c *Fake) PrependProxyReactor(resource string, reaction ProxyReactionFunc)

PrependProxyReactor adds a reactor to the beginning of the chain.

func (*Fake) PrependReactor Uses

func (c *Fake) PrependReactor(verb, resource string, reaction ReactionFunc)

PrependReactor adds a reactor to the beginning of the chain.

func (*Fake) PrependWatchReactor Uses

func (c *Fake) PrependWatchReactor(resource string, reaction WatchReactionFunc)

PrependWatchReactor adds a reactor to the beginning of the chain.

type FakeDiscovery Uses

type FakeDiscovery struct {
    *Fake
}

TODO: this probably should be moved to somewhere else.

func (*FakeDiscovery) ServerGroups Uses

func (c *FakeDiscovery) ServerGroups() (*metav1.APIGroupList, error)

func (*FakeDiscovery) ServerResources Uses

func (c *FakeDiscovery) ServerResources() ([]*metav1.APIResourceList, error)

func (*FakeDiscovery) ServerResourcesForGroupVersion Uses

func (c *FakeDiscovery) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error)

func (*FakeDiscovery) ServerVersion Uses

func (c *FakeDiscovery) ServerVersion() (*version.Info, error)

type GenericAction Uses

type GenericAction interface {
    Action
    GetValue() interface{}
}

type GenericActionImpl Uses

type GenericActionImpl struct {
    ActionImpl
    Value interface{}
}

func (GenericActionImpl) GetValue Uses

func (a GenericActionImpl) GetValue() interface{}

type GetAction Uses

type GetAction interface {
    Action
    GetName() string
}

type GetActionImpl Uses

type GetActionImpl struct {
    ActionImpl
    Name string
}

func NewGetAction Uses

func NewGetAction(resource schema.GroupVersionResource, namespace, name string) GetActionImpl

func NewGetSubresourceAction Uses

func NewGetSubresourceAction(resource schema.GroupVersionResource, namespace, subresource, name string) GetActionImpl

func NewRootGetAction Uses

func NewRootGetAction(resource schema.GroupVersionResource, name string) GetActionImpl

func (GetActionImpl) GetName Uses

func (a GetActionImpl) GetName() string

type ListAction Uses

type ListAction interface {
    Action
    GetListRestrictions() ListRestrictions
}

type ListActionImpl Uses

type ListActionImpl struct {
    ActionImpl
    Kind             schema.GroupVersionKind
    Name             string
    ListRestrictions ListRestrictions
}

func NewListAction Uses

func NewListAction(resource schema.GroupVersionResource, kind schema.GroupVersionKind, namespace string, opts interface{}) ListActionImpl

func NewListSubresourceAction Uses

func NewListSubresourceAction(resource schema.GroupVersionResource, name, subresource string, kind schema.GroupVersionKind, namespace string, opts interface{}) ListActionImpl

func NewRootListAction Uses

func NewRootListAction(resource schema.GroupVersionResource, kind schema.GroupVersionKind, opts interface{}) ListActionImpl

func (ListActionImpl) GetKind Uses

func (a ListActionImpl) GetKind() schema.GroupVersionKind

func (ListActionImpl) GetListRestrictions Uses

func (a ListActionImpl) GetListRestrictions() ListRestrictions

type ListRestrictions Uses

type ListRestrictions struct {
    Labels labels.Selector
    Fields fields.Selector
}

type ObjectScheme Uses

type ObjectScheme interface {
    runtime.ObjectCreater
    runtime.ObjectTyper
}

ObjectScheme abstracts the implementation of common operations on objects.

type ObjectTracker Uses

type ObjectTracker interface {
    // Add adds an object to the tracker. If object being added
    // is a list, its items are added separately.
    Add(obj runtime.Object) error

    // Get retrieves the object by its kind, namespace and name.
    Get(gvr schema.GroupVersionResource, ns, name string) (runtime.Object, error)

    // Create adds an object to the tracker in the specified namespace.
    Create(gvr schema.GroupVersionResource, obj runtime.Object, ns string) error

    // Update updates an existing object in the tracker in the specified namespace.
    Update(gvr schema.GroupVersionResource, obj runtime.Object, ns string) error

    // List retrieves all objects of a given kind in the given
    // namespace. Only non-List kinds are accepted.
    List(gvr schema.GroupVersionResource, gvk schema.GroupVersionKind, ns string) (runtime.Object, error)

    // Delete deletes an existing object from the tracker. If object
    // didn't exist in the tracker prior to deletion, Delete returns
    // no error.
    Delete(gvr schema.GroupVersionResource, ns, name string) error

    // Watch watches objects from the tracker. Watch returns a channel
    // which will push added / modified / deleted object.
    Watch(gvr schema.GroupVersionResource, ns string) (watch.Interface, error)
}

ObjectTracker keeps track of objects. It is intended to be used to fake calls to a server by returning objects based on their kind, namespace and name.

func NewObjectTracker Uses

func NewObjectTracker(scheme ObjectScheme, decoder runtime.Decoder) ObjectTracker

NewObjectTracker returns an ObjectTracker that can be used to keep track of objects for the fake clientset. Mostly useful for unit tests.

type PatchAction Uses

type PatchAction interface {
    Action
    GetName() string
    GetPatch() []byte
}

type PatchActionImpl Uses

type PatchActionImpl struct {
    ActionImpl
    Name  string
    Patch []byte
}

func NewPatchAction Uses

func NewPatchAction(resource schema.GroupVersionResource, namespace string, name string, patch []byte) PatchActionImpl

func NewPatchSubresourceAction Uses

func NewPatchSubresourceAction(resource schema.GroupVersionResource, namespace, name string, patch []byte, subresources ...string) PatchActionImpl

func NewRootPatchAction Uses

func NewRootPatchAction(resource schema.GroupVersionResource, name string, patch []byte) PatchActionImpl

func NewRootPatchSubresourceAction Uses

func NewRootPatchSubresourceAction(resource schema.GroupVersionResource, name string, patch []byte, subresources ...string) PatchActionImpl

func (PatchActionImpl) GetName Uses

func (a PatchActionImpl) GetName() string

func (PatchActionImpl) GetPatch Uses

func (a PatchActionImpl) GetPatch() []byte

type ProxyGetAction Uses

type ProxyGetAction interface {
    Action
    GetScheme() string
    GetName() string
    GetPort() string
    GetPath() string
    GetParams() map[string]string
}

type ProxyGetActionImpl Uses

type ProxyGetActionImpl struct {
    ActionImpl
    Scheme string
    Name   string
    Port   string
    Path   string
    Params map[string]string
}

func NewProxyGetAction Uses

func NewProxyGetAction(resource schema.GroupVersionResource, namespace, scheme, name, port, path string, params map[string]string) ProxyGetActionImpl

func (ProxyGetActionImpl) GetName Uses

func (a ProxyGetActionImpl) GetName() string

func (ProxyGetActionImpl) GetParams Uses

func (a ProxyGetActionImpl) GetParams() map[string]string

func (ProxyGetActionImpl) GetPath Uses

func (a ProxyGetActionImpl) GetPath() string

func (ProxyGetActionImpl) GetPort Uses

func (a ProxyGetActionImpl) GetPort() string

func (ProxyGetActionImpl) GetScheme Uses

func (a ProxyGetActionImpl) GetScheme() string

type ProxyReactionFunc Uses

type ProxyReactionFunc func(action Action) (handled bool, ret restclient.ResponseWrapper, err error)

ProxyReactionFunc is a function that returns a ResponseWrapper interface for a given Action. If "handled" is false, then the test client will ignore the results and continue to the next ProxyReactionFunc.

type ProxyReactor Uses

type ProxyReactor interface {
    // Handles indicates whether or not this Reactor deals with a given
    // action.
    Handles(action Action) bool
    // React handles a watch action and returns results.  It may choose to
    // delegate by indicating handled=false.
    React(action Action) (handled bool, ret restclient.ResponseWrapper, err error)
}

ProxyReactor is an interface to allow the composition of proxy get functions.

type ReactionFunc Uses

type ReactionFunc func(action Action) (handled bool, ret runtime.Object, err error)

ReactionFunc is a function that returns an object or error for a given Action. If "handled" is false, then the test client will ignore the results and continue to the next ReactionFunc. A ReactionFunc can describe reactions on subresources by testing the result of the action's GetSubresource() method.

func ObjectReaction Uses

func ObjectReaction(tracker ObjectTracker) ReactionFunc

ObjectReaction returns a ReactionFunc that applies core.Action to the given tracker.

type Reactor Uses

type Reactor interface {
    // Handles indicates whether or not this Reactor deals with a given
    // action.
    Handles(action Action) bool
    // React handles the action and returns results.  It may choose to
    // delegate by indicated handled=false.
    React(action Action) (handled bool, ret runtime.Object, err error)
}

Reactor is an interface to allow the composition of reaction functions.

type SimpleProxyReactor Uses

type SimpleProxyReactor struct {
    Resource string

    Reaction ProxyReactionFunc
}

SimpleProxyReactor is a ProxyReactor. Each reaction function is attached to a given resource. "*" matches everything for that value. For instance, *,pods matches all verbs on pods. This allows for easier composition of reaction functions.

func (*SimpleProxyReactor) Handles Uses

func (r *SimpleProxyReactor) Handles(action Action) bool

func (*SimpleProxyReactor) React Uses

func (r *SimpleProxyReactor) React(action Action) (bool, restclient.ResponseWrapper, error)

type SimpleReactor Uses

type SimpleReactor struct {
    Verb     string
    Resource string

    Reaction ReactionFunc
}

SimpleReactor is a Reactor. Each reaction function is attached to a given verb,resource tuple. "*" in either field matches everything for that value. For instance, *,pods matches all verbs on pods. This allows for easier composition of reaction functions

func (*SimpleReactor) Handles Uses

func (r *SimpleReactor) Handles(action Action) bool

func (*SimpleReactor) React Uses

func (r *SimpleReactor) React(action Action) (bool, runtime.Object, error)

type SimpleWatchReactor Uses

type SimpleWatchReactor struct {
    Resource string

    Reaction WatchReactionFunc
}

SimpleWatchReactor is a WatchReactor. Each reaction function is attached to a given resource. "*" matches everything for that value. For instance, *,pods matches all verbs on pods. This allows for easier composition of reaction functions

func (*SimpleWatchReactor) Handles Uses

func (r *SimpleWatchReactor) Handles(action Action) bool

func (*SimpleWatchReactor) React Uses

func (r *SimpleWatchReactor) React(action Action) (bool, watch.Interface, error)

type UpdateAction Uses

type UpdateAction interface {
    Action
    GetObject() runtime.Object
}

type UpdateActionImpl Uses

type UpdateActionImpl struct {
    ActionImpl
    Object runtime.Object
}

func NewRootUpdateAction Uses

func NewRootUpdateAction(resource schema.GroupVersionResource, object runtime.Object) UpdateActionImpl

func NewRootUpdateSubresourceAction Uses

func NewRootUpdateSubresourceAction(resource schema.GroupVersionResource, subresource string, object runtime.Object) UpdateActionImpl

func NewUpdateAction Uses

func NewUpdateAction(resource schema.GroupVersionResource, namespace string, object runtime.Object) UpdateActionImpl

func NewUpdateSubresourceAction Uses

func NewUpdateSubresourceAction(resource schema.GroupVersionResource, subresource string, namespace string, object runtime.Object) UpdateActionImpl

func (UpdateActionImpl) GetObject Uses

func (a UpdateActionImpl) GetObject() runtime.Object

type WatchAction Uses

type WatchAction interface {
    Action
    GetWatchRestrictions() WatchRestrictions
}

type WatchActionImpl Uses

type WatchActionImpl struct {
    ActionImpl
    WatchRestrictions WatchRestrictions
}

func NewRootWatchAction Uses

func NewRootWatchAction(resource schema.GroupVersionResource, opts interface{}) WatchActionImpl

func NewWatchAction Uses

func NewWatchAction(resource schema.GroupVersionResource, namespace string, opts interface{}) WatchActionImpl

func (WatchActionImpl) GetWatchRestrictions Uses

func (a WatchActionImpl) GetWatchRestrictions() WatchRestrictions

type WatchReactionFunc Uses

type WatchReactionFunc func(action Action) (handled bool, ret watch.Interface, err error)

WatchReactionFunc is a function that returns a watch interface. If "handled" is false, then the test client will ignore the results and continue to the next ReactionFunc.

func DefaultWatchReactor Uses

func DefaultWatchReactor(watchInterface watch.Interface, err error) WatchReactionFunc

type WatchReactor Uses

type WatchReactor interface {
    // Handles indicates whether or not this Reactor deals with a given
    // action.
    Handles(action Action) bool
    // React handles a watch action and returns results.  It may choose to
    // delegate by indicating handled=false.
    React(action Action) (handled bool, ret watch.Interface, err error)
}

WatchReactor is an interface to allow the composition of watch functions.

type WatchRestrictions Uses

type WatchRestrictions struct {
    Labels          labels.Selector
    Fields          fields.Selector
    ResourceVersion string
}

Package testing imports 15 packages (graph) and is imported by 239 packages. Updated 2018-01-17. Refresh now. Tools for package owners.