Skip to content
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

doc: add base doc that clarifies how users can test their projects #3823

Merged
merged 3 commits into from Oct 14, 2020

Conversation

camilamacedo86
Copy link
Contributor

@camilamacedo86 camilamacedo86 commented Sep 1, 2020

Description of the change:
doc: add base doc to clarifies how users can test their projects

Motivation for the change:
Many users have raised these questions. The goal of this doc is to provide the basic information and the links/references for they are able to move forward. It can be improved by the community and/or in the post 1.0 doc plans.

Closes: #3511

Checklist

If the pull request includes user-facing changes, extra documentation is required:

@jberkhahn
Copy link
Contributor

Couple more nits, then this looks good to go.

@camilamacedo86
Copy link
Contributor Author

Hi @jberkhahn,

Really thank you for your review. All nits addressed.

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>` the test also will be executed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the last bit of the sentence "the test also will be executed" is uneeded and can be deleted.

@jberkhahn
Copy link
Contributor

one more thing and this
/lgtm

although your tests seem to be blowing up

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 25, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 30, 2020
@jberkhahn
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 30, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Oct 5, 2020
@jberkhahn
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 6, 2020
@jmrodri jmrodri changed the title doc: add base doc to clarifies how users can test their projects doc: add base doc that clarifies how users can test their projects Oct 7, 2020
Copy link
Member

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start, some minor cleanup. Once that's done I'll lgtm

@@ -230,11 +230,11 @@ test: generate fmt vet manifests

## Migrate your tests

For the new layout, you will see that `controllers/suite_test.go` is created. This file contains boilerplate for executing integration tests using [envtest][envtest] with [ginkgo](https://onsi.github.io/ginkgo/) and [gomega](https://onsi.github.io/gomega/).
For the new layout, 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](https://onsi.github.io/gomega/).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should just be consistent with how we handle links. Add ginkgo and gomega to the bottom with the other links.


Operator SDK 1.0.0+ removes support for the legacy test framework and no longer supports the `operator-sdk test` subcommand. All affected tests should be migrated to use `envtest`.

The Operator SDK project recommends controller-runtime's [envtest][envtest] because it has a more active contributor community, it has become 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.
The Operator SDK project recommends using controller-runtime's [envtest][envtest] to write tests for your Operators projects because it has a more active contributor community, it has become 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split the sentence up.

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.


## Overview

The Operator SDK project recommends using controller-runtime's [envtest][envtest] to write tests for your Operators projects because it has a more active contributor community, it has become 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split the sentence up.

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](https://onsi.github.io/gomega/).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just be consistent with how we handle links. Add ginkgo and gomega to the bottom with the other links.

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>`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add backticks around make test.


## Other Options

Also you can write tests for your operator in a declarative using the [kuttl](https://kuttl.dev/). 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].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you can write tests for your operator in a declarative manner using [kuttl][kuttl]. With kuttl, you define YAML manifests that contain the expected before and after states of the cluster. For more info see [Writing Kuttl Scorecard Tests][writing-kuttl-scorecard-tests].

Put the kuttl link with the other links in the doc.
kuttl


Also you can write tests for your operator in a declarative using the [kuttl](https://kuttl.dev/). 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 test harness of the SDK, [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].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change: the test harness of the SDK -> the SDK's test harness

[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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the links to this section

@camilamacedo86
Copy link
Contributor Author

Really thank you for your time @jmrodri and help with this review.
All suggestions are applied now.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Oct 7, 2020
Copy link
Member

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 14, 2020
@camilamacedo86 camilamacedo86 merged commit 6eb3129 into operator-framework:master Oct 14, 2020
@camilamacedo86 camilamacedo86 deleted the doc-tests branch October 14, 2020 14:15
estroz pushed a commit to estroz/operator-sdk that referenced this pull request Oct 14, 2020
…perator-framework#3823)

**Description of the change:**
doc: add base doc to clarifies how users can test their projects

**Motivation for the change:**
Many users have raised these questions. The goal of this doc is to provide the basic information and the links/references for they are able to move forward. It can be improved by the community and/or in the post 1.0 doc plans. 

Closes: operator-framework#3511
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need references/documentation for unit testing
4 participants