-
Notifications
You must be signed in to change notification settings - Fork 31
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
(techdebt): refactor catalog controller unit tests #196
(techdebt): refactor catalog controller unit tests #196
Conversation
to no longer use Ginkgo and instead use the native Go testing and testify Signed-off-by: Bryce Palmer <everettraven@gmail.com>
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #196 +/- ##
==========================================
- Coverage 49.72% 46.15% -3.58%
==========================================
Files 6 6
Lines 366 364 -2
==========================================
- Hits 182 168 -14
- Misses 163 177 +14
+ Partials 21 19 -2
☔ View full report in Codecov by Sentry. |
// Having the parameterized fields allows us to easily change the values that are used in | ||
// the tests by changing them in one place as opposed to manually changing many string literals | ||
// throughout the code. | ||
const testBundleTemplate = `--- |
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.
Why was it valid to lose this?
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 was necessary when the reconcile()
function would call helper functions, passing the fs.FS
that was returned from the source.Unpacker.Unpack()
call, that would create the Package
, BundleMetadata
, and CatalogMetadata
CRs. Since this was happening as part of the reconciliation loop we had to ensure our MockSource
was returning an fs.FS
with a proper set of FBC files. Since we no longer do that and the logic for storing catalog contents is now abstracted + mocked for these unit tests we can provide an empty fs.FS
from our mock source.
This should instead be used when testing the storage logic directly and has already been duplicated over there previously:
catalogd/pkg/storage/localdir_test.go
Lines 155 to 184 in 9f3ba06
const testBundleTemplate = `--- | |
image: %s | |
name: %s | |
schema: olm.bundle | |
package: %s | |
relatedImages: | |
- name: %s | |
image: %s | |
properties: | |
- type: olm.bundle.object | |
value: | |
data: %s | |
- type: some.other | |
value: | |
data: arbitrary-info | |
` | |
const testPackageTemplate = `--- | |
defaultChannel: %s | |
name: %s | |
schema: olm.package | |
` | |
const testChannelTemplate = `--- | |
schema: olm.channel | |
package: %s | |
name: %s | |
entries: | |
- name: %s | |
` |
…ocks. goimports. Signed-off-by: Bryce Palmer <everettraven@gmail.com>
9f91fc5
Description:
HTTPServer
feature gate as there is no other logic for serving catalog contents which means this should now be the default.Catalog
controller unit tests to use pure Go testing + testify instead of Ginkgo.Catalog
controller tests and instead targets thereconcile()
function for unit testing.envtest
results in a ~90% decrease in time spent running the unit tests (on my M2 Macbook Airmain
runs tests for thepkg/controllers/core
package in ~6 seconds and this branch runs in ~.5 seconds)Reconcile()
function to make it easier to test the logic without usingenvtest
.SetupWithManager()
function as it wasn't really providing any valueMotivation