builder

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

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 and 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 are two types of functions defined in this package:

*Builders*: Create and return a struct
*Modifiers*: Return a function that will operate on a given struct.
    // Definition
    type TriggerBindingOp func(*v1alpha1.TriggerBinding)
    // Builder
    func TriggerBinding(name, namespace string, ops ...TriggerBindingOp) *v1alpha1.TriggerBinding {
        // […]
    }
    // Modifier
    func TriggerBindingSpec(ops ...TriggerBindingSpecOp) TriggerBindingOp {
        // […]
    }

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.

The go tests in this package exemplify the consolidation that can be achieved by using the builders:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventListener

func EventListener(name, namespace string, ops ...EventListenerOp) *v1alpha1.EventListener

EventListener creates an EventListener with default values. Any number of EventListenerOp modifiers can be passed to transform it.

func Trigger

func Trigger(tbName, ttName, apiVersion string, ops ...EventListenerTriggerOp) v1alpha1.EventListenerTrigger

Trigger creates an EventListenerTrigger. Any number of EventListenerTriggerOp modifiers can be passed to create/modify it. For an empty TriggerBinding name, the pointer is left nil.

func TriggerBinding

func TriggerBinding(name, namespace string, ops ...TriggerBindingOp) *v1alpha1.TriggerBinding

TriggerBinding creates a TriggerBinding with default values. Any number of TriggerBinding modifiers can be passed.

func TriggerTemplate

func TriggerTemplate(name, namespace string, ops ...TriggerTemplateOp) *v1alpha1.TriggerTemplate

TriggerTemplate creates a TriggerTemplate with default values. Any number of TriggerTemplate modifiers can be passed.

Types

type EventInterceptorOp

type EventInterceptorOp func(*v1alpha1.EventInterceptor)

EventInterceptorOp is an operation which modifies the EventInterceptor.

func EventInterceptorParam

func EventInterceptorParam(name, value string) EventInterceptorOp

EventInterceptorParam adds a parameter to the EventInterceptor.

type EventListenerOp

type EventListenerOp func(*v1alpha1.EventListener)

EventListenerOp is an operation which modifies the EventListener.

func EventListenerMeta

func EventListenerMeta(ops ...MetaOp) EventListenerOp

EventListenerMeta sets the Meta structs of the EventListener. Any number of MetaOp modifiers can be passed.

func EventListenerSpec

func EventListenerSpec(ops ...EventListenerSpecOp) EventListenerOp

EventListenerSpec sets the specified spec of the EventListener. Any number of EventListenerSpecOp modifiers can be passed to create/modify it.

func EventListenerStatus

func EventListenerStatus(ops ...EventListenerStatusOp) EventListenerOp

EventListenerStatus sets the specified status of the EventListener. Any number of EventListenerStatusOp modifiers can be passed to create/modify it.

type EventListenerSpecOp

type EventListenerSpecOp func(*v1alpha1.EventListenerSpec)

EventListenerSpecOp is an operation which modifies the EventListenerSpec.

func EventListenerServiceAccount

func EventListenerServiceAccount(saName string) EventListenerSpecOp

EventListenerServiceAccount sets the specified ServiceAccount of the EventListener.

func EventListenerTrigger

func EventListenerTrigger(tbName, ttName, apiVersion string, ops ...EventListenerTriggerOp) EventListenerSpecOp

EventListenerTrigger adds an EventListenerTrigger to the EventListenerSpec Triggers. Any number of EventListenerTriggerOp modifiers can be passed to create/modify it.

type EventListenerStatusOp

type EventListenerStatusOp func(*v1alpha1.EventListenerStatus)

EventListenerStatusOp is an operation which modifies the EventListenerStatus.

func EventListenerAddress

func EventListenerAddress(hostname string) EventListenerStatusOp

EventListenerAddress sets the EventListenerAddress on the EventListenerStatus

func EventListenerCondition

func EventListenerCondition(t apis.ConditionType, status corev1.ConditionStatus, message, reason string) EventListenerStatusOp

EventListenerCondition sets the specified condition on the EventListenerStatus.

func EventListenerConfig

func EventListenerConfig(generatedResourceName string) EventListenerStatusOp

