common

package
v0.10.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ClusterRoleKind = "ClusterRole"
	RoleKind        = "Role"
)
View Source
const DefaultChannel = resources.InMemoryChannelKind

DefaultChannel is the default channel we will run tests against.

View Source
const TestPullSecretName = "kn-eventing-test-pull-secret"

Variables

View Source
var ApiServerSourceTypeMeta = SourcesTypeMeta(resources.ApiServerSourceKind)

ApiServerSourceTypeMeta is the TypeMeta ref for ApiServerSource.

BrokerTypeMeta is the TypeMeta ref for Broker.

View Source
var ChannelFeatureMap = map[string][]Feature{
	resources.InMemoryChannelKind: {FeatureBasic},
}

ChannelFeatureMap saves the channel-features mapping. Each pair means the channel support the list of features.

ChannelTypeMeta is the TypeMeta ref for Channel.

View Source
var ContainerSourceTypeMeta = SourcesTypeMeta(resources.ContainerSourceKind)

ContainerSourceTypeMeta is the TypeMeta ref for ContainerSource.

CronJobSourceTypeMeta is the TypeMeta ref for CronJobSource.

ParallelTypeMeta is the TypeMeta ref for Parallel.

SequenceTypeMeta is the TypeMeta ref for Sequence.

SubscriptionTypeMeta is the TypeMeta ref for Subscription.

TriggerTypeMeta is the TypeMeta ref for Trigger.

Functions

func CheckerContains

func CheckerContains(content string) func(string) bool

CheckerContains returns a checker function to check if the log contains the given content.

func CheckerContainsAll

func CheckerContainsAll(contents []string) func(string) bool

CheckerContainsAll returns a checker function to check if the log contains all the given contents.

func CheckerContainsAtLeast

func CheckerContainsAtLeast(content string, count int) func(string) bool

CheckerContainsAtLeast returns a checker function to check if the log contains at least the count number of given content.

func CheckerContainsCount

func CheckerContainsCount(content string, count int) func(string) bool

CheckerContainsCount returns a checker function to check if the log contains the count number of given content.

func CopySecret added in v0.10.0

func CopySecret(client *Client, srcNS string, srcSecretName string, tgtNS string, svcAccount string) (*corev1.Secret, error)

CopySecret will copy a secret from one namespace into another. If a ServiceAccount name is provided then it'll add it as a PullSecret to it. It'll either return a pointer to the new Secret or and error indicating why it couldn't do it.

func CreateNamespaceIfNeeded

func CreateNamespaceIfNeeded(t *testing.T, client *Client, namespace string)

CreateNamespaceIfNeeded creates a new namespace if it does not exist.

func DeleteNameSpace

func DeleteNameSpace(client *Client) error

DeleteNameSpace deletes the namespace that has the given name.

func EventingTypeMeta

func EventingTypeMeta(kind string) *metav1.TypeMeta

EventingTypeMeta returns the TypeMeta ref for an eventing resource.

func GetChannelTypeMeta

func GetChannelTypeMeta(channelKind string) *metav1.TypeMeta

GetChannelTypeMeta gets the actual typemeta of the typed channel.

func LogPodLogsForDebugging

func LogPodLogsForDebugging(client *Client, podName, containerName string)

LogPodLogsForDebugging add the pod logs in the testing log for further debugging.

func MessagingTypeMeta

func MessagingTypeMeta(kind string) *metav1.TypeMeta

MessagingTypeMeta returns the TypeMeta ref for an eventing messaing resource.

func SourcesTypeMeta

func SourcesTypeMeta(kind string) *metav1.TypeMeta

SourcesTypeMeta returns the TypeMeta ref for an eventing sources resource.

func TearDown

func TearDown(client *Client)

TearDown will delete created names using clients.

func WithService

func WithService(name string) func(*corev1.Pod, *Client) error

WithService returns an option that creates a Service binded with the given pod.

Types

type ChannelTestRunner added in v0.9.0

type ChannelTestRunner struct {
	ChannelFeatureMap map[string][]Feature
	ChannelsToTest    []string
}

ChannelTestRunner is used to run tests against channels.

func (*ChannelTestRunner) RunTests added in v0.9.0

func (tr *ChannelTestRunner) RunTests(
	t *testing.T,
	feature Feature,
	testFunc func(st *testing.T, channel string),
)

RunTests will use all channels that support the given feature, to run a test for the testFunc.

type Client

type Client struct {
	Kube     *test.KubeClient
	Eventing *eventing.Clientset
	Dynamic  dynamic.Interface

	Namespace string
	T         *testing.T
	Tracker   *Tracker
	// contains filtered or unexported fields
}

Client holds instances of interfaces for making requests to Knative.

func NewClient

func NewClient(configPath string, clusterName string, namespace string, t *testing.T) (*Client, error)

NewClient instantiates and returns several clientsets required for making request to the cluster specified by the combination of clusterName and configPath.

func Setup

func Setup(t *testing.T, runInParallel bool) *Client

