test

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

README

Test

This directory contains tests and testing docs for Knative Eventing.

Running tests with scripts

Presubmit tests

presubmit-tests.sh is the entry point for the tests before code submission.

You can run it simply with:

test/presubmit-tests.sh

By default, this script will run build tests, unit tests and integration tests. If you only want to run one type of tests, you can run this script with corresponding flags like below:

test/presubmit-tests.sh --build-tests
test/presubmit-tests.sh --unit-tests
test/presubmit-tests.sh --integration-tests

Note that if the tests you are running include integration tests, it will create a new GKE cluster in project $PROJECT_ID, start Knative Serving and Eventing system, upload test images to $KO_DOCKER_REPO, and run all e2e-*tests.sh scripts under test. After the tests finish, it will delete the cluster.

E2E tests

e2e-tests.sh is the entry point for running all e2e tests.

You can run it simply with:

test/e2e-tests.sh

By default, it will create a new GKE cluster in project $PROJECT_ID, start Knative Serving and Eventing system, upload test images to $KO_DOCKER_REPO, and run the end-to-end tests. After the tests finishes, it will delete the cluster.

If you have already created your own Kubernetes cluster but haven't installed Knative, you can run with test/e2e-tests.sh --run-tests.

If you have set up a running environment that meets the e2e test environment requirements, you can run with test/e2e-tests.sh --run-tests --skip-knative-setup.

Running tests with go test command

Running unit tests

You can also use go test command to run unit tests:

go test -v ./pkg/...

By default go test will not run the e2e tests, which needs -tags=e2e to be enabled.

Running end-to-end tests

To run the e2e tests with go test command, you need to have a running environment that meets the e2e test environment requirements, and you need to specify the build tag e2e.

go test -v -tags=e2e -count=1 ./test/e2e -run ^TestMain$ -runFromMain=true

By default, it will run all tests configured for the default ClusterChannelProvisioner in main_test.go.

If you want to run tests against other ClusterChannelProvisioners, you can specify them through -clusterChannelProvisioners.

go test -v -tags=e2e -count=1 ./test/e2e -run ^TestMain$ -runFromMain=true -clusterChannelProvisioners=in-memory-channel,gcp-pubsub
One test case

To run one e2e test case, e.g. TestSingleBinaryEvents, use the -run flag with go test:

go test -v -tags=e2e -count=1 ./test/e2e -run ^TestSingleBinaryEvent$

By default, it will run the test against the default ClusterChannelProvisioner.

If you want to run it against another ClusterChannelProvisioner, you can specify it through -clusterChannelProvisioners. Note that you can only specify one ClusterChannelProvisioner if you are not running from TestMain.

go test -v -tags=e2e -count=1 ./test/e2e -run ^TestSingleBinaryEvent$ -clusterChannelProvisioners=in-memory-channel

Environment requirements

There's couple of things you need to install before running e2e tests locally.

  1. A running Knative cluster
  2. A docker repo containing the test images

Test images

Building the test images

Note: this is only required when you run e2e tests locally with go test commands. Running tests through e2e-tests.sh will publish the images automatically.

The upload-test-images.sh script can be used to build and push the test images used by the e2e tests. It requires:

To run the script for all end to end test images:

./test/upload-test-images.sh e2e

A docker tag is mandatory to avoid issues with using latest tag for images deployed in GCR.

Adding new test images

New test images should be placed in ./test/test_images. For each image create a new sub-folder and include a Go file that will be an entry point to the application. This Go file should use the package main and include the function main(). It is a good practice to include a readme file as well. When uploading test images, ko will build an image from this folder.

Flags

Flags are similar to those in Knative Serving

Documentation

Index

Constants

