Skip to content

Commit 78eba97

Browse files
bobcatfishknative-prow-robot
authored andcommitted
Move docs from knative/serving to knative/pkg (knative#2097)
* Move docs from knative/serving to knative/pkg While working on tektoncd/pipeline#16 I started trying to build some integration tests, and I wanted to use the code which had been moved to knative/pkg, but it turned out the docs hadn't been ported with the code, so I am moving the docs relevant to knative/pkg/test to that repo. I also fixed some headings which were duplicated. Adding docs to knative/pkg in knative/pkg#102 * Fix name of function in docs lol this one was wrong THE WHOLE TIME SINCE THE VERY FIRST COMMIT where I used one name in the implementation and a different name in the docs XD knative@5bc7377
1 parent e17bfde commit 78eba97

File tree

2 files changed

+17
-154
lines changed

2 files changed

+17
-154
lines changed

test/README.md

+5-69
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ These tests require:
7070
```
7171
3. A docker repo containing [the test images](#test-images)
7272

73-
### Flags
73+
### Common Flags
7474

7575
* By default the e2e tests against the current cluster in `~/.kube/config`
7676
using the environment specified in [your environment variables](/DEVELOPMENT.md#environment-setup).
@@ -115,6 +115,7 @@ To run the script for all end to end test images:
115115
```bash
116116
./test/upload-test-images.sh
117117
```
118+
118119
A docker tag may be passed as an optional parameter. This can be
119120
useful on [Minikube] in tandem with the `--tag` [flag](#using-a-docker-tag):
120121

@@ -132,58 +133,12 @@ New test images should be placed in `./test/test_images`.
132133
These flags are useful for running against an existing cluster, making use of your existing
133134
[environment setup](/DEVELOPMENT.md#environment-setup).
134135

135-
Tests importing [`github.com/knative/serving/test`](adding_tests.md#test-library) recognize these flags:
136+
Tests importing [`github.com/knative/serving/test`](#test-library) recognize these flags:
136137

137-
* [`--kubeconfig`](#specifying-kubeconfig)
138-
* [`--cluster`](#specifying-cluster)
139-
* [`--namespace`](#specifying-namespace)
138+
* [All flags added by `knative/pkg/test`](https://github.com/knative/pkg/tree/master/test#flags)
140139
* [`--dockerrepo`](#overriding-docker-repo)
141140
* [`--tag`](#using-a-docker-tag)
142141
* [`--resolvabledomain`](#using-a-resolvable-domain)
143-
* [`--logverbose`](#output-verbose-logs)
144-
* [`--emitmetrics`](#emit-metrics)
145-
146-
### Specifying kubeconfig
147-
148-
By default the tests will use the [kubeconfig
149-
file](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/)
150-
at `~/.kube/config`. If there is an error getting the current user, it will use `kubeconfig` instead as the default value.
151-
You can specify a different config file with the argument `--kubeconfig`.
152-
153-
To run the tests with a non-default kubeconfig file:
154-
155-
```bash
156-
go test -v -tags=e2e -count=1 ./test/conformance --kubeconfig /my/path/kubeconfig
157-
go test -v -tags=e2e -count=1 ./test/e2e --kubeconfig /my/path/kubeconfig
158-
```
159-
160-
### Specifying cluster
161-
162-
The `--cluster` argument lets you use a different cluster than [your specified
163-
kubeconfig's](#specifying-kubeconfig) active context. This will default to the value
164-
of your [`K8S_CLUSTER_OVERRIDE` environment variable](/DEVELOPMENT.md#environment-setup)
165-
if not specified.
166-
167-
```bash
168-
go test -v -tags=e2e -count=1 ./test/conformance --cluster your-cluster-name
169-
go test -v -tags=e2e -count=1 ./test/e2e --cluster your-cluster-name
170-
```
171-
172-
The current cluster names can be obtained by running:
173-
174-
```bash
175-
kubectl config get-clusters
176-
```
177-
178-
### Specifying namespace
179-
180-
The `--namespace` argument lets you specify the namespace to use for the
181-
tests. By default, tests will use `serving-tests`.
182-
183-
```bash
184-
go test -v -tags=e2e -count=1 ./test/conformance --namespace your-namespace-name
185-
go test -v -tags=e2e -count=1 ./test/e2e --namespace your-namespace-name
186-
```
187142

188143
### Overridding docker repo
189144

@@ -212,7 +167,6 @@ go test -v -tags=e2e -count=1 ./test/e2e --tag any-old-tag
212167
Of course, this implies that you tagged the images when you [uploaded
213168
them](#building-the-test-images).
214169

215-
216170
### Using a resolvable domain
217171

218172
If you set up your cluster using [the getting started
@@ -226,22 +180,4 @@ the header.
226180

227181
If you have configured your cluster to use a resolvable domain, you can use the
228182
`--resolvabledomain` flag to indicate that the test should make requests directly against
229-
`Route.Status.Domain` and does not need to spoof the `Host`.
230-
231-
### Output verbose logs
232-
233-
The `--logverbose` argument lets you see verbose test logs and k8s logs.
234-
235-
```bash
236-
go test -v -tags=e2e -count=1 ./test/e2e --logverbose
237-
```
238-
239-
### Emit metrics
240-
241-
Running tests with the `--emitmetrics` argument will cause latency metrics to be emitted by
242-
the tests.
243-
244-
* To add additional metrics to a test, see [emitting metrics](adding_tests.md#emit-metrics).
245-
* For more info on the format of the metrics, see [metric format](adding_tests.md#metric-format).
246-
247-
[Minikube]: https://kubernetes.io/docs/setup/minikube/
183+
`Route.Status.Domain` and does not need to spoof the `Host`.

test/adding_tests.md

+12-85
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,23 @@ so that `go test ./...` can be used to run only [the unit tests](README.md#runni
2121
In the [`test`](/test/) dir you will find several libraries in the `test` package
2222
you can use in your tests.
2323

24-
You can:
24+
This library exists partially in this directory and partially in
25+
[`knative/pkg/test`](https://github.com/knative/pkg/tree/master/test).
26+
27+
The libs in this dir can:
2528

2629
* [Use common test flags](#use-common-test-flags)
27-
* [Output logs](#output-logs)
28-
* [Emit metrics](#emit-metrics)
2930
* [Get access to client objects](#get-access-to-client-objects)
3031
* [Make requests against deployed services](#make-requests-against-deployed-services)
3132
* [Check Knative Serving resources](#check-knative-serving-resources)
3233
* [Verify resource state transitions](#verify-resource-state-transitions)
3334
* [Generate boilerplate CRDs](#generate-boilerplate-crds)
34-
* [Ensure test cleanup](#ensure-test-cleanup)
35+
36+
See [`knative/pkg/test`](https://github.com/knative/pkg/tree/master/test) to:
37+
38+
* Output logs
39+
* Emit metrics
40+
* Ensure test cleanup
3541

3642
### Use common test flags
3743

@@ -47,73 +53,6 @@ imagePath := strings.Join([]string{test.ServingFlags.DockerRepo, image}, "/"))
4753

4854
_See [e2e_flags.go](./e2e_flags.go)._
4955

50-
### Output logs
51-
52-
[When tests are run with `--logverbose`
53-
option](README.md#output-verbose-logs), debug logs will be emitted to stdout.
54-
55-
We are using the common [e2e logging library](/pkg/test/logging) that uses the [Knative logging library](/pkg/logging/) for structured logging.
56-
It is built on top of [zap](https://github.com/uber-go/zap). Tests should initialize the global logger to use a test specifc context with `logging.GetContextLogger`:
57-
58-
```go
59-
// The convention is for the name of the logger to match the name of the test.
60-
logging.GetContextLogger("TestHelloWorld")
61-
```
62-
63-
Logs can then be emitted using the `logger` object which is required by
64-
many functions in the test library. To emit logs:
65-
66-
```go
67-
logger.Infof("Creating a new Route %s and Configuration %s", route, configuration)
68-
logger.Debugf("The LogURL is %s, not yet verifying", logURL)
69-
```
70-
71-
_See [logging.go](./logging/logging.go)._
72-
73-
### Emit metrics
74-
75-
You can emit metrics from your tests using [the opencensus
76-
library](https://github.com/census-instrumentation/opencensus-go), which [is being
77-
used inside Knative as well](/docs/telemetry.md). These metrics will be emitted by
78-
the test if the test is run with [the `--emitmetrics` option](README.md#emit-metrics).
79-
80-
You can record arbitrary metrics with
81-
[`stats.Record`](https://github.com/census-instrumentation/opencensus-go#stats) or
82-
measure latency with [`trace.StartSpan`](https://github.com/census-instrumentation/opencensus-go#traces):
83-
84-
```go
85-
ctx, span := trace.StartSpan(context.Background(), "MyMetric")
86-
```
87-
88-
* These traces will be emitted automatically by [the generic crd polling
89-
functions](#check-knative-serving-resources).
90-
* The traces are emitted by [a custom metric exporter](./logging.go)
91-
that uses the global logger instance.
92-
93-
#### Metric format
94-
95-
When a `trace` metric is emitted, the format is `metric name startTime endTime duration`. The name
96-
of the metric is arbitrary and can be any string. The values are:
97-
98-
* "metric" - Indicates this log is a metric
99-
* name - Arbitrary string indentifying the metric. TODO(#1379) determine metric format
100-
* startTime - Unix time in nanoseconds when measurement started
101-
* endTime - Unix time in nanoseconds when measurement ended
102-
* duration - The difference in ms between the startTime and endTime
103-
104-
For example:
105-
106-
```bash
107-
metric WaitForConfigurationState/prodxiparjxt/ConfigurationUpdatedWithRevision 1529980772357637397 1529980772431586609 73.949212ms
108-
```
109-
110-
_The [`Wait` methods](#check-knative-serving-resources) (which poll resources) will
111-
prefix the metric names with the name of the function, and if applicable, the name of the resource,
112-
separated by `/`. In the example above, `WaitForConfigurationState` is the name of
113-
the function, and `prodxiparjxt` is the name of the configuration resource being polled.
114-
`ConfigurationUpdatedWithRevision` is the string passed to `WaitForConfigurationState` by
115-
the caller to identify what state is being polled for._
116-
11756
### Get access to client objects
11857

11958
To initialize client objects that you can use [the command line flags](#use-flags)
@@ -275,15 +214,15 @@ _See [states.go](./states.go)._
275214
Your tests will probably need to create `Route` and `Configuration` objects. You can use the
276215
existing boilerplate to describe them.
277216

278-
You can also use the function `RandomizedName` to create a random name for your `crd` so that
217+
You can also use the function `AppendRandomString` to create a random name for your `crd` so that
279218
your tests can use unique names each time they run.
280219

281220
For example to create a `Configuration` object that uses a certain docker image with a
282221
randomized name:
283222

284223
```go
285224
var names test.ResourceNames
286-
names.Config := test.RandomizedName('hotdog')
225+
names.Config := test.AppendRandomString('hotdog', logger)
287226
_, err := clients.ServingClient.Create(test.Configuration(namespaceName, names, imagePath))
288227
if err != nil {
289228
return err
@@ -293,15 +232,3 @@ if err != nil {
293232
Please expand these functions as more use cases are tested.
294233

295234
_See [crd.go](./crd.go)._
296-
297-
### Ensure test cleanup
298-
299-
To ensure your test is cleaned up, you should defer cleanup to execute after your
300-
test completes and also ensure the cleanup occurs if the test is interrupted:
301-
302-
```go
303-
defer tearDown(clients)
304-
test.CleanupOnInterrupt(func() { tearDown(clients) })
305-
```
306-
307-
_See [cleanup.go](./cleanup.go)._

0 commit comments

Comments
 (0)