-
Notifications
You must be signed in to change notification settings - Fork 1.8k
doc: add base doc that clarifies how users can test their projects #3823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
camilamacedo86
merged 3 commits into
operator-framework:master
from
camilamacedo86:doc-tests
Oct 14, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
website/content/en/docs/building-operators/golang/advanced-topics.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| --- | ||
| title: Advanced Topics | ||
| linkTitle: Advanced Topics | ||
| weight: 70 | ||
| weight: 80 | ||
| --- | ||
|
|
||
| ### Manage CR status conditions | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
website/content/en/docs/building-operators/golang/testing.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --- | ||
| title: Testing your Operator project | ||
| linkTitle: Testing with EnvTest | ||
| description: Learn how to ensure the quality of your Operator project | ||
| weight: 70 | ||
| --- | ||
|
|
||
| ## Overview | ||
|
|
||
| The Operator SDK project recommends using controller-runtime's [envtest][envtest] to write tests for your Operators projects. Envtest has a more active contributor community, it is more mature than Operator SDK's test framework, and it does not require an actual cluster to run tests which can be a huge benefit in CI scenarios. | ||
|
|
||
| ## Using EnvTest | ||
|
|
||
| You will see that `controllers/suite_test.go` is created when a controller is scaffolded by the tool. This file contains boilerplate for executing integration tests using [envtest][envtest] with [ginkgo](https://onsi.github.io/ginkgo/) and [gomega][gomega]. | ||
|
|
||
|
|
||
| It means that you will implement your controller's tests in go using this stack and it will be called by the `suite_test.go` via go tool such as: | ||
|
|
||
| ```shell | ||
| go test controllers/ -v -ginkgo.v | ||
| ``` | ||
|
|
||
| The projects generated by using the SDK tool have a Makefile which contains the target tests which executes when you run `make test`. Note that this target will also execute when you run `make docker-build IMG=<some-registry>/<project-name>:<tag>`. | ||
|
|
||
| Operator SDK adopted this stack to write tests for its operators. It might be useful to check [writing controller tests][writing-controller-tests] documentation and examples to learn how to better write tests for your operator. See, for example, that [controller-runtime](https://github.com/kubernetes-sigs/controller-runtime) is covered by tests using the same stack as well. | ||
|
|
||
| ## Other Options | ||
|
camilamacedo86 marked this conversation as resolved.
|
||
|
|
||
| Also you can write tests for your operator in a declarative using the [kuttl][kuttl]. Via kuttl, you can define YAML manifests that specify the expected before and after statues of a cluster when your operator is used. For more info see [Writing Kuttl Scorecard Tests][writing-kuttl-scorecard-tests]. | ||
|
|
||
| To implement application-specific tests, the SDK's test harness, [scorecard][scorecard], provides the ability to ship custom code in container images as well, which can be referenced in the test suite. Because this test suite definition metadata travels with the Operator Bundle, it allows for functional testing of the Operator without the source code or the project layout being available. See [Writing Custom Scorecard Tests][writing-custom-scorecard-tests]. | ||
|
|
||
| [envtest]: https://godoc.org/sigs.k8s.io/controller-runtime/pkg/envtest | ||
| [writing-controller-tests]: https://book.kubebuilder.io/cronjob-tutorial/writing-tests.html | ||
| [envtest-setup]: /docs/building-operators/golang/references/envtest-setup | ||
| [writing-kuttl-scorecard-tests]: /docs/advanced-topics/scorecard/kuttl-tests | ||
| [writing-custom-scorecard-tests]: /docs/advanced-topics/scorecard/custom-tests | ||
| [scorecard]: /docs/advanced-topics/scorecard/scorecard | ||
| [gomega]: https://onsi.github.io/gomega/ | ||
| [kuttl]: https://kuttl.dev/ | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.