EventListenerConfig sets the EventListenerConfiguration on the EventListenerStatus.

type EventListenerTriggerOp

type EventListenerTriggerOp func(*v1alpha1.EventListenerTrigger)

EventListenerTriggerOp is an operation which modifies the Trigger.

func EventListenerTriggerInterceptor

func EventListenerTriggerInterceptor(name, version, kind, namespace string, ops ...EventInterceptorOp) EventListenerTriggerOp

EventListenerTriggerInterceptor adds an objectRef to an interceptor Service to the EventListenerTrigger.

func EventListenerTriggerName

func EventListenerTriggerName(name string) EventListenerTriggerOp

EventListenerTriggerName adds a Name to the Trigger in EventListenerSpec Triggers.

func EventListenerTriggerParam

func EventListenerTriggerParam(name, value string) EventListenerTriggerOp

EventListenerTriggerParam adds a param to the EventListenerTrigger

type MetaOp

type MetaOp interface{}

MetaOp is an interface that is used in other builders. Other builders should have a Meta function that accepts ...MetaOp where ObjectMetaOp/TypeMetaOp are the underlying type.

type ObjectMetaOp

type ObjectMetaOp func(m *metav1.ObjectMeta)

ObjectMetaOp is an operation which modifies the ObjectMeta.

func Label

func Label(key, value string) ObjectMetaOp

Label adds a single label to the ObjectMeta.

type TriggerBindingOp

type TriggerBindingOp func(*v1alpha1.TriggerBinding)

TriggerBindingOp is an operation which modifies the TriggerBinding.

func TriggerBindingMeta

func TriggerBindingMeta(ops ...MetaOp) TriggerBindingOp

TriggerBindingMeta sets the Meta structs of the TriggerBinding. Any number of MetaOp modifiers can be passed.

func TriggerBindingSpec

func TriggerBindingSpec(ops ...TriggerBindingSpecOp) TriggerBindingOp

TriggerBindingSpec sets the specified spec of the TriggerBinding. Any number of TriggerBindingSpecOp modifiers can be passed.

type TriggerBindingSpecOp

type TriggerBindingSpecOp func(*v1alpha1.TriggerBindingSpec)

TriggerBindingSpecOp is an operation which modifies the TriggerBindingSpec.

func TriggerBindingParam

func TriggerBindingParam(name, value string) TriggerBindingSpecOp

TriggerBindingParam adds a param to the TriggerBindingSpec.

type TriggerTemplateOp

type TriggerTemplateOp func(*v1alpha1.TriggerTemplate)

TriggerTemplateOp is an operation which modifies an TriggerTemplate struct.

func TriggerTemplateMeta

func TriggerTemplateMeta(ops ...MetaOp) TriggerTemplateOp

TriggerTemplateMeta sets the Meta structs of the TriggerTemplate. Any number of MetaOp modifiers can be passed.

func TriggerTemplateSpec

func TriggerTemplateSpec(ops ...TriggerTemplateSpecOp) TriggerTemplateOp

TriggerTemplateSpec sets the TriggerTemplateSpec. Any number of TriggerTemplate modifiers can be passed.

type TriggerTemplateSpecOp

type TriggerTemplateSpecOp func(*v1alpha1.TriggerTemplateSpec)

TriggerTemplateSpecOp is an operation which modifies a TriggerTemplateSpec struct.

func TriggerResourceTemplate

func TriggerResourceTemplate(resourceTemplate json.RawMessage) TriggerTemplateSpecOp

TriggerResourceTemplate adds a ResourceTemplate to the TriggerTemplateSpec.

func TriggerTemplateParam

func TriggerTemplateParam(name, description, defaultValue string) TriggerTemplateSpecOp

TriggerTemplateParam adds a ParamSpec to the TriggerTemplateSpec.

type TypeMetaOp

type TypeMetaOp func(m *metav1.TypeMeta)

TypeMetaOp is an operation which modifies the TypeMeta.

func TypeMeta

func TypeMeta(kind, apiVersion string) TypeMetaOp

TypeMeta sets the TypeMeta struct with default values.

Jump to

Keyboard shortcuts

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