-
Notifications
You must be signed in to change notification settings - Fork 115
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
Provider Unit Tests (Provider Lifecycle) #2768
Conversation
Does the PR have any schema changes?Looking good! No breaking changes found. |
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.
Changes mostly looks good to me. A few comments. I'm still curious how this suite sits amongst our existing vanilla Go unit tests? I'm still hesitant on introducing Ginkgo, but do see utility in BDD for testing the higher level provider calls. I still believe that regular Go table tests should be used for unit testing our lower level functions, and much prefer them over Gingko for such tests.
Thanks for taking the time to mock the clients though!
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #2768 +/- ##
==========================================
+ Coverage 18.41% 23.12% +4.71%
==========================================
Files 47 48 +1
Lines 9589 9620 +31
==========================================
+ Hits 1766 2225 +459
+ Misses 7724 7240 -484
- Partials 99 155 +56 ☔ View full report in Codecov by Sentry. |
Proposed changes
This PR implements a suite of unit tests for the provider implementation code in
provider/pkg/provider/provider.go
. Unlike the test suites intests/
, this suite uses a mock Kubernetes client and executes the provider code directly.This PR focuses on the provider lifecycle (e.g. plugin info and provider configuration):
In follow-up PR(s), tests will be developed for the resource lifecycle (eg.
Check
,Diff
,Read
,Create
,Update
,Delete
), and for invokes (Invoke
,StreamInvoke
).Changes to Implementation Code
Some minor refactoring was necessary to make it possible to substitute fake Kubernetes clients.
RESTMapper
field ofDynamicClientSet
was changed to an interface.client
field ofLogClient
was changed to an interface.makeClient
.makeClient
field tokubeProvider
as an indirection for test purposes.Running the Tests
The tests are written as a Ginkgo suite and is integrated with gotest via an ordinary test function called
TestSuite
insuite_test.go
. Here's howgo test
behaves:Here's a full example in a CI context.
One may also use the
ginkgo
CLI as a drop-in replacement with some niceties.There's a minor limitation of using
go test
, it is that the--parallel
flag doesn't work and causes Ginkgo to quit. The overall test pass is fast enough without parallelization and so I removed the flag for now. We could switch to using theginkgo
CLI (which runs the standard tests too) as an alternative solution.Related issues (optional)
Closes #2767