Skip to content

Commit c2c0120

Browse files
authored
Switch from using Ginkgo to using only the Go test framework (#778)
As explored in the prototypes in #253, we have decided that although Ginkgo is the best of the Go test frameworks, we do not want to be tied to BDD and feel these tests will be cleaner and easier to contribute to if we use no framework. I have also refactored the supporting logic of the tests into a `test` library which can be reused for other e2e tests, documented in test/adding_tests.md * Improved docs on running tests: now all docs on running are in test/README.md, there is only one place to look to see how to run all of the tests. Instructions on how to run conformance tests are hopefully more clear. * Updated links that pointed at CONTRIBUTING.md since the content moved Fixes #253
1 parent c5af8a1 commit c2c0120

239 files changed

Lines changed: 965 additions & 177899 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DEVELOPMENT.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Development
22

33
This doc explains how to setup a development environment so you can get started
4-
[contributing](./CONTRIBUTING.md) to `Elafros`. Also take a look at [the
5-
development workflow](./CONTRIBUTING.md#workflow) and [the test docs](./test/README.md).
4+
[contributing](./community/CONTRIBUTING.md) to `Elafros`. Also take a look at:
5+
6+
* [The pull request workflow](./community/CONTRIBUTING.md#pull-requests)
7+
* [How to add and run tests](./test/README.md)
8+
* [Iterating](#iterating)
69

710
## Getting started
811

@@ -168,12 +171,6 @@ bazel run :controller.apply
168171
Or you can [clean it up completely](./README.md#clean-up) and [completely
169172
redeploy `Elafros`](./README.md#start-elafros).
170173

171-
## Tests
172-
173-
Tests are run automatically for every PR. For more details, see [the development workflow](./CONTRIBUTING.md#prow).
174-
175-
For more details about the tests themselves and how to run them, see [the test docs](./test/README.md).
176-
177174
## Clean up
178175

179176
You can delete all of the service components with:

Gopkg.lock

Lines changed: 1 addition & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/BUILD.bazel

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = [
6+
"cleanup.go",
7+
"clients.go",
8+
"crd.go",
9+
"crd_polling.go",
10+
"e2e_flags.go",
11+
"request.go",
12+
"states.go",
13+
],
14+
importpath = "github.com/elafros/elafros/test",
15+
visibility = ["//visibility:public"],
16+
deps = [
17+
"//pkg/apis/ela/v1alpha1:go_default_library",
18+
"//pkg/client/clientset/versioned:go_default_library",
19+
"//pkg/client/clientset/versioned/typed/ela/v1alpha1:go_default_library",
20+
"//vendor/k8s.io/api/core/v1:go_default_library",
21+
"//vendor/k8s.io/api/extensions/v1beta1:go_default_library",
22+
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
23+
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
24+
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
25+
"//vendor/k8s.io/client-go/kubernetes/typed/extensions/v1beta1:go_default_library",
26+
"//vendor/k8s.io/client-go/rest:go_default_library",
27+
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
28+
],
29+
)

test/README.md

Lines changed: 168 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,125 @@
22

33
This 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
1416
bazel test //pkg/... --test_output=errors
1517
```
1618

17-
Or can be run using `go test`:
19+
Or `go test`:
1820

1921
```shell
2022
go 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

31125
1. Have `kubetest` installed:
32126
```
@@ -36,14 +130,75 @@ In order to run the end-to-end tests, make sure you:
36130
```
37131
2. 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

Comments
 (0)