This directory contains tests and testing docs for Knative Eventing.
- Unit tests reside in the codebase alongside the code they test
- End-to-end tests reside in
/test/e2e
presubmit-tests.sh is the entry point for the tests
before code submission.
You can run it simply with:
test/presubmit-tests.shBy 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-testsNote 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.sh is the entry point for running all e2e tests.
You can run it simply with:
test/e2e-tests.shBy 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.
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.
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=trueBy 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,gcp-pubsubTo 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-memoryThere's couple of things you need to install before running e2e tests locally.
- A running Knative cluster
- A docker repo containing 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:
KO_DOCKER_REPOto be set- You to be
authenticated with your
KO_DOCKER_REPO dockerto be installed
To run the script for all end to end test images:
./test/upload-test-images.sh e2eA docker tag is mandatory to avoid issues with using latest tag for images
deployed in GCR.
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 are similar to those in
Knative Serving