refactor(tests): update synchronization handling in certificate pool tests

- Replaced direct initialization of sync.Once instances with pointers to enhance clarity and consistency in the test setup.
- Updated the `withTestRootPool` function to use new `doneOnce` variables for managing synchronization, ensuring proper initialization of the root certificate pool and revoked serials.
This commit is contained in:
Max 2026-03-27 15:09:05 +08:00
parent 789cc85996
commit aa5a16c4a7
2 changed files with 8 additions and 6 deletions

View file

@ -23,11 +23,13 @@ func withTestRootPool(t *testing.T, ca *testCA, revoked []*big.Int) {
pool := x509.NewCertPool() pool := x509.NewCertPool()
pool.AddCert(ca.Cert) pool.AddCert(ca.Cert)
rootPool = pool rootPool = pool
rootPoolOnce = sync.Once{} doneOnce := &sync.Once{}
rootPoolOnce.Do(func() {}) // mark as done so RootPool() returns our pool doneOnce.Do(func() {}) // pre-mark as done so RootPool() returns our pool
rootPoolOnce = doneOnce
revokedSerials = revoked revokedSerials = revoked
revokedOnce = sync.Once{} doneOnce2 := &sync.Once{}
revokedOnce.Do(func() {}) // mark as done doneOnce2.Do(func() {})
revokedOnce = doneOnce2
t.Cleanup(func() { t.Cleanup(func() {
rootPool = origPool rootPool = origPool

View file

@ -19,10 +19,10 @@ var rootCA2PEM []byte
var revokedJSON []byte var revokedJSON []byte
var ( var (
rootPoolOnce sync.Once rootPoolOnce = &sync.Once{}
rootPool *x509.CertPool rootPool *x509.CertPool
revokedOnce sync.Once revokedOnce = &sync.Once{}
revokedSerials []*big.Int revokedSerials []*big.Int
) )