package
0.1.0
Repository: https://github.com/mattmoor/serving.git
Documentation: pkg.go.dev

# README

Test

This directory contains tests and testing docs for Knative Serving:

The conformance tests are a subset of the end to end test with more strict requirements around what can be tested.

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

Presubmit tests

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

This script, and consequently, the e2e and conformance 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'll need kubernetes kubetest installed:

go get -u k8s.io/test-infra/kubetest

Running unit tests

To run all unit tests:

go test ./...

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

Running end to end tests

To run the e2e tests and the conformance 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/conformance
go test -v -tags=e2e -count=1 ./test/e2e

One test case

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

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

Environment requirements

These tests require:

  1. A running Knative Serving cluster.
  2. The namespaces pizzaplanet and noodleburg:
    kubectl create namespace pizzaplanet
    kubectl create namespace noodleburg
    
  3. A docker repo containing the test images

Flags

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

go test -v -tags=e2e -count=1 ./test/conformance --kubeconfig ~/special/kubeconfig --cluster myspecialcluster --dockerrepo myspecialdockerrepo
go test -v -tags=e2e -count=1 ./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 -tags=e2e -count=1 ./test/conformance --resolvabledomain
go test -v -tags=e2e -count=1 ./test/e2e --resolvabledomain

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 for all end to end test images:

./test/upload-test-images.sh ./test/e2e/test_images
./test/upload-test-images.sh ./test/conformance/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 -v -tags=e2e -count=1 ./test/conformance --kubeconfig /my/path/kubeconfig
go test -v -tags=e2e -count=1 ./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 -v -tags=e2e -count=1 ./test/conformance --cluster your-cluster-name
go test -v -tags=e2e -count=1 ./test/e2e --cluster your-cluster-name

The current cluster names can be obtained by running:

kubectl config get-clusters

Specifying namespace

The --namespace argument lets you specify the namespace to use for the tests. By default, conformance will use noodleburg and e2e will use pizzaplanet.

go test -v -tags=e2e -count=1 ./test/conformance --namespace your-namespace-name
go test -v -tags=e2e -count=1 ./test/e2e --namespace your-namespace-name

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 -v -tags=e2e -count=1 ./test/conformance --dockerrepo gcr.myhappyproject
go test -v -tags=e2e -count=1 ./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 example.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 service knative-ingressgateway in the namespace istio-system 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.

Output verbose logs

The --logverbose argument lets you see verbose test logs and k8s logs.

go test -v -tags=e2e -count=1 ./test/e2e --logverbose

Emit metrics

Running tests with the --emitmetrics argument will cause latency metrics to be emitted by the tests.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

AllRouteTrafficAtRevision will check the revision that route r is routing traffic to and return true if 100% of the traffic is routing to revisionName.
AppendRandomString will generate a random string that begins with prefix.
BlueGreenRoute returns a Route object in namespace using the route and configuration names in names.
CheckConfigurationState verifies the status of the Configuration called name from client is in a particular state by calling `inState` and expecting `true`.
CheckRevisionState verifies the status of the Revision called name from client is in a particular state by calling `inState` and expecting `true`.
CheckRouteState verifies the status of the Route called name from client is in a particular state by calling `inState` and expecting `true`.
CheckServiceState verifies the status of the Service called name from client is in a particular state by calling `inState` and expecting `true`.
CleanupOnInterrupt will execute the function cleanup if an interrupt signal is caught.
Configuration returns a Configuration object in namespace with the name names.Config that uses the image specifed by imagePath.
EventuallyMatchesBody checks that the response body *eventually* matches the expected body.
IsRevisionReady will check the status conditions of the revision and return true if the revision is ready to serve traffic.
IsRouteReady will check the status conditions of the route and return true if the route is ready.
IsServiceReady will check the status conditions of the service and return true if the service is ready.
LatestService returns a RunLatest Service object in namespace with the name names.Service that uses the image specifed by imagePath.
MatchesAny is a NOP matcher.
MatchesBody checks that the *first* response body matches the "expected" body, otherwise failing.
NewClients instantiates and returns several clientsets required for making request to the Knative Serving cluster specified by the combination of clusterName and configPath.
Route returns a Route object in namespace using the route and configuration names in names.
RouteTrafficToRevisionWithInClusterDNS will check the revision that route r is routing traffic using in cluster DNS and return true if the revision received the request.
ServiceTrafficToRevisionWithInClusterDNS will check the revision that route r is routing traffic using in cluster DNS and return true if the revision received the request.
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.
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.
WaitForEndpointState will poll an endpoint until inState indicates the state is achieved.
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.
WaitForPodListState polls the status of the PodList from client every interval until inState returns `true` indicating it is done, returns an error or timeout.
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.
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.
WaitForServiceState polls the status of the Service called name from client every interval until inState returns `true` indicating it is done, returns an error or timeout.

# Constants

VerboseLogLevel defines verbose log level as 10.

# Variables

Flags holds the command line flags or defaults for settings in the user's environment.
Logger is to be used by test cases for logging and is also used for emitting metrics.

# Structs

Clients holds instances of interfaces for making requests to Knative Serving.
No description provided by the author
ResourceNames holds names of various resources.
ZapMetricExporter is a stats and trace exporter that logs the exported data to the provided (probably test specific) zap logger.