Setup creates the client objects needed in the e2e tests, and does other setups, like creating namespaces, set the test case to run in parallel, etc.

func (*Client) CheckLog

func (client *Client) CheckLog(podName string, checker func(string) bool) error

CheckLog waits until logs for the logger Pod satisfy the checker. If the checker does not pass within timeout it returns error.

func (*Client) CheckLogEmpty added in v0.9.0

func (client *Client) CheckLogEmpty(podName string, timeout time.Duration) error

CheckLogEmpty waits the given amount of time and check the log is empty

func (*Client) CreateApiServerSourceOrFail

func (client *Client) CreateApiServerSourceOrFail(apiServerSource *sourcesv1alpha1.ApiServerSource)

CreateApiServerSourceOrFail will create an ApiServerSource

func (*Client) CreateBrokerOrFail

func (client *Client) CreateBrokerOrFail(name string, channelTypeMeta *metav1.TypeMeta) *v1alpha1.Broker

CreateBrokerOrFail will create a Broker or fail the test if there is an error.

func (*Client) CreateBrokersOrFail

func (client *Client) CreateBrokersOrFail(names []string, channelTypeMeta *metav1.TypeMeta)

CreateBrokersOrFail will create a list of Brokers.

func (*Client) CreateChannelOrFail

func (client *Client) CreateChannelOrFail(name string, channelTypeMeta *metav1.TypeMeta)

CreateChannelOrFail will create a typed Channel Resource in Eventing or fail the test if there is an error.

func (*Client) CreateChannelWithDefaultOrFail added in v0.9.0

func (client *Client) CreateChannelWithDefaultOrFail(channel *messagingv1alpha1.Channel)

CreateChannelWithDefaultOrFail will create a default Channel Resource in Eventing or fail the test if there is an error.

func (*Client) CreateChannelsOrFail

func (client *Client) CreateChannelsOrFail(names []string, channelTypeMeta *metav1.TypeMeta)

CreateChannelsOrFail will create a list of typed Channel Resources in Eventing or fail the test if there is an error.

func (*Client) CreateClusterRoleBindingOrFail

func (client *Client) CreateClusterRoleBindingOrFail(saName, crName, crbName string)

CreateClusterRoleBindingOrFail will create a ClusterRoleBinding or fail the test if there is an error.

func (*Client) CreateClusterRoleOrFail

func (client *Client) CreateClusterRoleOrFail(cr *rbacv1.ClusterRole)

CreateClusterRoleOrFail creates the given ClusterRole or fail the test if there is an error.

func (*Client) CreateContainerSourceOrFail

func (client *Client) CreateContainerSourceOrFail(containerSource *sourcesv1alpha1.ContainerSource)

CreateContainerSourceOrFail will create a ContainerSource or fail the test if there is an error.

func (*Client) CreateCronJobSourceOrFail

func (client *Client) CreateCronJobSourceOrFail(cronJobSource *sourcesv1alpha1.CronJobSource)

CreateCronJobSourceOrFail will create a CronJobSource or fail the test if there is an error.

func (*Client) CreateParallelOrFail added in v0.9.0

func (client *Client) CreateParallelOrFail(parallel *messagingv1alpha1.Parallel)

CreateParallelOrFail will create a Parallel or fail the test if there is an error.

func (*Client) CreatePodOrFail

func (client *Client) CreatePodOrFail(pod *corev1.Pod, options ...func(*corev1.Pod, *Client) error)

CreatePodOrFail will create a Pod or fail the test if there is an error.

func (*Client) CreateRBACResourcesForBrokers

func (client *Client) CreateRBACResourcesForBrokers()

CreateRBACResourcesForBrokers creates required RBAC resources for creating Brokers, see https://github.com/knative/docs/blob/master/docs/eventing/broker-trigger.md - Manual Setup.

func (*Client) CreateRoleBindingOrFail

func (client *Client) CreateRoleBindingOrFail(saName, rKind, rName, rbName, rbNamespace string)

CreateRoleBindingOrFail will create a RoleBinding or fail the test if there is an error.

func (*Client) CreateRoleOrFail added in v0.10.0

func (client *Client) CreateRoleOrFail(r *rbacv1.Role)

CreateRoleOrFail creates the given Role in the Client namespace or fail the test if there is an error.

func (*Client) CreateSequenceOrFail added in v0.8.0

func (client *Client) CreateSequenceOrFail(sequence *messagingv1alpha1.Sequence)

CreateSequenceOrFail will create a Sequence or fail the test if there is an error.

func (*Client) CreateServiceAccountOrFail

func (client *Client) CreateServiceAccountOrFail(saName string)

CreateServiceAccountOrFail will create a ServiceAccount or fail the test if there is an error.

func (*Client) CreateSubscriptionOrFail

func (client *Client) CreateSubscriptionOrFail(
	name, channelName string,
	channelTypeMeta *metav1.TypeMeta,
	options ...resources.SubscriptionOption,
)

