-
Notifications
You must be signed in to change notification settings - Fork 55
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
Add envtest controller tests for DevWorkspaces #957
Conversation
Skipping CI for Draft Pull Request. |
970f556
to
755db23
Compare
Codecov ReportBase: 54.11% // Head: 52.36% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #957 +/- ##
==========================================
- Coverage 54.11% 52.36% -1.75%
==========================================
Files 44 46 +2
Lines 2770 4289 +1519
==========================================
+ Hits 1499 2246 +747
- Misses 1135 1841 +706
- Partials 136 202 +66
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
755db23
to
a5fcf48
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome to me so far :)
One additional note:
The README should probably be updated to specify that go v1.17 is required, as well as Ginkgo CLI v2.0.0 (I initially tried v.2.4.0, and it wouldn't work).
controllers/workspace/util_test.go
Outdated
By("Loading DevWorkspace from test file") | ||
devworkspace := &dw.DevWorkspace{} | ||
err := loadObjectFromFile(name, devworkspace, fromFile) | ||
Expect(err).NotTo(HaveOccurred()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is purely stylistic, but error checks for loadObjectFromFile
like this one could be written: Expect(loadObjectFromFile(name, devworkspace, fromFile)).Should(Succeed())
Obviously, there's a tradeoff: you lose a line of code and don't care have to declare err
, but it's a bit more verbose of a line to write out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea -- updated the PR.
} | ||
} | ||
|
||
func namespacedName(name, namespace string) types.NamespacedName { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a future PR, we probably should add a similar function to use elsewhere in the codebase 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if you think this is worthwhile, and I'll create an issue about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, I think it's probably not worth a separate package that has to be imported everywhere. Golang is a language that includes code duplication by design 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not worth a separate package that has to be imported everywhere
Agreed +1
Golang is a language that includes code duplication by design 🤷
Very true ;P
make test | ||
- | ||
name: Build Codecov report |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason why this step was added to the PR CI action? The code-coverage CI action already occurs on pull-requests.
I know codecov was acting weird for this PR - I assume it's because there's no controller.cover.out
being referenced by codecov on the main branch, so it has nothing to compare the coverage against.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the Codecov action was also disabled for PRs; previously we were running the tests as part of the PR check and generating coverage files, and then running them again as part of the Codecov action; it's easier to just upload the already-generated files.
I should break this out into a separate PR perhaps; maybe that would fix the codecov weirdness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's easier to just upload the already-generated files
Agreed, it'll speed things up. If we do this, it's probably worth removing the PR trigger for the code coverage action (and only have it run on push to main), cause otherwise it will get run twice for PR's (I would imagine?).
I should break this out into a separate PR perhaps; maybe that would fix the codecov weirdness?
It should fix the weirdness because then there will be a reference point of coverage % for controller.cover.out
on the main branch. But if this causes other problems, then it's totally fine to leave it. Future PR's should not have this issue once the controller.cover.out
is uploaded to codecov.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, it'll speed things up. If we do this, it's probably worth removing the PR trigger for the code coverage action (and only have it run on push to main), cause otherwise it will get run twice for PR's (I would imagine?).
I thought I had already done this -- https://github.com/devfile/devworkspace-operator/pull/957/files#diff-49708f979e226a1e7bd7a68d71b2e91aae8114dd3e9254d9830cd3b4d62d4303L7-L8. Is anything else required?
My understanding is that codecov merges all uploaded files: https://docs.codecov.com/docs/merging-reports. I think this means that it should correctly compute a diff even if we were to e.g. split coverage reports per package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I had already done this -- #957 (files). Is anything else required?
Oops I forgot about that when I wrote this - that should be all that's needed for the code coverage action.
My understanding is that codecov merges all uploaded files: docs.codecov.com/docs/merging-reports. I think this means that it should correctly compute a diff even if we were to e.g. split coverage reports per package.
Yes, that seems to be the case. My theory about the controller.cover.out
not being present on master doesn't seem to hold up then.
I think it's okay to just include the CI changes in this PR and if codecov continues to display incorrect coverage reports after this PR is merged, I will look into it.
a5fcf48
to
b54b578
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: amisevsk, AObuchow, ibuziuk The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Update to testing packages Ginkgo and Gomega to version expected by kubebuilder bootstrapped test files. This requires minor updates to the previous end to end tests as Ginkgo v2 does not support custom reporters in the same way. Signed-off-by: Angel Misevski <[email protected]>
Bootstrap test files for DevWorkspace controller and add a basic DevWorkspace creation test. Signed-off-by: Angel Misevski <[email protected]>
Add controller tests to cover creation of various objects used workspaces (roles, rolebindings, devworkspaceroutings, deployments, etc.) Verify that each created object is owned by the DevWorkspace that defines it. Signed-off-by: Angel Misevski <[email protected]>
Introduce a fake http.Transport to allow simulating responses to HTTP calls in DevWorkspace Operator tests. This is required for testing that DevWorkspaces with mainUrls can enter the Running state. Signed-off-by: Angel Misevski <[email protected]>
Add test to verify that workspaces can enter the running state Signed-off-by: Angel Misevski <[email protected]>
Fix issue where workspaces with a mainUrl with path that did not end in a '/' resulted in the incorrect path for the '/healthz' endpoint due to DWO only concatenating strings. Signed-off-by: Angel Misevski <[email protected]>
Extract common test functionality to functions that can be reused to make test code less painfully long. Signed-off-by: Angel Misevski <[email protected]>
Add test cases covering automatic mounting of image pull secrets, configmaps/secrets, git credentials. Signed-off-by: Angel Misevski <[email protected]>
Rework makefile rules to automatically download binaries needed for running envtest tests. New versions of envtest ship a binary instead of shell script, making the install process different, so the new rules are copied from the Makefile bootstrapped by recent versions of controller-gen Signed-off-by: Angel Misevski <[email protected]>
Add fixups for tests (originally written in January 2022) to accommodate changes to DevWorkspace controller functionality since then. Signed-off-by: Angel Misevski <[email protected]>
Regenerate DeepCopy files for CRDs after switching how controller-gen is downloaded. Previously, we would download + build controller-gen locally and use that in scripts. Now we `go install` it to ./bin and use that, which is a lot simpler. However, despite both instances using controller-gen v0.6.1, the output of deepcopy-gen is different: Previously, locally-built controller gen included the line //go:build !ignore_autogenerated at the top of deepcopy files The new, `go install`ed version omits this line. ¯\_(ツ)_/¯ Signed-off-by: Angel Misevski <[email protected]>
Signed-off-by: Angel Misevski <[email protected]>
Signed-off-by: Angel Misevski <[email protected]>
Signed-off-by: Angel Misevski <[email protected]>
Creating multiple workspaces during a test is required for testing functionality that only triggers when multiple workspaces exist (e.g. PVC cleanup) Signed-off-by: Angel Misevski <[email protected]>
Signed-off-by: Angel Misevski <[email protected]>
Signed-off-by: Angel Misevski <[email protected]>
* Update make rule to run envtest tests using Ginkgo CLI if available * Update github actions to install ginkgo and upload both coverage files * Allow skipping envtest tests by setting env var Signed-off-by: Angel Misevski <[email protected]>
Signed-off-by: Angel Misevski <[email protected]>
Signed-off-by: Angel Misevski <[email protected]>
b54b578
to
490987d
Compare
New changes are detected. LGTM label has been removed. |
* Test new ServiceAccount behavior (role binds to individual serviceaccounts rather than all SAs in namespace) * Set default PodSecurityContext when using a config for testing to accomodate changes around how PodSecurityContext is handled in OpenShift Signed-off-by: Angel Misevski <[email protected]>
What does this PR do?
Sets up tooling and configuration to allow running controller tests via envtest. These tests work by launching a control plane and allowing the controller to "interact" with it -- i.e. creating DevWorkspaces and related objects.
Currently a draft PR as this is a revival of something I started back in January and hadn't touched again until a few weeks ago; I'm not sure the overall quality.
Tests can still be run without installing the ginkgo CLI, but the output is nicer if it's present.
Controller-gen assumes a newer version of ginkgo/gomega than was used previously; these packages are updated and that requires updates to existing e2e test code.
Docs:
What issues does this PR fix or reference?
Closes #930
Is it tested? How?
They're tests :)
PR Checklist
/test v8-devworkspace-operator-e2e, v8-che-happy-path
to trigger)v8-devworkspace-operator-e2e
: DevWorkspace e2e testv8-che-happy-path
: Happy path for verification integration with Che