* upgrade to latest dependencies bumping k8s.io/kube-openapi 4241196...3ee0da9: > 3ee0da9 Merge pull request # 299 from Jefftree/def-optimize > 3a31a64 Merge pull request # 292 from Jefftree/v2v3conv > ba6f675 Optimize Definition generation > e69a86c Merge pull request # 298 from Jefftree/allOf > 2cbad14 Add OpenAPIConv > 9f9c01d Merge pull request # 297 from cici37/errFix > 207f0c7 Wrap Refs with AllOf > 29d7264 Merge pull request # 295 from Jefftree/fix-api-json > d2a55e8 Align maxProperties/minProperties err value with others > 52feaf8 Merge pull request # 290 from jiahuif/feature/prune-v2-when-serving-v3 > 352e363 Fix json encoding for OpenAPI v3 Discovery > 662cbb0 Return valid for kubernetes to handle err properly > 13192b9 Merge pull request # 289 from jiahuif/feature/openapi-oneof-type > 2580423 remove embedded v2 from expected schema > 8a7ee80 Merge pull request # 293 from alexzielenski/cache-busting > 79a5a7d generated: update integration test. > d436835 add test for pruning v2 schema. > 6a7b704 Merge pull request # 291 from Jefftree/builder3-test > de6f8b0 split openapi mock class into Fake and FakeV3 > da7e27a add integration test for v3 OneOf > eca4f62 do not include v2 schema when serving v3. > 89ac9db Merge pull request # 284 from Jefftree/cache-busting > 7afa56c Add test for builder3 > 3ca26f0 address comments > 697543f add support for custom v3 oneOf types. > ddc6692 Merge pull request # 288 from Jefftree/gnostic-fix > b0d7548 Cache busting > 130db2b add wrapper around gnostic v3 document > a9dfcaa Merge pull request # 286 from Jefftree/leading-newline > 91ab739 Update gnostic to drop jsonschema dependency > 3f90b8c Merge pull request # 282 from alexzielenski/header_vendorext_marshal > c7e0de3 Merge pull request # 285 from Jefftree/proto-upgrade > 7626df5 Trim leading newlines in Descriptions > 1cd4920 add vendor extensions to marshal openapi v2 header > 86aaf54 Upgrade protobuf and change references of googleapis/gnostic -> google/gnostic Signed-off-by: Knative Automation <automation@knative.team> * Fix client-go version * Add missing license file * Add another missing license file Signed-off-by: Knative Automation <automation@knative.team> Co-authored-by: David Simansky <dsimansk@redhat.com> |
||
|---|---|---|
| .. | ||
| environment | ||
| ingress | ||
| logging | ||
| monitoring | ||
| spoof | ||
| zipkin | ||
| README.md | ||
| cleanup.go | ||
| clients.go | ||
| crd.go | ||
| e2e_flags.go | ||
| kube_checks.go | ||
| presubmit-tests.sh | ||
| request.go | ||
| test-reconciler-codegen.sh | ||
| tinterface.go | ||
README.md
Test
This directory contains tests and testing docs.
- Test library contains code you can use in your
knativetests - Flags added by the test library
- Unit tests currently reside in the codebase alongside the code they test
Running unit tests
To run all unit tests:
go test ./...
Test library
You can use the test library in this dir to:
Use common test flags
These flags are useful for running against an existing cluster, making use of your existing environment setup.
By importing knative.dev/pkg/test you get access to a global variable called
test.Flags which holds the values of
the command line flags.
logger.Infof("Using namespace %s", test.Flags.Namespace)
See e2e_flags.go.
Output logs
When tests are run with --logverbose option,
debug logs will be emitted to stdout.
We are using a generic
FormatLogger
that can be passed in any existing logger that satisfies it. Test can use the
generic logging methods to log info and
error logs. All the common methods accept generic FormatLogger as a parameter
and tests can pass in t.Logf like this:
_, err = pkgTest.WaitForEndpointState(
kubeClient,
t.Logf,
...),
See logging.go.
Check Knative Serving resources
WARNING: this code also exists in
knative/serving.
After creating Knative Serving resources or making changes to them, you will need to wait for the system to realize those changes. You can use the Knative Serving CRD check and polling methods to check the resources are either in or reach the desired state.
The WaitFor* functions use the kubernetes
wait package. To poll
they use
PollImmediate
and the return values of the function you provide behave the same as
ConditionFunc:
a bool to indicate if the function should stop or continue polling, and an
error to indicate if there has been an error.
For example, you can poll a Configuration object to find the name of the
Revision that was created for it:
var revisionName string
err := test.WaitForConfigurationState(
clients.ServingClient, configName, func(c *v1alpha1.Configuration) (bool, error) {
if c.Status.LatestCreatedRevisionName != "" {
revisionName = c.Status.LatestCreatedRevisionName
return true, nil
}
return false, nil
}, "ConfigurationUpdatedWithRevision")
See kube_checks.go.
Ensure test cleanup
To ensure your test is cleaned up, you should defer cleanup to execute after your test completes and also ensure the cleanup occurs if the test is interrupted:
defer tearDown(clients)
test.CleanupOnInterrupt(func() { tearDown(clients) })
See cleanup.go.
Flags
Importing the test library adds flags that are useful for end to end tests that need to run against a cluster.
Tests importing knative.dev/pkg/test recognize these flags:
--kubeconfig--cluster--namespace--logverbose--ingressendpoint--dockerrepo--tag--imagetemplate
Specifying kubeconfig
By default the tests will use the
kubeconfig file
at ~/.kube/config. If there is an error getting the current user, it will use
kubeconfig instead as the default value. You can specify a different config
file with the argument --kubeconfig.
To run tests with a non-default kubeconfig file:
go test ./test --kubeconfig /my/path/kubeconfig
Specifying cluster
The --cluster argument lets you use a different cluster than
your specified kubeconfig's active context.
go test ./test --cluster your-cluster-name
The current cluster names can be obtained by running:
kubectl config get-clusters
Specifying ingress endpoint
The --ingressendpoint argument lets you specify a static url to use as the
ingress server during tests. This is useful for Kubernetes configurations which
do not provide external IPs.
go test ./test --ingressendpoint <k8s-controller-ip>:32380
Specifying namespace
The --namespace argument lets you specify the namespace to use for the tests.
By default, tests will use serving-tests.
go test ./test --namespace your-namespace-name
Output verbose logs
The --logverbose argument lets you see verbose test logs and k8s logs.
go test ./test --logverbose
Specifying docker repo
The --dockerrepo argument lets you specify a uri of the docker repo where you
have uploaded the test image to using uploadtestimage.sh. Defaults to
$KO_DOCKER_REPO
go test ./test --dockerrepo myspecialdockerrepo
Specifying tag
The --tag argument lets you specify the version tag for the test images.
go test ./test --tag v1.0
Specifying image template
The --imagetemplate argument lets you specify a template to generate the
reference to an image from the test. Defaults to
{{.Repository}}/{{.Name}}:{{.Tag}}
go test ./test --imagetemplate {{.Repository}}/{{.Name}}:{{.Tag}}
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License.