Documentation ¶
Overview ¶
Package test holds the project's test helpers and end-to-end tests (e2e).
Create Pipeline resources ¶
To create Tekton objects (e.g. Task, Pipeline, …), you can use the builder (./builder) package to reduce noise:
func MyTest(t *testing.T){ // Pipeline pipeline := tb.Pipeline("tomatoes", "namespace", tb.PipelineSpec(tb.PipelineTask("foo", "banana")), ) // … and PipelineRun pipelineRun := tb.PipelineRun("pear", "namespace", tb.PipelineRunSpec("tomatoes", tb.PipelineRunServiceAccount("inexistent")), ) // And do something with them // […] if _, err := c.PipelineClient.Create(pipeline); err != nil { t.Fatalf("Failed to create Pipeline `%s`: %s", "tomatoes", err) } if _, err := c.PipelineRunClient.Create(pipelineRun); err != nil { t.Fatalf("Failed to create PipelineRun `%s`: %s", "pear", err) } }
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:
- Kubernetes objects
- Pipelines (https://github.com/tektoncd/pipeline#pipeline)
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 ¶
- func CollectPodLogs(c *clients, podName, namespace string, logf logging.FormatLogger)
- func GetLogMessages(logs *observer.ObservedLogs) []string
- func SeedTestData(t *testing.T, d Data) (Clients, Informers)
- func WaitForPipelineRunState(c *clients, name string, polltimeout time.Duration, inState PipelineRunStateFn, ...) error
- func WaitForPodState(c *clients, name string, namespace string, ...) error
- func WaitForServiceExternalIPState(c *clients, namespace, name string, ...) error
- func WaitForTaskRunState(c *clients, name string, inState TaskRunStateFn, desc string) error
- type Clients
- type Data
- type Informers
- type PipelineRunStateFn
- type TaskRunStateFn
- type TestAssets
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectPodLogs ¶ added in v0.5.0
func CollectPodLogs(c *clients, podName, namespace string, logf logging.FormatLogger)
CollectPodLogs will get the logs for all containers in a Pod
func GetLogMessages ¶
func GetLogMessages(logs *observer.ObservedLogs) []string
GetLogMessages returns a list of all string logs in logs.
func SeedTestData ¶
SeedTestData returns Clients and Informers populated with the given Data.
func WaitForPipelineRunState ¶
func WaitForPipelineRunState(c *clients, name string, polltimeout time.Duration, inState PipelineRunStateFn, 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(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 WaitForServiceExternalIPState ¶
func WaitForServiceExternalIPState(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(c *clients, name string, inState TaskRunStateFn, 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 Clients ¶
type Clients struct { Pipeline *fakepipelineclientset.Clientset Kube *fakekubeclientset.Clientset }
Clients holds references to clients which are useful for reconciler tests.
type Data ¶
type Data struct { PipelineRuns []*v1alpha1.PipelineRun Pipelines []*v1alpha1.Pipeline TaskRuns []*v1alpha1.TaskRun Tasks []*v1alpha1.Task ClusterTasks []*v1alpha1.ClusterTask PipelineResources []*v1alpha1.PipelineResource Pods []*corev1.Pod Namespaces []*corev1.Namespace }
Data represents the desired state of the system (i.e. existing resources) to seed controllers with.
type Informers ¶
type Informers struct { PipelineRun informersv1alpha1.PipelineRunInformer Pipeline informersv1alpha1.PipelineInformer TaskRun informersv1alpha1.TaskRunInformer Task informersv1alpha1.TaskInformer ClusterTask informersv1alpha1.ClusterTaskInformer PipelineResource informersv1alpha1.PipelineResourceInformer Pod coreinformers.PodInformer }
Informers holds references to informers which are useful for reconciler tests.
type PipelineRunStateFn ¶
type PipelineRunStateFn func(pr *v1alpha1.PipelineRun) (bool, error)
PipelineRunStateFn is a condition function on TaskRun used polling functions
func PipelineRunFailed ¶
func PipelineRunFailed(name string) PipelineRunStateFn
PipelineRunFailed provides a poll condition function that checks if the PipelineRun has failed.
func PipelineRunSucceed ¶
func PipelineRunSucceed(name string) PipelineRunStateFn
PipelineRunSucceed provides a poll condition function that checks if the PipelineRun has successfully completed.
type TaskRunStateFn ¶
TaskRunStateFn is a condition function on TaskRun used polling functions
func TaskRunFailed ¶
func TaskRunFailed(name string) TaskRunStateFn
TaskRunFailed provides a poll condition function that checks if the TaskRun has failed.
func TaskRunSucceed ¶
func TaskRunSucceed(name string) TaskRunStateFn
TaskRunSucceed provides a poll condition function that checks if the TaskRun has successfully completed.
type TestAssets ¶
type TestAssets struct { Controller *controller.Impl Logs *observer.ObservedLogs Clients Clients Informers Informers }
TestAssets holds references to the controller, logs, clients, and informers.
Directories ¶
Path | Synopsis |
---|---|
Package builder holds Builder functions that can be used to create struct in tests with less noise.
|
Package builder holds Builder functions that can be used to create struct in tests with less noise. |