package
0.9.2
Repository: https://github.com/othomann/pipeline.git
Documentation: pkg.go.dev

# README

Builder package for tests

This package holds Builder functions that can be used to create struct in tests with less noise.

One of the most important characteristic of a unit test (and any type of test really) is readability. This means it should be easy to read but most importantly it should clearly show the intent of the test. The setup (and cleanup) of the tests should be as small as possible to avoid the noise. Those builders exists to help with that.

There is two types of functions defined in that package :

* *Builders*: create and return a struct
* *Modifiers*: return a function
  that will operate on a given struct. They can be applied to other
  Modifiers or Builders.

Most of the Builder (and Modifier) that accepts Modifiers defines a type (TypeOp) that can be satisfied by existing function in this package, from other package or inline. An example would be the following.

    // Definition
    type TaskRunOp func(*v1alpha1.TaskRun)
    func TaskRun(name, namespace string, ops ...TaskRunOp) *v1alpha1.TaskRun {
        // […]
    }
    func TaskRunOwnerReference(kind, name string) TaskRunOp {
        return func(t *v1alpha1.TaskRun) {
            // […]
        }
    }
    // Usage
    t := TaskRun("foo", "bar", func(t *v1alpha1.TaskRun){
        // Do something with the Task struct
        // […]
    })

The main reason to define the Op type, and using it in the methods signatures is to group Modifier function together. It makes it easier to see what is a Modifier (or Builder) and on what it operates.

By convention, this package is import with the "tb" as alias. The examples make that assumption.

Example

Let's look at a non-exhaustive example.

package builder_test

import (
    "fmt"
    "testing"

    "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
    tb "github.com/tektoncd/pipeline/test/builder"
    corev1 "k8s.io/api/core/v1"
)

func MyTest(t *testing.T) {
    // You can declare re-usable modifiers
    myStep := tb.Step("my-step", "myimage")
    // … and use them in a Task definition
    myTask := tb.Task("my-task", "namespace", tb.TaskSpec(
        tb.Step("simple-step", "myotherimage", tb.Command("/mycmd")),
        myStep,
    ))
    // … and another one.
    myOtherTask := tb.Task("my-other-task", "namespace",
        tb.TaskSpec(myStep,
            tb.TaskInputs(tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit)),
        ),
    )
    myClusterTask := tb.ClusterTask("my-task", tb.ClusterTaskSpec(
        tb.Step("simple-step", "myotherimage", tb.Command("/mycmd")),
    ))
    // A simple definition, with a Task reference
    myTaskRun := tb.TaskRun("my-taskrun", "namespace", tb.TaskRunSpec(
        tb.TaskRunTaskRef("my-task"),
    ))
    // … or a more complex one with inline TaskSpec
    myTaskRunWithSpec := tb.TaskRun("my-taskrun-with-spec", "namespace", tb.TaskRunSpec(
        tb.TaskRunInputs(
            tb.TaskRunInputsParam("myarg", "foo"),
            tb.TaskRunInputsResource("workspace", tb.TaskResourceBindingRef("git-resource")),
        ),
        tb.TaskRunTaskSpec(
            tb.TaskInputs(
                tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit),
                tb.InputsParam("myarg", tb.ParamDefault("mydefault")),
            ),
            tb.Step("mycontainer", "myimage", tb.Command("/mycmd"),
                tb.Args("--my-arg=$(inputs.params.myarg)"),
            ),
        ),
    ))
    // 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)
    }
    // […]
}

# Functions