View Source
const (
	// DefaultBrokerName is the name of the Broker that is automatically created after the current namespace is labeled.
	DefaultBrokerName = "default"
	// DefaultClusterChannelProvisioner is the default ClusterChannelProvisioner we will run tests against.
	DefaultClusterChannelProvisioner = InMemoryProvisioner

	// InMemoryChannelProvisioner is the in-memory-channel provisioner.
	// It will be delete in 0.7, see https://github.com/knative/eventing/pull/1062 for more info.
	InMemoryChannelProvisioner = "in-memory-channel"

	// InMemoryProvisioner is the in-memory provisioner, which is also the default one.
	InMemoryProvisioner = "in-memory"
	// GCPPubSubProvisioner is the gcp-pubsub provisioner, which is under contrib/gcppubsub.
	GCPPubSubProvisioner = "gcp-pubsub"
	// KafkaProvisioner is the kafka provisioner, which is under contrib/kafka.
	KafkaProvisioner = "kafka"
	// NatssProvisioner is the natss provisioner, which is under contrib/natss
	NatssProvisioner = "natss"
)
View Source
const (
	CloudEventEncodingBinary     = "binary"
	CloudEventEncodingStructured = "structured"
	CloudEventDefaultEncoding    = CloudEventEncodingBinary
	CloudEventDefaultType        = "dev.knative.test.event"
)

CloudEvent related constants.

Variables

View Source
var EventingFlags = initializeEventingFlags()

EventingFlags holds the command line flags specific to knative/eventing.

Functions

func Broker added in v0.5.0

func Broker(name, namespace string, provisioner *corev1.ObjectReference) *v1alpha1.Broker

Broker returns a Broker.

func Channel

func Channel(name string, namespace string, provisioner *corev1.ObjectReference) *v1alpha1.Channel

Channel returns a Channel with the specified provisioner.

func ChannelRef

func ChannelRef(name string) *corev1.ObjectReference

ChannelRef returns an ObjectReference for a given Channel Name.

func ClusterChannelProvisioner

func ClusterChannelProvisioner(name string) *corev1.ObjectReference

ClusterChannelProvisioner returns a ClusterChannelProvisioner for a given name.

func EventLoggerPod added in v0.4.0

func EventLoggerPod(name string, namespace string, selector map[string]string) *corev1.Pod

EventLoggerPod creates a Pod that logs events received.

func EventSenderPod added in v0.4.0

func EventSenderPod(name string, namespace string, sink string, event *CloudEvent) *corev1.Pod

EventSenderPod creates a Pod that sends a single event to the given address.

func EventTransformationPod added in v0.6.0

func EventTransformationPod(name string, namespace string, selector map[string]string, event *CloudEvent) *corev1.Pod

EventTransformationPod creates a Pod that transforms events received.

func IsBrokerReady added in v0.5.0

func IsBrokerReady(b *eventingv1alpha1.Broker) (bool, error)

IsBrokerReady will check the status conditions of the Broker and return true if the Broker is ready.

func IsChannelReady added in v0.4.0

func IsChannelReady(c *eventingv1alpha1.Channel) (bool, error)

IsChannelReady will check the status conditions of the Channel and return true if the Channel is ready.

func IsSubscriptionReady added in v0.4.0

func IsSubscriptionReady(s *eventingv1alpha1.Subscription) (bool, error)

IsSubscriptionReady will check the status conditions of the Subscription and return true if the Subscription is ready.

func IsTriggerReady added in v0.5.0

func IsTriggerReady(t *eventingv1alpha1.Trigger) (bool, error)

IsTriggerReady will check the status conditions of the Trigger and return true if the Trigger is ready.

func PodsRunning

func PodsRunning(podList *corev1.PodList) (bool, error)

PodsRunning will check the status conditions of the pod list and return true if all pods are Running.

func ReplyStrategyForChannel added in v0.6.0

func ReplyStrategyForChannel(name string) *v1alpha1.ReplyStrategy

ReplyStrategyForChannel returns a ReplyStrategy for a given Channel.

func Service added in v0.4.0

func Service(name string, namespace string, selector map[string]string) *corev1.Service

Service creates a Kubernetes Service with the given name, namespace, and selector. Port 8080 is assumed the target port.

func SubscriberSpecForService added in v0.4.0

func SubscriberSpecForService(name string) *v1alpha1.SubscriberSpec

SubscriberSpecForService returns a SubscriberSpec for a given Knative Service.

func Subscription

func Subscription(name string, namespace string, channel *corev1.ObjectReference, subscriber *v1alpha1.SubscriberSpec, reply *v1alpha1.ReplyStrategy) *v1alpha1.Subscription

Subscription returns a Subscription.

func TriggersReady added in v0.5.0

func TriggersReady(triggerList *eventingv1alpha1.TriggerList) (bool, error)