CreateSubscriptionOrFail will create a Subscription or fail the test if there is an error.

func (*Client) CreateSubscriptionsOrFail

func (client *Client) CreateSubscriptionsOrFail(
	names []string,
	channelName string,
	channelTypeMeta *metav1.TypeMeta,
	options ...resources.SubscriptionOption,
)

CreateSubscriptionsOrFail will create a list of Subscriptions with the same configuration except the name.

func (*Client) CreateTriggerOrFail

func (client *Client) CreateTriggerOrFail(name string, options ...resources.TriggerOption) *v1alpha1.Trigger

CreateTriggerOrFail will create a Trigger or fail the test if there is an error.

func (*Client) FindAnyLogContents

func (client *Client) FindAnyLogContents(podName string, contents []string) (bool, error)

FindAnyLogContents attempts to find logs for given Pod/Container that has 'any' of the given contents. It returns an error if it couldn't retrieve the logs. In case 'any' of the contents are there, it returns true.

func (*Client) GetAddressableURI

func (client *Client) GetAddressableURI(addressableName string, typeMeta *metav1.TypeMeta) (string, error)

GetAddressableURI returns the URI of the addressable resource. To use this function, the given resource must have implemented the Addressable duck-type.

func (*Client) GetLog added in v0.10.0

func (client *Client) GetLog(podName string) (string, error)

GetLog gets the logs from the given Pod in the namespace of this client. It will get the logs from the first container, whichever it is.

func (*Client) LabelNamespace

func (client *Client) LabelNamespace(labels map[string]string) error

LabelNamespace labels the given namespace with the labels map.

func (*Client) SendFakeEventToAddressable

func (client *Client) SendFakeEventToAddressable(
	senderName,
	addressableName string,
	typemeta *metav1.TypeMeta,
	event *resources.CloudEvent,
) error

SendFakeEventToAddressable will send the given event to the given Addressable.

func (*Client) SendFakeEventWithTracingToAddressable added in v0.9.0

func (client *Client) SendFakeEventWithTracingToAddressable(
	senderName,
	addressableName string,
	typemeta *metav1.TypeMeta,
	event *resources.CloudEvent,
) error

SendFakeEventWithTracingToAddressable will send the given event with tracing to the given Addressable.

func (*Client) WaitForAllTestResourcesReady

func (client *Client) WaitForAllTestResourcesReady() error

WaitForAllTestResourcesReady waits until all test resources in the namespace are Ready.

func (*Client) WaitForResourceReady

func (client *Client) WaitForResourceReady(name string, typemeta *metav1.TypeMeta) error

WaitForResourceReady waits for the resource to become ready. To use this function, the given resource must have implemented the Status duck-type.

func (*Client) WaitForResourcesReady

func (client *Client) WaitForResourcesReady(typemeta *metav1.TypeMeta) error

WaitForResourcesReady waits for resources of the given type in the namespace to become ready. To use this function, the given resource must have implemented the Status duck-type.

type Feature

type Feature string

Feature is the feature supported by the channel.

const (
	// FeatureBasic is the feature that should be supported by all channels.
	FeatureBasic Feature = "basic"
	// FeatureRedelivery means if downstream rejects an event, that request will be attempted again.
	FeatureRedelivery Feature = "redelivery"
	// FeaturePersistence means if channel's Pod goes down, all events already ACKed by the channel
	// will persist and be retransmitted when the Pod restarts.
	FeaturePersistence Feature = "persistence"
)

type ResourceDeleter

type ResourceDeleter struct {
	Resource dynamic.ResourceInterface
	Name     string
}

ResourceDeleter holds the resource interface and name of resource to be cleaned

type Tracker

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

Tracker holds resources that need to be tracked during test execution. It includes: 1. KResources that need to check their Ready status; 2. All Kubernetes resources that need to be cleaned after test is done.

func NewTracker

func NewTracker(log logging.FormatLogger, client dynamic.Interface) *Tracker

NewTracker creates a new Tracker

func (*Tracker) Add

func (t *Tracker) Add(group string, version string, resource string, namespace string, name string)

Add will register a resource to be cleaned by the Clean function This function is generic enough so as to be able to register any resources Each resource is identified by: * group (e.g. serving.knative.dev) * version (e.g. v1alpha1) * resource's plural (e.g. routes) * namespace (use "" if the resource is not tied to any namespace) * actual name of the resource (e.g. myroute)

func (*Tracker) AddObj

func (t *Tracker) AddObj(obj kmeta.OwnerRefable)

AddObj will register a resource that implements OwnerRefable interface to be cleaned by the Clean function. It also register the resource for checking if its status is Ready. Note this function assumes all resources that implement kmeta.OwnerRefable are KResources.

func (*Tracker) Clean

func (t *Tracker) Clean(awaitDeletion bool) error

Clean will delete all registered resources

func (*Tracker) WaitForKResourcesReady

func (t *Tracker) WaitForKResourcesReady() error

WaitForKResourcesReady will wait for all registered KResources to become ready.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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