test

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

README

Test

This directory contains tests and testing docs for Knative Eventing.

Running unit tests

Use go test:

go test -v ./pkg/...

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

Presubmit tests

presubmit-tests.sh is the entry point for the end-to-end tests.

This script, and consequently, the e2e tests will be run before every code submission. You can run these tests manually with:

test/presubmit-tests.sh

Note that to run presubmit-tests.sh or e2e-tests.sh scripts, you need to have a running environment that meets the e2e test environment requirements

Running end-to-end tests

To run the e2e tests, 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
One test case

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

go test -v -tags=e2e -count=1 ./test/e2e -run ^TestKubernetesEvents$
Environment requirements

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

  1. kubetest installed:
    go get -u k8s.io/test-infra/kubetest
    
  2. [A running Knative Serving cluster.]
  3. A docker repo containing the test images

Simply run the ./test/e2e-tests.sh script. It will create a GKE cluster, install Knative Serving stack with Istio, upload test images to your Docker repo and run the end-to-end tests against the Knative Eventing built from source.

If you already have the *_OVERRIDE environment variables set, call the script with the --run-tests argument and it will use the cluster and run the tests. Note that this requires you to have Serving and Istio installed and configured to your particular configuration setup. Knative Eventing will still built and deployed from source.

Otherwise, calling this script without arguments will create a new cluster in project $PROJECT_ID, start Knative Serving and the eventing system, upload test images, run the tests and delete the cluster. In this case, it's required that $DOCKER_REPO_OVERRIDE points to a valid writable docker repo.

Test images

Building the test images

Note: this is only required when you run e2e tests locally with go test commands. Running tests throught 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 (
	CloudEventEncodingBinary     = "binary"
	CloudEventEncodingStructured = "structured"
)

Variables

View Source
var EventingFlags = initializeEventingFlags()

EventingFlags holds the command line flags specific to knative/eventing

Functions

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 CleanupOnInterrupt

func CleanupOnInterrupt(cleanup func(), logger *logging.BaseLogger)

CleanupOnInterrupt will execute the function cleanup if an interrupt signal is caught

func ClusterChannelProvisioner

func ClusterChannelProvisioner(name string) *corev1.ObjectReference

ClusterChannelProvisioner returns a ClusterChannelProvisioner for a given name

func ClusterRoleBinding

func ClusterRoleBinding(name string, namespace string, serviceAccount string, role string) *rbacv1.ClusterRoleBinding

ClusterRoleBinding returns ClusterRoleBinding for given subject and role

func Configuration

func Configuration(name string, namespace string, imagePath string) *servingv1alpha1.Configuration

Configuration returns a Configuration object in namespace with the name names.Config that uses the image specified by imagePath.

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 ImagePath added in v0.4.0

func ImagePath(name string) string

ImagePath returns an image path using the configured image repo and tag.

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 IsRevisionReady

func IsRevisionReady(r *servingv1alpha1.Revision) (bool, error)

IsRevisionReady will check the status conditions of the revision and return true if the revision is ready to serve traffic. It will return false if the status indicates a state other than deploying or being ready. It will also return false if the type of the condition is unexpected.

func IsRouteReady

func IsRouteReady(r *servingv1alpha1.Route) (bool, error)

IsRouteReady will check the status conditions of the route and return true if the route is ready.

func IsServiceReady

func IsServiceReady(s *servingv1alpha1.Service) (bool, error)

IsServiceReady will check the status conditions of the service and return true if the service is ready. This means that its configurations and routes have all reported 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 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 Route

func Route(name string, namespace string, configName string) *servingv1alpha1.Route

Route returns a Route object in namespace

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 ServiceAccount

func ServiceAccount(name string, namespace string) *corev1.ServiceAccount

ServiceAccount returns ServiceAccount object in given namespace

func SubscriberSpecForRoute

func SubscriberSpecForRoute(name string) *v1alpha1.SubscriberSpec

SubscriberSpecForRoute returns a SubscriberSpec for a given Knative Service.

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 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 WaitForRouteState

func WaitForRouteState(client servingclient.RouteInterface, name string, inState func(r *servingv1alpha1.Route) (bool, error), desc string) error

WaitForRouteState polls the status of the Route 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.

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.BaseLogger, 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
	Serving  *serving.Clientset
	Eventing *eventing.Clientset
	Dynamic  dynamic.Interface
}

Clients holds instances of interfaces for making requests to Knative.

func NewClients

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

NewClients instantiates and returns several clientsets required for making request to the cluster specified by the combination of clusterName and configPath. Clients can make requests within namespace.

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 {
	DockerRepo  string // Docker repo (defaults to $DOCKER_REPO_OVERRIDE)
	Tag         string // Tag for test images
	Provisioner string // The name of the Channel's ClusterChannelProvisioner
}

EventingEnvironmentFlags holds the e2e flags needed only by the eventing repo

type ResourceDeleter

type ResourceDeleter struct {
	Resource dynamic.ResourceInterface
	Name     string
}

ResourceDeleter holds the cleaner and name of resource to be cleaned

Directories

Path Synopsis
test_images

Jump to

Keyboard shortcuts

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