Args sets the command arguments to the Container (step in this case).
ArrayOrString creates an ArrayOrString of type ParamTypeString or ParamTypeArray, based on how many inputs are given (>1 input will create an array, not string).
No description provided by the author
ClusterTask creates a ClusterTask with default values.
ClusterTaskSpec sets the specified spec of the cluster task.
Command sets the command to the Container (step in this case).
Condition creates a Condition with default values.
ConditionParamSpec adds a param, with specified name, to the Spec.
ConditionResource adds a resource with specified name, and type to the ConditionSpec.
ConditionSpec creates a ConditionSpec with default values.
ConditionSpecCheck adds a Container, with the specified name and image, to the Condition Spec Check.
No description provided by the author
CPU sets the CPU resource on the ResourceList.
EnvVar add an environment variable, with specified name and value, to the Container (step).
EphemeralStorage sets the ephemeral storage resource on the ResourceList.
From will update the provided PipelineTaskInputResource to indicate that it should come from tasks.
InputsParamSpec adds a ParamSpec, with specified name and type, to the Inputs.
InputsResource adds a resource, with specified name and type, to the Inputs.
Limits adds Limits to the ResourceRequirements.
Memory sets the memory resource on the ResourceList.
OutputsResource adds a resource, with specified name and type, to the Outputs.
OwnerReferenceAPIVersion sets the APIVersion to the OwnerReference.
ParamSpecDefault sets the default value of a ParamSpec.
ParamSpecDescription sets the description of a ParamSpec.
Pipeline creates a Pipeline with default values.
PipelineCreationTimestamp sets the creation time of the pipeline.
PipelineDeclaredResource adds a resource declaration to the Pipeline Spec, with the specified name and type.
PipelineParamSpec adds a param, with specified name and type, to the PipelineSpec.
PipelineResource creates a PipelineResource with default values.
PipelineResourceBindingRef set the ResourceRef name to the Resource called Name.
PipelineResourceBindingResourceSpec set the PipelineResourceResourceSpec to the PipelineResourceBinding.
PipelineResourceSpec set the PipelineResourceSpec, with specified type, to the PipelineResource.
PipelineResourceSpecParam adds a ResourceParam, with specified name and value, to the PipelineResourceSpec.
PipelineResourceSpecSecretParam adds a SecretParam, with specified fieldname, secretKey and secretName, to the PipelineResourceSpec.
PipelineRun creates a PipelineRun with default values.
PipelineRunAffinity sets the affinity to the PipelineSpec.
PipelineRunAnnotations adds a annotation to the PipelineRun.
PipelineRunCancelled sets the status to cancel to the TaskRunSpec.
PipelineRunCompletionTime sets the completion time to the PipelineRunStatus.
PipelineRunLabels adds a label to the PipelineRun.
PipelineRunNilTimeout sets the timeout to nil on the PipelineRunSpec.
PipelineRunNodeSelector sets the Node selector to the PipelineSpec.
PipelineRunParam add a param, with specified name and value, to the PipelineRunSpec.
PipelineRunResourceBinding adds bindings from actual instances to a Pipeline's declared resources.
PipelineRunServiceAccount sets the service account to the PipelineRunSpec.
PipelineRunServiceAccountTask configures the service account for given Task in PipelineRun.
PipelineRunSpec sets the PipelineRunSpec, references Pipeline with specified name, to the PipelineRun.
PipelineRunStartTime sets the start time to the PipelineRunStatus.
PipelineRunStatus sets the PipelineRunStatus to the PipelineRun.
PipelineRunStatusCondition adds a StatusCondition to the TaskRunStatus.
PipelineRunTaskRunsStatus sets the status of TaskRun to the PipelineRunStatus.
PipelineRunTimeout sets the timeout to the PipelineRunSpec.
PipelineRunTolerations sets the Node selector to the PipelineSpec.
PipelineSpec sets the PipelineSpec to the Pipeline.
PipelineTask adds a PipelineTask, with specified name and task name, to the PipelineSpec.
PipelineTaskCondition adds a condition to the PipelineTask with the specified conditionRef.
PipelineTaskConditionParam adds a parameter to a PipelineTaskCondition.
PipelineTaskConditionResource adds a resource to a PipelineTaskCondition.
PipelineTaskInputResource adds an input resource to the PipelineTask with the specified name, pointing at the declared resource.
PipelineTaskOutputResource adds an output resource to the PipelineTask with the specified name, pointing at the declared resource.
PipelineTaskParam adds a ResourceParam, with specified name and value, to the PipelineTask.
PipelineTaskRefKind sets the TaskKind to the PipelineTaskRef.
Pod creates a Pod with default values.
PodLabel adds an annotation to the Pod.
PodContainer adds a Container, with the specified name and image, to the PodSpec.
PodCreationTimestamp sets the creation time of the pod.
PodInitContainer adds an InitContainer, with the specified name and image, to the PodSpec.
PodLabel adds a label to the Pod.
PodName sets the Pod name to the TaskRunStatus.
PodOwnerReference adds an OwnerReference, with specified kind and name, to the Pod.
PodRestartPolicy sets the restart policy on the PodSpec.
PodServiceAccountName sets the service account on the PodSpec.
PodSpec creates a PodSpec with default values.
PodStatus creates a PodStatus with default values.
No description provided by the author
PodVolume sets the Volumes on the PodSpec.
Requests adds Requests to the ResourceRequirements.
ResolvedTaskResources creates a ResolvedTaskResources with default values.
ResolvedTaskResourcesInputs adds an input PipelineResource, with specified name, to the ResolvedTaskResources.
ResolvedTaskResourcesOutputs adds an output PipelineResource, with specified name, to the ResolvedTaskResources.
ResolvedTaskResourcesTaskSpec sets a TaskSpec to the ResolvedTaskResources.
Resources adds ResourceRequirements to the Container (step).
No description provided by the author
No description provided by the author
No description provided by the author
RunAfter will update the provided Pipeline Task to indicate that it should be run after the provided list of Pipeline Task names.
SetStepStateRunning sets Running state of a step.
SetStepStateTerminated sets Terminated state of a step.
SetStepStateWaiting sets Waiting state of a step.
No description provided by the author
StateTerminated sets Terminated to the StepState.
StatusCondition adds a StatusCondition to the TaskRunStatus.
Step adds a step with the specified name and image to the TaskSpec.
StepArgs sets the command arguments to the Container (step in this case).
StepCommand sets the command to the Container (step in this case).
StepCPU sets the CPU resource on the ResourceList.
StepEnvVar add an environment variable, with specified name and value, to the Container (step).
StepEphemeralStorage sets the ephemeral storage resource on the ResourceList.
StepLimits adds Limits to the ResourceRequirements.
StepMemory sets the memory resource on the ResourceList.
StepRequests adds Requests to the ResourceRequirements.
StepResources adds ResourceRequirements to the Container (step).
StepSecurityContext sets the SecurityContext to the Step.
StepState adds a StepState to the TaskRunStatus.
StepTerminationMessagePath sets the source of the termination message.
StepTerminationMessagePolicy sets the policy of the termination message.
StepVolumeMount add a VolumeMount to the Container (step).
StepWorkingDir sets the WorkingDir on the Container.
Task creates a Task with default values.
TaskInputs sets inputs to the TaskSpec.
TaskOutputs sets inputs to the TaskSpec.
TaskRefAPIVersion sets the specified api version to the TaskRef.
TaskRefKind set the specified kind to the TaskRef.
TaskResourceBindingPaths add any number of path to the TaskResourceBinding.
TaskResourceBindingRef set the PipelineResourceRef name to the TaskResourceBinding.
TaskResourceBindingRefAPIVersion set the PipelineResourceRef APIVersion to the TaskResourceBinding.
TaskResourceBindingResourceSpec set the PipelineResourceResourceSpec to the TaskResourceBinding.
TaskRun creates a TaskRun with default values.
TaskRunAffinity sets the Affinity to the TaskRunSpec.
No description provided by the author
TaskRunCancelled sets the status to cancel to the TaskRunSpec.
TaskRunCloudEvent adds an event to the TaskRunStatus.
TaskRunCompletionTime sets the start time to the TaskRunStatus.
TaskRunInputs sets inputs to the TaskRunSpec.
TaskRunInputsParam add a param, with specified name and value, to the TaskRunInputs.
TaskRunInputsResource adds a resource, with specified name, to the TaskRunInputs.
No description provided by the author
TaskRunNilTimeout sets the timeout duration to nil on the TaskRunSpec.
TaskRunNodeSelector sets the NodeSelector to the TaskRunSpec.
TaskRunOutputs sets inputs to the TaskRunSpec.
TaskRunOutputsResource adds a TaskResourceBinding, with specified name, to the TaskRunOutputs.
TaskRunOwnerReference sets the OwnerReference, with specified kind and name, to the TaskRun.
TaskRunPodSecurityContext sets the SecurityContext to the TaskRunSpec (through PodTemplate).
TaskRunSelfLink adds a SelfLink.
TaskRunServiceAccount sets the serviceAccount to the TaskRunSpec.
TaskRunSpec sets the specified spec of the TaskRun.
TaskRunSpecStatus sets the Status in the Spec, used for operations such as cancelling executing TaskRuns.
TaskRunStartTime sets the start time to the TaskRunStatus.
TaskRunStatus sets the TaskRunStatus to tshe TaskRun.
TaskRunTaskRef sets the specified Task reference to the TaskRunSpec.
TaskRunTaskSpec sets the specified TaskRunSpec reference to the TaskRunSpec.
TaskRunTimeout sets the timeout duration to the TaskRunSpec.
TaskRunTolerations sets the Tolerations to the TaskRunSpec.
TaskSpec sets the specified spec of the task.
TaskStepTemplate adds a base container for all steps in the task.
TaskVolume adds a volume with specified name to the TaskSpec.
TerminationMessagePolicy sets the policy of the termination message.
VolumeMount add a VolumeMount to the Container (step).
VolumeSource sets the VolumeSource to the Volume.
WorkingDir sets the WorkingDir on the Container.

