-
Notifications
You must be signed in to change notification settings - Fork 12
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
Update TestBpfmanConfigReconcileAndDelete unit test to verify that the OpenShift SCC is deployed #65
Update TestBpfmanConfigReconcileAndDelete unit test to verify that the OpenShift SCC is deployed #65
Conversation
Introduce a new test helper function `setupTestEnvironment` to standardise the setup process for BpfmanConfigReconciler tests. This function handles the initialisation of the fake client, the registration of necessary types with the runtime scheme, and the configuration of the reconciler. The helper enables specific OpenShift testing by conditionally setting the RestrictedSCC field on the reconciler object. The logic is taken from the existing TestBpfmanConfigReconcileAndDelete function. The previous setup logic duplicated paths to various YAML files by pre-pending ../../. This new setup function dispenses with the duplicated paths by using the constants declared in the internal package and resolves the path at runtime to the actual files in the filesystem relative to the test directory. This allows us to refer to the canonical path without having to duplicate it, ensuring that if we ever change the filename then the test code doesn't need to be updated. This commit allows us to share the test setup logic so that we can subsequently modify TestBpfmanConfigReconcileAndDelete to verify that the Restricted SCC is created in the OpenShift test case, which was previously not tested. Signed-off-by: Andrew McDermott <[email protected]>
…Shift Refactor the TestBpfmanConfigReconcileAndDelete function to use a table-driven approach, enabling testing for both standard and OpenShift environments. This change introduces testing for OpenShift by verifying that the Restricted Security Context Constraints (SCC) is created and configured correctly when the isOpenShift flag is true. Additionally, this test identified that the Restricted SCC was not being deleted during the reconciliation process. The reconciler function has been updated to address this omission, ensuring proper cleanup of resources in the OpenShift case. The refactored test uses the new setupTestEnvironment helper function to standardise the setup process. Signed-off-by: Andrew McDermott <[email protected]>
4f27d9f
to
375cbf2
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65 +/- ##
==========================================
+ Coverage 27.39% 27.66% +0.27%
==========================================
Files 81 81
Lines 6968 6986 +18
==========================================
+ Hits 1909 1933 +24
+ Misses 4873 4864 -9
- Partials 186 189 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -173,6 +173,20 @@ func (r *BpfmanConfigReconciler) ReconcileBpfmanConfig(ctx context.Context, req | |||
return ctrl.Result{Requeue: true, RequeueAfter: retryDurationOperator}, nil | |||
} | |||
|
|||
if r.IsOpenshift { |
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 catch!!
/LGTM Thanks @frobware |
…/ocp-bpfman-agent chore(deps): update ocp-bpfman-agent to 1211a10
Fixes #27.
This pull request refactors the existing
TestBpfmanConfigReconcileAndDelete
function to verify that the OpenShift Security Context Constraints (SCC) resource is created and deleted during reconciliation. The previous implementation did not test the OpenShift case.Summary
setupTestEnvironment
helper function.TestBpfmanConfigReconcileAndDelete
to use a table-driven approach.These are the key changes:
Introduce
setupTestEnvironment
Helper Function:TestBpfmanConfigReconcileAndDelete
tests.RestrictedSCC
field on the reconciler object.Refactor
TestBpfmanConfigReconcileAndDelete
:isOpenShift
flag is true.setupTestEnvironment
helper function to standardise the setup process.