22
33This directory contains tests and testing docs for ` Elafros ` :
44
5- * [ Unit tests] ( #running-unit-tests ) currently reside in the codebase alongside the code they test.
5+ * [ Unit tests] ( #running-unit-tests ) currently reside in the codebase alongside the code they test
6+ * [ Conformance tests] ( #running-conformance-tests ) in [ ` /test/conformance ` ] ( ./conformance )
67* [ End-to-end tests] ( #running-end-to-end-tests )
7- * [ Conformance tests] ( ./conformance/README.md ) are in [ ` ./test/conformance ` ] ( ./conformance )
8+
9+ If you want to add more tests, see [ adding_tests.md] ( ./adding_tests.md ) .
810
911## Running unit tests
1012
11- The tests can be run using bazel directly :
13+ Use bazel:
1214
1315``` shell
1416bazel test //pkg/... --test_output=errors
1517```
1618
17- Or can be run using ` go test ` :
19+ Or ` go test ` :
1820
1921``` shell
2022go test -v ./pkg/...
2123```
24+ ## Running conformance tests
25+
26+ To run [ the conformance tests] ( ./conformance ) , you need to have a running environment that meets
27+ [ the conformance test environment requirements] ( #conformance-test-environment-requirements ) .
28+
29+ To run the conformance tests against the current cluster in ` ~/.kube/config `
30+ using ` go test ` using the environment specified in [ your environment
31+ variables] ( /DEVELOPMENT.md#environment-setup ) :
32+
33+ Since these tests are fairly slow (~ 1 minute), running them with logging
34+ enabled is recommended:
35+
36+ ``` bash
37+ go test -v ./test/conformance
38+ ```
39+
40+ You can [ use test flags] ( #flags ) to control the environment
41+ your tests run against, i.e. override [ your environment variables] ( /DEVELOPMENT.md#environment-setup ) :
42+
43+ ``` bash
44+ go test -v ./test/conformance --kubeconfig ~ /special/kubeconfig --cluster myspecialcluster --dockerrepo myspecialdockerrepo
45+ ```
46+
47+ If you are running against an environment with no loadbalancer for the ingress, at the moment
48+ your only option is to use a domain which will resolve to the IP of the running node (see
49+ [ #609 ] ( https://github.com/elafros/elafros/issues/609 ) ):
50+
51+ ``` bash
52+ go test -v ./test/conformance --resolvabledomain
53+ ```
54+
55+ ## Conformance test environment requirements
56+
57+ These tests require:
58+
59+ 1 . [ A running ` Elafros ` cluster.] ( /DEVELOPMENT.md#getting-started )
60+ 2 . The namespace ` pizzaplanet ` to exist in the cluster: ` kubectl create namespace pizzaplanet `
61+ 3 . A docker repo contianing [ the conformance test images] ( #conformance-test-images )
62+
63+ ### Conformance test images
64+
65+ The configuration for the images used for the existing conformance tests lives in
66+ [ ` test_images_node ` ] ( ./conformance/test_images_node ) .
67+
68+ [ ` upload-test-images.sh ` ] ( ./upload-test-images.sh ) can be used to build and push the
69+ docker images. It requires:
70+
71+ * [ ` DOCKER_REPO_OVERRIDE ` ] ( /DEVELOPMENT.md#environment-setup ) to be set
72+ * You to be [ authenticated with your
73+ ` DOCKER_REPO_OVERRIDE ` ] ( /docs/setting-up-a-docker-registry.md )
74+ * [ ` docker ` ] ( https://docs.docker.com/install/ ) to be installed
75+
76+ To run the script:
77+
78+ ``` bash
79+ ./test/conformance/upload-test-images.sh
80+ ```
81+
82+ ### Running conformance tests with Bazel
83+
84+ To run the conformance tests with ` bazel ` you must:
85+
86+ * Provide a ` kubeconfig ` file. This file must be a ` data ` dependency of the test in
87+ [ ` BUILD.bazel ` ] ( ./conformance/BUILD.bazel ) . By default [ ` BUILD.bazel ` ] ( ./conformance/BUILD.bazel )
88+ is configured to use [ ` test/conformance/kubeconfig ` ] ( /test/conformance/kubeconfig ) .
89+ * Provide a docker repo from which the built images will be pulled. This is done
90+ via the ` --dockerrepo ` argument.
91+
92+ _ The ` bazel ` execution environment will not contain your environment variables, so you must
93+ explicitly specify them with [ command line args] ( #flags ) ._
94+
95+ To run the tests with ` bazel ` (assuming you have populated [ ` ./kubeconfig ` ] ( ./conformance/kubeconfig )
96+ and your [ ` DOCKER_REPO_OVERRIDE ` ] ( /DEVELOPMENT.md#environment-setup ) is configured
97+ to the location where [ you have pushed the conformance test images] ( #conformance-test-images ) ):
98+
99+ ``` bash
100+ bazel test //test/... --test_arg=--dockerrepo=$DOCKER_REPO_OVERRIDE --test_arg=--kubeconfig=./kubeconfig
101+ ```
22102
23103## Running end-to-end tests
24104
25- You can either run all the end-to-end tests in an isolated, hermetic cluster, or use your already existing cluster for that.
105+ The script [ ` e2e-tests.sh ` ] ( /test/e2e-tests.sh ) can be used to run all the end to end tests
106+ (including [ the conformance tests] ( #running-conformance-tests ) ) either:
107+
108+ * [ Using an existing cluster] ( #running-against-an-existing-cluster )
109+ * [ In an isolated, hermetic GCP cluster] ( #running-against-an-isolated-hermetic-gcp-cluster )
110+
111+ ### Running against an existing cluster
112+
113+ Assuming you have [ ` K8S_USER_OVERRIDE ` , ` K8S_CLUSTER_OVERRIDE ` and
114+ ` DOCKER_REPO_OVERRIDE ` set] ( /DEVELOPMENT.md#environment-setup ) , run:
115+
116+ ``` bash
117+ ./tests/e2e-tests.sh --run-tests
118+ ```
26119
27- ### Running against an isolated, hermetic cluster
120+ ### Running against an isolated, hermetic GCP cluster
28121
29- In order to run the end-to-end tests, make sure you:
122+ This will start a cluster for you in GCP using [ kubetest] ( https://github.com/kubernetes/test-infra/tree/master/kubetest ) .
123+ Make sure you:
30124
311251 . Have ` kubetest ` installed:
32126 ```
@@ -36,14 +130,75 @@ In order to run the end-to-end tests, make sure you:
36130 ```
371312 . Have the ` PROJECT_ID ` environment variable set to a GCP project you own.
38132
39- The end-to-end tests can be run by simply executing the ` e2e-tests.sh ` script.
133+ Run:
40134
41- ### Running against an already existing cluster
135+ ``` bash
136+ ./tests/e2e-tests.sh
137+ ```
42138
43- In order to run the end-to-end tests, make sure you have the ` K8S_USER_OVERRIDE ` , ` K8S_CLUSTER_OVERRIDE ` and ` DOCKER_REPO_OVERRIDE ` environment variables correctly set.
139+ ## Flags
44140
45- The end-to-end tests can be run by executing ` e2e-tests.sh --run-tests ` in the command line.
141+ These flags are useful for running against an existing cluster, making use of your existing
142+ [ environment setup] )(/DEVELOPMENT.md#environment-setup).
46143
47- ## Running conformance tests
144+ Tests importing [ ` github.com/elafros/elafros/test ` ] ( adding_tests.md#test-library ) recognize these flags:
145+
146+ * [ ` --kubeconfig ` ] ( #specifying-kubeconfig )
147+ * [ ` --cluster ` ] ( #specifying-cluster )
148+ * [ ` --dockerrepo ` ] ( #overriding-docker-repo )
149+ * [ ` --resolvabledomain ` ] ( #using-a-resolvable-domain )
150+
151+ #### Specifying kubeconfig
152+
153+ By default the tests will use the [ kubeconfig
154+ file] ( https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/ )
155+ at ` ~./kube/config ` .
156+ You can specify a different config file with the argument ` --kubeconfig ` .
157+
158+ To run the conformance tests with a non-default kubeconfig file:
159+
160+ ``` bash
161+ go test ./test/conformance --kubeconfig /my/path/kubeconfig
162+ ```
163+
164+ #### Specifying cluster
165+
166+ The ` --cluster ` argument lets you use a different cluster than [ your specified
167+ kubeconfig's] ( #specifying-kubeconfig ) active context. This will default to the value
168+ of your [ ` K8S_CLUSTER_OVERRIDE ` environment variable] ( /DEVELOPMENT.md#environment-setup )
169+ if not specified.
170+
171+ ``` bash
172+ go test ./test/conformance --cluster your-cluster-name
173+ ```
174+
175+ The current cluster names can be obtained by running:
176+
177+ ``` bash
178+ kubectl config get-clusters
179+ ```
180+
181+ #### Overridding docker repo
182+
183+ The ` --dockerrepo ` argument lets you specify the docker repo from which images used
184+ by your tests should be pulled. This will default to the value
185+ of your [ ` DOCKER_REPO_OVERRIDE ` environment variable] ( /DEVELOPMENT.md#environment-setup )
186+ if not specified.
187+
188+ ``` bash
189+ go test ./test/conformance --dockerrepo gcr.myhappyproject
190+ ```
191+
192+ #### Using a resolvable domain
193+
194+ If you setup your cluster using [ the getting started
195+ docs] ( ../../DEVELOPMENT.md#getting-started ) , Routes created in the test will
196+ use the domain ` demo-domain.com ` , unless the route has label ` app=prod ` in which
197+ case they will use the domain ` prod-domain.com ` . Since these domains will not be
198+ resolvable to deployments in your test cluster, in order to make a request
199+ against the endpoint, the test use the IP assigned to the istio ` *-ela-ingress `
200+ and spoof the ` Host ` in the header.
48201
49- See [ conformance test docs] ( ./conformance/README.md ) .
202+ If you have configured your cluster to use a resolvable domain, you can use the
203+ ` --resolvabledomain ` flag to indicate that the test should make requests directly against
204+ ` Route.Status.Domain ` and does not need to spoof the ` Host ` .
0 commit comments