test

package
v0.0.0-...-ea02baa Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

README

Test

This directory contains tests and testing docs for Knative Serving:

If you want to add more tests, see adding_tests.md.

Running unit tests

go test -v ./pkg/...

Running conformance tests

To run the conformance tests, you need to have a running environment that meets the conformance test environment requirements.

Since these tests are fairly slow (~1 minute), running them with logging enabled is recommended.

To run the conformance tests against the current cluster in ~/.kube/config use go test with test caching disabled and the environment specified in your environment variables:

go test -v -count=1 ./test/conformance

You can use test flags to control the environment your tests run against, i.e. override your environment variables:

go test -v -count=1 ./test/conformance --kubeconfig ~/special/kubeconfig --cluster myspecialcluster --dockerrepo myspecialdockerrepo

If you are running against an environment with no loadbalancer for the ingress, at the moment your only option is to use a domain which will resolve to the IP of the running node (see #609):

go test -v -count=1 ./test/conformance --resolvabledomain

Conformance test environment requirements

These tests require:

  1. A running Knative Serving cluster.
  2. The namespace pizzaplanet to exist in the cluster: kubectl create namespace pizzaplanet
  3. A docker repo contianing the conformance test images
Conformance test images

The configuration for the images used for the existing conformance tests lives in test_images. See the section about test images for details about building and adding new ones.

Running end-to-end tests

The e2e tests have almost the exact same requirements and specs as the conformance tests, but they will be enumerated for clarity.

To run the e2e tests, you need to have a running environment that meets the e2e test environment requirements.

To run the e2e tests against the current cluster in ~/.kube/config using go test using the environment specified in your environment variables:

Since these tests are fairly slow, running them with logging enabled is recommended. Do so by passing the -v flag to go test like so:

go test -v ./test/e2e

You can use test flags to control the environment your tests run against, i.e. override your environment variables:

go test -v ./test/e2e --kubeconfig ~/special/kubeconfig --cluster myspecialcluster --dockerrepo myspecialdockerrepo

If you are running against an environment with no loadbalancer for the ingress, at the moment your only option is to use a domain which will resolve to the IP of the running node (see #609):

go test -v ./test/e2e --resolvabledomain

End-to-end test environment requirements

These tests require:

  1. A running Knative Serving cluster.
  2. The namespace noodleburg to exist in the cluster: kubectl create namespace noodleburg
  3. A docker repo containing the e2e test images
End-to-end test images

The configuration for the images used for the existing e2e tests lives in test_images. See the section about test images for details about building and adding new ones.

Test images

Building the test images

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

To run the script:

./test/upload-test-images.sh /path/containing/test/images

The path containing test images is any directory whose subdirectories contain the Dockerfile and any required files to build Docker images (e.g., ./test/e2e/test_images).

Adding new test images

New test images should be placed in their own subdirectories. Be sure to to include a Dockerfile for building and running the test image.

The new test images will also need to be uploaded to the e2e tests Docker repo. You will need one of the owners found in /test/OWNERS to do this.

Flags

These flags are useful for running against an existing cluster, making use of your existing environment setup.

Tests importing github.com/knative/serving/test recognize these flags:

Specifying kubeconfig

By default the tests will use the kubeconfig file at ~/.kube/config. You can specify a different config file with the argument --kubeconfig.

To run the tests with a non-default kubeconfig file:

go test ./test/conformance --kubeconfig /my/path/kubeconfig
go test ./test/e2e --kubeconfig /my/path/kubeconfig
Specifying cluster

The --cluster argument lets you use a different cluster than your specified kubeconfig's active context. This will default to the value of your K8S_CLUSTER_OVERRIDE environment variable if not specified.

go test ./test/conformance --cluster your-cluster-name
go test ./test/e2e --cluster your-cluster-name

The current cluster names can be obtained by running:

kubectl config get-clusters
Overridding docker repo

The --dockerrepo argument lets you specify the docker repo from which images used by your tests should be pulled. This will default to the value of your DOCKER_REPO_OVERRIDE environment variable if not specified.

go test ./test/conformance --dockerrepo gcr.myhappyproject
go test ./test/e2e --dockerrepo gcr.myhappyproject
Using a resolvable domain

If you set up your cluster using the getting started docs, Routes created in the test will use the domain demo-domain.com, unless the route has label app=prod in which case they will use the domain prod-domain.com. Since these domains will not be resolvable to deployments in your test cluster, in order to make a request against the endpoint, the test use the IP assigned to the istio *-ela-ingress and spoof the Host in the header.

If you have configured your cluster to use a resolvable domain, you can use the --resolvabledomain flag to indicate that the test should make requests directly against Route.Status.Domain and does not need to spoof the Host.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Flags = initializeFlags()

Flags will include the k8s cluster (defaults to $K8S_CLUSTER_OVERRIDE), kubeconfig (defaults to ./kube/config) (for connecting to an existing cluster), dockerRepo (defaults to $DOCKER_REPO_OVERRIDE) and how to connect to deployed endpoints.

Functions

func AllRouteTrafficAtRevision

func AllRouteTrafficAtRevision(routeName string, revisionName string) func(r *v1alpha1.Route) (bool, error)

AllRouteTrafficeAtRevision will check the revision that routeName is routing traffic to and return true if 100% of the traffic is routing to revisionName.

func CleanupOnInterrupt

func CleanupOnInterrupt(cleanup func())

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

func Configuration

func Configuration(namespace string, config string, imagePath string) *v1alpha1.Configuration

Configuration returns a Configuration object in namespace with the name config that uses the image specifed by imagePath.

func IsRevisionReady

func IsRevisionReady(revisionName string) func(r *v1alpha1.Revision) (bool, error)

IsRevisionReady will check the status conditions of revision revisionName 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 Route

func Route(namespace string, route string, config string) *v1alpha1.Route

Route returns a Route object in namespace with name route that will use the configuration resource called config.

func WaitForConfigurationState

func WaitForConfigurationState(client elatyped.ConfigurationInterface, name string, inState func(c *v1alpha1.Configuration) (bool, error)) error

WaitForConfigurationState polls the status of the Configuration called name from client every interval until inState returns `true` indicating it is done, returns an error or timeout.

func WaitForDeploymentState

func WaitForDeploymentState(client v1beta1.DeploymentInterface, name string,
	inState func(d *apiv1beta1.Deployment) (bool, error)) error

WaitForDeploymentState polls the status of the Deployment called name from client every interval until inState returns `true` indicating it is done, returns an error or timeout.

func WaitForEndpointState

func WaitForEndpointState(kubeClientset *kubernetes.Clientset, resolvableDomain bool, domain string, namespaceName string, routeName string, inState func(body string) (bool, error)) error

WaitForEndpointState will poll an endpoint until inState indicates the state is achieved. If resolvableDomain is false, it will use kubeClientset to look up the ingress (named based on routeName) in the namespace namespaceName, and spoof domain in the request heaers, otherwise it will make the request directly to domain.

func WaitForIngressState

func WaitForIngressState(client v1beta1.IngressInterface, name string, inState func(r *apiv1beta1.Ingress) (bool, error)) error

WaitForIngressState polls the status of the Ingress called name from client every interval until inState returns `true` indicating it is done, returns an error or timeout.

func WaitForPodListState

func WaitForPodListState(client v1.PodInterface,
	inState func(p *corev1.PodList) (bool, error)) error

WaitForPodListState polls the status of the PodList from client every interval until inState returns `true` indicating it is done, returns an error or timeout.

func WaitForRevisionState

func WaitForRevisionState(client elatyped.RevisionInterface, name string, inState func(r *v1alpha1.Revision) (bool, error)) error

WaitForRevisionState polls the status of the Revision called name from client every interval until inState returns `true` indicating it is done, returns an error or timeout.

func WaitForRouteState

func WaitForRouteState(client elatyped.RouteInterface, name string, inState func(r *v1alpha1.Route) (bool, error)) 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.

Types

type Clients

type Clients struct {
	Kube      *kubernetes.Clientset
	Routes    elatyped.RouteInterface
	Configs   elatyped.ConfigurationInterface
	Revisions elatyped.RevisionInterface
}

Clients holds instances of interfaces for making requests to Knative Serving.

func NewClients

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

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

func (*Clients) Delete

func (clients *Clients) Delete(routes []string, configs []string) error

Delete will delete all Routes and Configs with the names routes and configs, if clients has been successfully initialized.

type EnvironmentFlags

type EnvironmentFlags struct {
	Cluster          string
	DockerRepo       string
	Kubeconfig       string
	ResolvableDomain bool
}

EnvironmentFlags holds the command line flags or defaults for settings in the user's environment.

Directories

Path Synopsis
conformance
e2e

Jump to

Keyboard shortcuts

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