TriggersReady will check the status conditions of the trigger list and return true if all triggers are Ready.

func WaitForBrokerState added in v0.5.0

func WaitForBrokerState(client eventingclient.BrokerInterface, name string, inState func(r *eventingv1alpha1.Broker) (bool, error), desc string) error

WaitForBrokerState polls the status of the Broker 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 WaitForChannelState added in v0.4.0

func WaitForChannelState(client eventingclient.ChannelInterface, name string, inState func(r *eventingv1alpha1.Channel) (bool, error), desc string) error

WaitForChannelState polls the status of the Channel 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 WaitForSubscriptionState added in v0.4.0

func WaitForSubscriptionState(client eventingclient.SubscriptionInterface, name string, inState func(r *eventingv1alpha1.Subscription) (bool, error), desc string) error

WaitForSubscriptionState polls the status of the Subscription 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 WaitForTriggerState added in v0.5.0

func WaitForTriggerState(client eventingclient.TriggerInterface, name string, inState func(r *eventingv1alpha1.Trigger) (bool, error), desc string) error

WaitForTriggerState polls the status of the Trigger 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 WaitForTriggersListState added in v0.5.0

func WaitForTriggersListState(clients eventingclient.TriggerInterface, inState func(t *eventingv1alpha1.TriggerList) (bool, error), desc string) error

WaitForTriggersListState polls the status of the TriggerList 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 to get into the state checked by inState.

Types

type Cleaner

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

Cleaner holds resources that will be cleaned after test

func NewCleaner

func NewCleaner(log logging.FormatLogger, client dynamic.Interface) *Cleaner

NewCleaner creates a new Cleaner

func (*Cleaner) Add

func (c *Cleaner) Add(group string, version string, resource string, namespace string, name string) error

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 (*Cleaner) Clean

func (c *Cleaner) Clean(awaitDeletion bool) error

Clean will delete all registered resources

type Clients

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

Clients holds instances of interfaces for making requests to Knative.

func NewClients

func NewClients(configPath string, clusterName string) (*Clients, error)

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

type CloudEvent added in v0.4.0

type CloudEvent struct {
	ID       string
	Type     string
	Source   string
	Data     string
	Encoding string // binary or structured
}

CloudEvent specifies the arguments for a CloudEvent sent by the sendevent binary.

type EventingEnvironmentFlags

type EventingEnvironmentFlags struct {
	Provisioners
	RunFromMain bool
}

EventingEnvironmentFlags holds the e2e flags needed only by the eventing repo.

type Provisioners added in v0.6.0

type Provisioners []string

Provisioners holds the ClusterChannelProvisioners we want to run test against.

func (*Provisioners) Set added in v0.6.0

func (ps *Provisioners) Set(value string) error

Set converts the input string to Provisioners. The default CCP we will test against is in-memory.

func (*Provisioners) String added in v0.6.0

func (ps *Provisioners) String() string

type ResourceDeleter

type ResourceDeleter struct {
	Resource dynamic.ResourceInterface
	Name     string
}

ResourceDeleter holds the cleaner and name of resource to be cleaned

type TriggerBuilder added in v0.5.0

type TriggerBuilder struct {
	*eventingv1alpha1.Trigger
}

TriggerBuilder is the builder for trigger objects.

func NewTriggerBuilder added in v0.5.0

func NewTriggerBuilder(name, namespace string) *TriggerBuilder

func (*TriggerBuilder) Broker added in v0.5.0

func (b *TriggerBuilder) Broker(brokerName string) *TriggerBuilder

func (*TriggerBuilder) Build added in v0.5.0

func (*TriggerBuilder) EventSource added in v0.5.0

func (b *TriggerBuilder) EventSource(eventSource string) *TriggerBuilder

func (*TriggerBuilder) EventType added in v0.5.0

func (b *TriggerBuilder) EventType(eventType string) *TriggerBuilder

func (*TriggerBuilder) SubscriberSvc added in v0.5.0

func (b *TriggerBuilder) SubscriberSvc(svcName string) *TriggerBuilder

type TypeAndSource added in v0.5.0

type TypeAndSource struct {
	Type   string
	Source string
}

TypeAndSource specifies the type and source of an Event.

Directories

Path Synopsis
test_images

Jump to

Keyboard shortcuts

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