# Type aliases

ClusterTaskOp is an operation which modify a ClusterTask struct.
ConditionOp is an operation which modifies a Condition struct.
ConditionSpecOp is an operation which modifies a ConditionSpec struct.
ContainerOp is an operation which modifies a Container struct.
InputsOp is an operation which modify an Inputs struct.
OutputsOp is an operation which modify an Outputs struct.
OwnerReferenceOp is an operation which modifies an OwnerReference struct.
ParamSpecOp is an operation which modify a ParamSpec struct.
PipelineOp is an operation which modify a Pipeline struct.
PipelineResourceBindingOp is an operation which modify a PipelineResourceBinding struct.
PipelineResourceOp is an operation which modify a PipelineResource struct.
PipelineResourceSpecOp is an operation which modify a PipelineResourceSpec struct.
PipelineRunOp is an operation which modify a PipelineRun struct.
PipelineRunSpecOp is an operation which modify a PipelineRunSpec struct.
PipelineRunStatusOp is an operation which modifies a PipelineRunStatus.
PipelineSpecOp is an operation which modify a PipelineSpec struct.
PipelineTaskConditionOp is an operation which modifies a PipelineTaskCondition.
PipelineTaskInputResourceOp is an operation which modifies a PipelineTaskInputResource.
PipelineTaskOp is an operation which modify a PipelineTask struct.
PodOp is an operation which modifies a Pod struct.
PodSpecOp is an operation which modifies a PodSpec struct.
PodStatusOp is an operation which modifies a PodStatus struct.
ResolvedTaskResourcesOp is an operation which modify a ResolvedTaskResources struct.
ResourceListOp is an operation which modifies a ResourceList struct.
ResourceRequirementsOp is an operation which modifies a ResourceRequirements struct.
StepOp is an operation which modifies a Container struct.
StepStateOp is an operation which modify a StepStep struct.
TaskOp is an operation which modify a Task struct.
TaskRefOp is an operation which modify a TaskRef struct.
TaskResourceBindingOp is an operation which modify a TaskResourceBinding struct.
TaskResourceOp is an operation which modify a TaskResource struct.
TaskRunInputsOp is an operation which modify a TaskRunInputs struct.
TaskRunOp is an operation which modify a TaskRun struct.
TaskRunOutputsOp is an operation which modify a TaskRunOutputs struct.
TaskRunSpecOp is an operation which modify a TaskRunSpec struct.
TaskRunStatusOp is an operation which modify a TaskRunStatus struct.
TaskSpeOp is an operation which modify a TaskSpec struct.
VolumeMountOp is an operation which modifies a VolumeMount struct.
VolumeOp is an operation which modify a Volume struct.