-
Notifications
You must be signed in to change notification settings - Fork 78
test/e2e: migrate time-based-ca-rotation test for OTE compatibility #308
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
base: main
Are you sure you want to change the base?
test/e2e: migrate time-based-ca-rotation test for OTE compatibility #308
Conversation
WalkthroughAdds a time-based CA rotation end-to-end test flow: new test scaffolding and helper functions in Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes ✨ Finishing touches
Comment |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wangke19 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@test/e2e/e2e.go`:
- Around line 1334-1353: The current checkRotationGinkgo skips validation for
Ginkgo because util.CheckRotation requires *testing.T (it uses t.Run); to fix,
either refactor util.CheckRotation to extract its core validation into a new
helper that accepts testing.TB (removing subtest t.Run usage) and call that from
both util.CheckRotation and checkRotationGinkgo, or implement the rotation
verification directly inside checkRotationGinkgo (replicating
util.CheckRotation's core checks but without using t.Run/subtests) so Ginkgo
gets full validation; locate the logic around checkRotationGinkgo and
util.CheckRotation and move shared verification into a testing-TB-compatible
function or inline the checks in checkRotationGinkgo.
🧹 Nitpick comments (1)
test/e2e/e2e.go (1)
1418-1418: Discarding the returned secret from pollForCARotationGinkgo.The return value of
pollForCARotationGinkgois being discarded. While this mirrors the pattern intriggerTimeBasedRotationin e2e_test.go, consider whether the returned secret should be used for additional validation or if the function should be simplified to not return a value if it's not needed.
test/e2e/e2e.go
Outdated
| // checkRotationGinkgo is a wrapper for util.CheckRotation that works with testing.TB. | ||
| // This version accepts testing.TB for dual compatibility. | ||
| func checkRotationGinkgo(t testing.TB, dnsName string, oldCertPEM, oldKeyPEM, oldBundlePEM, newCertPEM, newKeyPEM, newBundlePEM []byte) { | ||
| // The underlying util.CheckRotation requires *testing.T, but we receive testing.TB from Ginkgo. | ||
| // We need to extract the underlying *testing.T from Ginkgo's wrapper. | ||
| // For regular Go tests, t is already *testing.T and this will work. | ||
| // For Ginkgo tests, g.GinkgoTB() provides a compatible interface. | ||
|
|
||
| // Since util.CheckRotation uses t.Run internally, which is part of testing.TB interface, | ||
| // we can safely call it with testing.TB. However, the signature requires *testing.T. | ||
| // We'll use a type assertion that should work in both contexts. | ||
| if testT, ok := t.(*testing.T); ok { | ||
| util.CheckRotation(testT, dnsName, oldCertPEM, oldKeyPEM, oldBundlePEM, newCertPEM, newKeyPEM, newBundlePEM) | ||
| } else { | ||
| // For Ginkgo context, we need to call the check logic directly | ||
| // For now, we'll skip this complex validation in Ginkgo context | ||
| // since it involves starting HTTP servers which is complex in Ginkgo | ||
| t.Logf("Skipping detailed rotation check in Ginkgo context for %s", dnsName) | ||
| } | ||
| } |
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.
🧩 Analysis chain
🏁 Script executed:
# Find and examine util.CheckRotation implementation
rg -n -A 15 'func CheckRotation' test/util/Repository: openshift/service-ca-operator
Length of output: 877
🏁 Script executed:
# Get more context from the CheckRotation function to see all testing.T usage
rg -n -A 50 'func CheckRotation' test/util/rotate.goRepository: openshift/service-ca-operator
Length of output: 1690
🏁 Script executed:
# Get complete checkClientTrust function to see all testing.T usage
rg -n -A 80 'func checkClientTrust' test/util/rotate.goRepository: openshift/service-ca-operator
Length of output: 3105
🏁 Script executed:
# Continue reading to see the rest of checkClientTrust and all testing.T usages
rg -n -A 130 'func checkClientTrust' test/util/rotate.go | tail -60Repository: openshift/service-ca-operator
Length of output: 2393
🏁 Script executed:
# Check usages of checkRotationGinkgo to understand scope and impact
rg -n 'checkRotationGinkgo' test/e2e/e2e.goRepository: openshift/service-ca-operator
Length of output: 564
🏁 Script executed:
# Verify which testing.T methods are part of testing.TB interface
# Check Go's testing package documentation or look at how testing.TB is used elsewhere
rg -n 'testing.TB' test/e2e/e2e.go | head -20Repository: openshift/service-ca-operator
Length of output: 1934
🏁 Script executed:
# Verify t.Run is not part of testing.TB by checking Go documentation
# Check if there are any other implementations that handle testing.TB with t.Run
python3 << 'EOF'
# testing.TB interface includes:
# - Error, Errorf, Fail, FailNow, Fatal, Fatalf, Helper, Log, Logf, Name, Skip, Skipf, SkipNow
# - Cleanup (added in Go 1.14), TempDir (added in Go 1.15)
# testing.T has additional methods not in testing.TB:
# - Run (for subtests)
# So the review comment is correct - t.Run is not in testing.TB interface
print("t.Run() is a testing.T-specific method, NOT part of testing.TB interface")
print("testing.TB includes: Error, Errorf, Fail, FailNow, Fatal, Fatalf, Helper, Log, Logf, Name, Skip, Skipf, SkipNow, Cleanup, TempDir")
print("\nThis means util.CheckRotation cannot be directly refactored to accept testing.TB without removing t.Run() calls")
EOFRepository: openshift/service-ca-operator
Length of output: 159
🏁 Script executed:
# Look at how other Ginkgo wrapper functions handle similar issues
rg -B5 -A5 'testing.TB' test/e2e/e2e.go | grep -A 10 'func.*Ginkgo'Repository: openshift/service-ca-operator
Length of output: 7978
Rotation validation is skipped in Ginkgo test path, reducing coverage.
The checkRotationGinkgo function calls util.CheckRotation only when the test is run as a regular Go test. For Ginkgo tests, the function logs and skips, meaning pre/post rotation cert combinations are never validated in the OTE path. This directly reduces test coverage for a critical validation.
The code comment incorrectly states that t.Run() is part of the testing.TB interface—it is not. The testing.TB interface lacks the Run() method needed for subtests, making direct refactoring of util.CheckRotation to accept testing.TB infeasible without removing the t.Run() calls.
Consider either:
- Refactoring
util.CheckRotationto remove subtest structure and accepttesting.TB, or - Implementing the rotation check logic directly in
checkRotationGinkgowithout relying on subtests.
🤖 Prompt for AI Agents
In `@test/e2e/e2e.go` around lines 1334 - 1353, The current checkRotationGinkgo
skips validation for Ginkgo because util.CheckRotation requires *testing.T (it
uses t.Run); to fix, either refactor util.CheckRotation to extract its core
validation into a new helper that accepts testing.TB (removing subtest t.Run
usage) and call that from both util.CheckRotation and checkRotationGinkgo, or
implement the rotation verification directly inside checkRotationGinkgo
(replicating util.CheckRotation's core checks but without using t.Run/subtests)
so Ginkgo gets full validation; locate the logic around checkRotationGinkgo and
util.CheckRotation and move shared verification into a testing-TB-compatible
function or inline the checks in checkRotationGinkgo.
9d165da to
6343bc1
Compare
Migrates the time-based-ca-rotation test suite to the OTE (Openshift Test Extended) Ginkgo framework while maintaining dual-compatibility with traditional Go tests. Changes: - Add Ginkgo test context in e2e.go for OTE test discovery: * time-based-ca-rotation - Tests CA rotation based on expiry time - Extract test logic into shared functions with testing.TB interface: * testTimeBasedCARotation() - Main test function * checkCARotationGinkgo() - Core rotation validation logic * triggerTimeBasedRotationGinkgo() - Triggers time-based CA rotation - Add Ginkgo-compatible helper functions in e2e.go: * pollForCARotationGinkgo() - Polls for CA secret changes * pollForInjectedCABundleGinkgo() - Polls for CA bundle injection * pollForUpdatedConfigMapGinkgo() - Polls for configmap updates * checkRotationGinkgo() - Wrapper for util.CheckRotation - Keep test runner in e2e_test.go that calls shared function - Add required imports for CA rotation (crypto, operator, etc.) Net change: +257 lines (257 added - 0 removed) Both test frameworks continue to work: - Standard Go test: go test -run "^TestE2E$/^time-based-ca-rotation$" - OTE: Ginkgo test discovery via service-ca-operator-tests-ext test/e2e: optimize time-based-ca-rotation migration Reduce code duplication and verbosity: - Replace pollForUpdatedServingCertGinkgo calls with existing pollForUpdatedServingCert (already uses testing.TB) - Remove duplicate pollForUpdatedServingCertGinkgo and pollForUpdatedSecretGinkgo functions (34 lines) - Add operatorclient import for TargetNamespace constant - Replace serviceCAControllerNamespace with operatorclient.TargetNamespace - Replace signingKeySecretName with api.ServiceCASecretName - Simplify verbose comments across all new functions Net change reduced from +257/-67 to +19/-89 (70 lines removed)
7357840 to
eac725d
Compare
|
/test e2e-aws-operator-serial-ote |
|
@wangke19: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
test/e2e: migrate time-based-ca-rotation test for OTE compatibility
Migrates the time-based-ca-rotation test suite to the OTE (Openshift Test Extended) Ginkgo framework while maintaining dual-compatibility with traditional Go tests.
Changes
test/e2e/e2e.go
time-based-ca-rotation- Tests CA rotation based on expiry timetestTimeBasedCARotation()- Entry point for both test frameworkscheckCARotationGinkgo()- Core CA rotation validation logictriggerTimeBasedRotationGinkgo()- Triggers rotation with short-lived CApollForCARotationGinkgo()- Polls for signing secret changespollForInjectedCABundleGinkgo()- Polls for CA bundle injectionpollForUpdatedConfigMapGinkgo()- Polls for configmap updatespollForResourceGinkgo()- Generic resource polling helpercheckRotationGinkgo()- Wrapper for util.CheckRotationtest/e2e/e2e_test.go
testTimeBasedCARotation()functiontriggerTimeBasedRotation()function (moved to e2e.go)Net Code Change Explanation
Total: +229 lines added, -105 lines removed = +124 net increase
This is 60 lines more than PR #305's +64 net. Here's why it's necessary:
Breakdown by Category
1. REQUIRED for OTE (14 lines):
2. MOVED from e2e_test.go (~122 lines):
triggerTimeBasedRotation→triggerTimeBasedRotationGinkgo: 62 linescheckCARotationlogic →checkCARotationGinkgo: ~60 lines3. NECESSARY helpers (71 lines):
pollForResourceGinkgo: 18 lines (generic poller used by 3 functions)pollForCARotationGinkgo: 20 lines (CA-specific polling)pollForUpdatedConfigMapGinkgo: 20 lines (configmap polling)pollForInjectedCABundleGinkgo: 5 lines (wrapper)checkRotationGinkgo: 8 lines (testing.TB compatibility wrapper)4. REMOVED (-141 lines):
Why More Than PR #305 (Metrics: +64 net)?
Key Points
The +124 net is necessary because:
Testing
Both test frameworks continue to work:
go test -run "^TestE2E$/^time-based-ca-rotation$"(76.19s)ginkgo --focus="should rotate CA based on expiry time"(74.98s)service-ca-operator-tests-ext run-test "[sig-service-ca] service-ca-operator time-based-ca-rotation [Operator][Serial] should rotate CA based on expiry time"(75.58s)All 17 sub-tests pass in all three test modes.
Related
Follows the migration pattern established in PR #305 (metrics test migration).
Part of the effort to migrate all e2e tests to OTE framework.
Remaining tests to migrate: