test

package
v0.0.0-...-1a72938 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 53 Imported by: 0

Documentation

Overview

Get access to client objects

To initialize client objects you can use the setup function. It returns a clients struct that contains initialized clients for accessing:

For example, to create a Pipeline

_, err = clients.PipelineClient.Pipelines.Create(test.Pipeline(namespaceName, pipelineName))

And you can use the client to clean up resources created by your test

func tearDown(clients *test.Clients) {
    if clients != nil {
        clients.Delete([]string{routeName}, []string{configName})
    }
}

Poll Pipeline resources

After creating Pipeline resources or making changes to them, you will need to wait for the system to realize those changes. You can use polling methods to check the resources reach the desired state.

The WaitFor* functions use the kubernetes wait package (https://godoc.org/k8s.io/apimachinery/pkg/util/wait). To poll they use PollImmediate (https://godoc.org/k8s.io/apimachinery/pkg/util/wait#PollImmediate) and the return values of the function you provide behave the same as ConditionFunc (https://godoc.org/k8s.io/apimachinery/pkg/util/wait#ConditionFunc): a boolean to indicate if the function should stop or continue polling, and an error to indicate if there has been an error.

For example, you can poll a TaskRun object to wait for it to have a Status.Condition:

err = WaitForTaskRunState(c, hwTaskRunName, func(tr *v1alpha1.TaskRun) (bool, error) {
	if len(tr.Status.Conditions) > 0 {
		return true, nil
	}
	return false, nil
}, "TaskRunHasCondition")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToInformer

func AddToInformer(t *testing.T, store cache.Store) func(ktesting.Action) (bool, runtime.Object, error)

func CollectPodLogs

func CollectPodLogs(ctx context.Context, c *clients, podName, namespace string, logf logging.FormatLogger)

CollectPodLogs will get the logs for all containers in a Pod

func PrependResourceVersionReactor

func PrependResourceVersionReactor(f *ktesting.Fake)

PrependResourceVersionReactor will instrument a client-go testing Fake with a reactor that simulates resourceVersion changes on mutations. This does not work with patches.

func SeedTestData

func SeedTestData(t *testing.T, ctx context.Context, d Data) (Clients, Informers)

SeedTestData returns Clients and Informers populated with the given Data. nolint: golint

func WaitForDeploymentState

func WaitForDeploymentState(ctx context.Context, c *clients, name string, namespace string, inState func(d *appsv1.Deployment) (bool, error), desc string) error

WaitForDeploymentState polls the status of the Deployment called name from client every interval until inState returns `true` indicating it is done, returns an error or timeout. desc will be used to name the metric that is emitted to track how long it took for name to get into the state checked by inState.

func WaitForPipelineRunState

func WaitForPipelineRunState(ctx context.Context, c *clients, name string, polltimeout time.Duration, inState ConditionAccessorFn, desc string) error

WaitForPipelineRunState polls the status of the PipelineRun called name from client every interval until inState returns `true` indicating it is done, returns an error or timeout. desc will be used to name the metric that is emitted to track how long it took for name to get into the state checked by inState.

func WaitForPodState

func WaitForPodState(ctx context.Context, c *clients, name string, namespace string, inState func(r *corev1.Pod) (bool, error), desc string) error

WaitForPodState polls the status of the Pod called name from client every interval until inState returns `true` indicating it is done, returns an error or timeout. desc will be used to name the metric that is emitted to track how long it took for name to get into the state checked by inState.

func WaitForRunState

func WaitForRunState(ctx context.Context, c *clients, name string, polltimeout time.Duration, inState ConditionAccessorFn, desc string) error

WaitForRunState polls the status of the Run called name from client every interval until inState returns `true` indicating it is done, returns an error or timeout. desc will be used to name the metric that is emitted to track how long it took for name to get into the state checked by inState.

func WaitForServiceExternalIPState

func WaitForServiceExternalIPState(ctx context.Context, c *clients, namespace, name string, inState func(s *corev1.Service) (bool, error), desc string) error

WaitForServiceExternalIPState polls the status of the a k8s Service called name from client every interval until an external ip is assigned indicating it is done, returns an error or timeout. desc will be used to name the metric that is emitted to track how long it took for name to get into the state checked by inState.

func WaitForTaskRunState

func WaitForTaskRunState(ctx context.Context, c *clients, name string, inState ConditionAccessorFn, desc string) error

WaitForTaskRunState polls the status of the TaskRun called name from client every interval until inState returns `true` indicating it is done, returns an error or timeout. desc will be used to name the metric that is emitted to track how long it took for name to get into the state checked by inState.

Types

type Assets

type Assets struct {
	Logger     *zap.SugaredLogger
	Controller *controller.Impl
	Clients    Clients
	Informers  Informers
	Recorder   *record.FakeRecorder
	Ctx        context.Context
}

Assets holds references to the controller, logs, clients, and informers.

type Clients

Clients holds references to clients which are useful for reconciler tests.

type ConditionAccessorFn

type ConditionAccessorFn func(ca apis.ConditionAccessor) (bool, error)

ConditionAccessorFn is a condition function used polling functions

func Failed

func Failed(name string) ConditionAccessorFn

Failed provides a poll condition function that checks if the ConditionAccessor resource has failed or not.

func FailedWithMessage

func FailedWithMessage(message, name string) ConditionAccessorFn

FailedWithMessage provides a poll function that checks if the ConditionAccessor resource has failed with the TimeoudOut reason

func FailedWithReason

func FailedWithReason(reason, name string) ConditionAccessorFn

FailedWithReason provides a poll function that checks if the ConditionAccessor resource has failed with the TimeoudOut reason

func PipelineRunFailed

func PipelineRunFailed(name string) ConditionAccessorFn

PipelineRunFailed provides a poll condition function that checks if the PipelineRun has failed.

func PipelineRunSucceed

func PipelineRunSucceed(name string) ConditionAccessorFn

PipelineRunSucceed provides a poll condition function that checks if the PipelineRun has successfully completed.

func Running

func Running(name string) ConditionAccessorFn

Running provides a poll condition function that checks if the ConditionAccessor resource is currently running.

func Succeed

func Succeed(name string) ConditionAccessorFn

Succeed provides a poll condition function that checks if the ConditionAccessor resource has successfully completed or not.

func TaskRunFailed

func TaskRunFailed(name string) ConditionAccessorFn

TaskRunFailed provides a poll condition function that checks if the TaskRun has failed.

func TaskRunSucceed

func TaskRunSucceed(name string) ConditionAccessorFn

TaskRunSucceed provides a poll condition function that checks if the TaskRun has successfully completed.

type Data

type Data struct {
	PipelineRuns      []*v1beta1.PipelineRun
	Pipelines         []*v1beta1.Pipeline
	TaskRuns          []*v1beta1.TaskRun
	Tasks             []*v1beta1.Task
	ClusterTasks      []*v1beta1.ClusterTask
	PipelineResources []*v1alpha1.PipelineResource
	Conditions        []*v1alpha1.Condition
	Runs              []*v1alpha1.Run
	Pods              []*corev1.Pod
	Namespaces        []*corev1.Namespace
	ConfigMaps        []*corev1.ConfigMap
	ServiceAccounts   []*corev1.ServiceAccount
}

Data represents the desired state of the system (i.e. existing resources) to seed controllers with.

type ResourceVersionReactor

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

func (*ResourceVersionReactor) Handles

func (r *ResourceVersionReactor) Handles(action ktesting.Action) bool

func (*ResourceVersionReactor) React

func (r *ResourceVersionReactor) React(action ktesting.Action) (handled bool, ret runtime.Object, err error)

React is noop-function

Jump to

Keyboard shortcuts

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