Documentation ¶
Overview ¶
Package testing includes utilities for testing controllers.
Package testing includes utilities for testing controllers.
Index ¶
- func InduceFailure(verb, resource string) clientgotesting.ReactionFunc
- func KeyOrDie(obj interface{}) string
- func ValidateCreates(action clientgotesting.Action) (handled bool, ret runtime.Object, err error)
- func ValidateUpdates(action clientgotesting.Action) (handled bool, ret runtime.Object, err error)
- type BuildLister
- type ConfigMapLister
- type ConfigurationLister
- type CreateHookFunc
- type Ctor
- type DeleteHookFunc
- type DeploymentLister
- func (r *DeploymentLister) Deployments(namespace string) appsv1listers.DeploymentNamespaceLister
- func (r *DeploymentLister) GetDeploymentsForReplicaSet(rs *appsv1.ReplicaSet) (results []*appsv1.Deployment, err error)
- func (r *DeploymentLister) List(selector labels.Selector) (results []*appsv1.Deployment, err error)
- type EndpointsLister
- type HookResult
- type Hooks
- func (h *Hooks) OnCreate(fake *kubetesting.Fake, resource string, rf CreateHookFunc)
- func (h *Hooks) OnDelete(fake *kubetesting.Fake, resource string, rf DeleteHookFunc)
- func (h *Hooks) OnUpdate(fake *kubetesting.Fake, resource string, rf UpdateHookFunc)
- func (h *Hooks) WaitForHooks(timeout time.Duration) error
- type K8sServiceLister
- type Listers
- func (f *Listers) GetBuildLister() *BuildLister
- func (f *Listers) GetBuildObjects() []runtime.Object
- func (f *Listers) GetConfigMapLister() *ConfigMapLister
- func (f *Listers) GetConfigurationLister() *ConfigurationLister
- func (f *Listers) GetDeploymentLister() *DeploymentLister
- func (f *Listers) GetEndpointsLister() *EndpointsLister
- func (f *Listers) GetK8sServiceLister() *K8sServiceLister
- func (f *Listers) GetKubeObjects() []runtime.Object
- func (f *Listers) GetRevisionLister() *RevisionLister
- func (f *Listers) GetRouteLister() *RouteLister
- func (f *Listers) GetServiceLister() *ServiceLister
- func (f *Listers) GetServingObjects() []runtime.Object
- func (f *Listers) GetVirtualServiceLister() *VirtualServiceLister
- type RevisionLister
- type RouteLister
- type ServiceLister
- type TableRow
- type TableTest
- type UpdateHookFunc
- type VirtualServiceLister
- func (r *VirtualServiceLister) GetPodServices(p *corev1.Pod) (results []*istiov1alpha3.VirtualService, err error)
- func (r *VirtualServiceLister) List(selector labels.Selector) (results []*istiov1alpha3.VirtualService, err error)
- func (r *VirtualServiceLister) VirtualServices(namespace string) istiolisters.VirtualServiceNamespaceLister
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InduceFailure ¶
func InduceFailure(verb, resource string) clientgotesting.ReactionFunc
InduceFailure is used in conjunction with TableTest's WithReactors field. Tests that want to induce a failure in a row of a TableTest would add:
WithReactors: []clientgotesting.ReactionFunc{ // Makes calls to create revisions return an error. InduceFailure("create", "revisions"), },
func KeyOrDie ¶
func KeyOrDie(obj interface{}) string
KeyOrDie returns the string key of the Kubernetes object or panics if a key cannot be generated.
func ValidateCreates ¶
func ValidateUpdates ¶
Types ¶
type BuildLister ¶
type BuildLister struct { Err error Items []*buildv1alpha1.Build }
BuildLister is a lister.BuildLister fake for testing.
func (*BuildLister) Builds ¶
func (r *BuildLister) Builds(namespace string) buildlisters.BuildNamespaceLister
func (*BuildLister) List ¶
func (r *BuildLister) List(selector labels.Selector) (results []*buildv1alpha1.Build, err error)
type ConfigMapLister ¶
ConfigMapLister is a lister.ConfigMapLister fake for testing.
func (*ConfigMapLister) ConfigMaps ¶
func (r *ConfigMapLister) ConfigMaps(namespace string) corev1listers.ConfigMapNamespaceLister
type ConfigurationLister ¶
type ConfigurationLister struct { Err error Items []*v1alpha1.Configuration }
ConfigurationLister is a lister.ConfigurationLister fake for testing.
func (*ConfigurationLister) Configurations ¶
func (r *ConfigurationLister) Configurations(namespace string) listers.ConfigurationNamespaceLister
func (*ConfigurationLister) List ¶
func (r *ConfigurationLister) List(selector labels.Selector) (results []*v1alpha1.Configuration, err error)
type CreateHookFunc ¶
type CreateHookFunc func(runtime.Object) HookResult
CreateHookFunc is a function for handling a Create hook. Its runtime.Object parameter will be the Kubernetes resource created. The resource can be cast to its actual type like this:
pod := obj.(*v1.Pod)
A return value of true marks the hook as completed. Returning false allows the hook to run again when the next resource of the requested type is created.
func ExpectNormalEventDelivery ¶
func ExpectNormalEventDelivery(t *testing.T, messageRegexp string) CreateHookFunc
ExpectNormalEventDelivery returns a hook function that can be passed to a Hooks.OnCreate() call to verify that an event of type Normal was created matching the given regular expression. For this expectation to be effective the test must also call Hooks.WaitForHooks().
func ExpectWarningEventDelivery ¶
func ExpectWarningEventDelivery(t *testing.T, messageRegexp string) CreateHookFunc
ExpectWarningEventDelivery returns a hook function that can be passed to a Hooks.OnCreate() call to verify that an event of type Warning was created matching the given regular expression. For this expectation to be effective the test must also call Hooks.WaitForHooks().
type Ctor ¶
type Ctor func(*Listers, controller.Options) controller.Interface
type DeleteHookFunc ¶
type DeleteHookFunc func(string) HookResult
DeleteHookFunc is a function for handling a delete hook. Its name parameter will be the name of the resource deleted. The resource itself is not available to the reactor.
type DeploymentLister ¶
type DeploymentLister struct { Err error Items []*appsv1.Deployment }
DeploymentLister is a lister.DeploymentLister fake for testing.
func (*DeploymentLister) Deployments ¶
func (r *DeploymentLister) Deployments(namespace string) appsv1listers.DeploymentNamespaceLister
func (*DeploymentLister) GetDeploymentsForReplicaSet ¶
func (r *DeploymentLister) GetDeploymentsForReplicaSet(rs *appsv1.ReplicaSet) (results []*appsv1.Deployment, err error)
func (*DeploymentLister) List ¶
func (r *DeploymentLister) List(selector labels.Selector) (results []*appsv1.Deployment, err error)
type EndpointsLister ¶
EndpointsLister is a lister.EndpointsLister fake for testing.
func (*EndpointsLister) Endpoints ¶
func (r *EndpointsLister) Endpoints(namespace string) corev1listers.EndpointsNamespaceLister
type HookResult ¶
type HookResult bool
HookResult is the return value of hook functions.
const ( // HookComplete indicates the hook function completed, and WaitForHooks should // not wait for it. HookComplete HookResult = true // HookIncomplete indicates the hook function is incomplete, and WaitForHooks // should wait for it to complete. HookIncomplete HookResult = false )
type Hooks ¶
type Hooks struct {
// contains filtered or unexported fields
}
Hooks is a utility struct that simplifies controller testing with fake clients. A Hooks struct allows attaching hook functions to actions (create, update, delete) on a specified resource type within a fake client and ensuring that all hooks complete in a timely manner.
Example ¶
h := NewHooks() f := fake.NewSimpleClientset() h.OnCreate(&f.Fake, "pods", func(obj runtime.Object) HookResult { pod := obj.(*v1.Pod) fmt.Printf("Pod %s has restart policy %v\n", pod.Name, pod.Spec.RestartPolicy) return true }) h.OnUpdate(&f.Fake, "pods", func(obj runtime.Object) HookResult { pod := obj.(*v1.Pod) fmt.Printf("Pod %s restart policy was updated to %v\n", pod.Name, pod.Spec.RestartPolicy) return true }) h.OnDelete(&f.Fake, "pods", func(name string) HookResult { fmt.Printf("Pod %s was deleted\n", name) return true }) pod := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "test-pod", }, Spec: v1.PodSpec{ RestartPolicy: v1.RestartPolicyAlways, }, } f.CoreV1().Pods("test").Create(pod) updatedPod := pod.DeepCopy() updatedPod.Spec.RestartPolicy = v1.RestartPolicyNever f.CoreV1().Pods("test").Update(updatedPod) f.CoreV1().Pods("test").Delete(pod.Name, &metav1.DeleteOptions{}) if err := h.WaitForHooks(time.Second); err != nil { log.Fatal(err) }
Output: Pod test-pod has restart policy Always Pod test-pod restart policy was updated to Never Pod test-pod was deleted
func NewHooks ¶
func NewHooks() *Hooks
NewHooks returns a Hooks struct that can be used to attach hooks to one or more fake clients and wait for all hooks to complete. TODO(grantr): Allow validating that a hook never fires
func (*Hooks) OnCreate ¶
func (h *Hooks) OnCreate(fake *kubetesting.Fake, resource string, rf CreateHookFunc)
OnCreate attaches a create hook to the given Fake. The hook function is executed every time a resource of the given type is created.
func (*Hooks) OnDelete ¶
func (h *Hooks) OnDelete(fake *kubetesting.Fake, resource string, rf DeleteHookFunc)
OnDelete attaches a delete hook to the given Fake. The hook function is executed every time a resource of the given type is deleted.
func (*Hooks) OnUpdate ¶
func (h *Hooks) OnUpdate(fake *kubetesting.Fake, resource string, rf UpdateHookFunc)
OnUpdate attaches an update hook to the given Fake. The hook function is executed every time a resource of the given type is updated.
type K8sServiceLister ¶
K8sServiceLister is a lister.ServiceLister fake for testing.
func (*K8sServiceLister) GetPodServices ¶
func (*K8sServiceLister) Services ¶
func (r *K8sServiceLister) Services(namespace string) corev1listers.ServiceNamespaceLister
type Listers ¶
type Listers struct { Service *ServiceLister Route *RouteLister Configuration *ConfigurationLister Revision *RevisionLister VirtualService *VirtualServiceLister Build *BuildLister Deployment *DeploymentLister K8sService *K8sServiceLister Endpoints *EndpointsLister ConfigMap *ConfigMapLister }
Listers holds the universe of objects that are available at the start of a reconciliation.
func NewListers ¶
func (*Listers) GetBuildLister ¶
func (f *Listers) GetBuildLister() *BuildLister
func (*Listers) GetBuildObjects ¶
func (*Listers) GetConfigMapLister ¶
func (f *Listers) GetConfigMapLister() *ConfigMapLister
func (*Listers) GetConfigurationLister ¶
func (f *Listers) GetConfigurationLister() *ConfigurationLister
func (*Listers) GetDeploymentLister ¶
func (f *Listers) GetDeploymentLister() *DeploymentLister
func (*Listers) GetEndpointsLister ¶
func (f *Listers) GetEndpointsLister() *EndpointsLister
func (*Listers) GetK8sServiceLister ¶
func (f *Listers) GetK8sServiceLister() *K8sServiceLister
func (*Listers) GetKubeObjects ¶
func (*Listers) GetRevisionLister ¶
func (f *Listers) GetRevisionLister() *RevisionLister
func (*Listers) GetRouteLister ¶
func (f *Listers) GetRouteLister() *RouteLister
func (*Listers) GetServiceLister ¶
func (f *Listers) GetServiceLister() *ServiceLister
func (*Listers) GetServingObjects ¶
func (*Listers) GetVirtualServiceLister ¶
func (f *Listers) GetVirtualServiceLister() *VirtualServiceLister
type RevisionLister ¶
RevisionLister is a lister.RevisionLister fake for testing.
func (*RevisionLister) Revisions ¶
func (r *RevisionLister) Revisions(namespace string) listers.RevisionNamespaceLister
type RouteLister ¶
RouteLister is a lister.RouteLister fake for testing.
func (*RouteLister) Routes ¶
func (r *RouteLister) Routes(namespace string) listers.RouteNamespaceLister
type ServiceLister ¶
ServiceLister is a lister.ServiceLister fake for testing.
func (*ServiceLister) Services ¶
func (r *ServiceLister) Services(namespace string) listers.ServiceNamespaceLister
type TableRow ¶
type TableRow struct { // Name is a descriptive name for this test suitable as a first argument to t.Run() Name string // Objects holds the state of the world at the onset of reconciliation. Objects []runtime.Object // Key is the parameter to reconciliation. // This has the form "namespace/name". Key string // WantErr holds whether we should expect the reconciliation to result in an error. WantErr bool // WantCreates holds the set of Create calls we expect during reconciliation. WantCreates []metav1.Object // WantUpdates holds the set of Update calls we expect during reconciliation. WantUpdates []clientgotesting.UpdateActionImpl // WantDeletes holds the set of Delete calls we expect during reconciliation. WantDeletes []clientgotesting.DeleteActionImpl // WantQueue is the set of keys we expect to be in the workqueue following reconciliation. WantQueue []string // WithReactors is a set of functions that are installed as Reactors for the execution // of this row of the table-driven-test. WithReactors []clientgotesting.ReactionFunc }
TableRow holds a single row of our table test.
type UpdateHookFunc ¶
type UpdateHookFunc func(runtime.Object) HookResult
UpdateHookFunc is a function for handling an update hook. its runtime.Object parameter will be the Kubernetes resource updated. The resource can be cast to its actual type like this:
pod := obj.(*v1.Pod)
A return value of true marks the hook as completed. Returning false allows the hook to run again when the next resource of the requested type is updated.
type VirtualServiceLister ¶
type VirtualServiceLister struct { Err error Items []*istiov1alpha3.VirtualService }
VirtualServiceLister is a istiolisters.VirtualServiceLister fake for testing.
func (*VirtualServiceLister) GetPodServices ¶
func (r *VirtualServiceLister) GetPodServices(p *corev1.Pod) (results []*istiov1alpha3.VirtualService, err error)
func (*VirtualServiceLister) List ¶
func (r *VirtualServiceLister) List(selector labels.Selector) (results []*istiov1alpha3.VirtualService, err error)
func (*VirtualServiceLister) VirtualServices ¶
func (r *VirtualServiceLister) VirtualServices(namespace string) istiolisters.VirtualServiceNamespaceLister