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:
parent
789cc85996
commit
aa5a16c4a7
2 changed files with 8 additions and 6 deletions
|
|
@ -23,11 +23,13 @@ func withTestRootPool(t *testing.T, ca *testCA, revoked []*big.Int) {
|
|||
pool := x509.NewCertPool()
|
||||
pool.AddCert(ca.Cert)
|
||||
rootPool = pool
|
||||
rootPoolOnce = sync.Once{}
|
||||
rootPoolOnce.Do(func() {}) // mark as done so RootPool() returns our pool
|
||||
doneOnce := &sync.Once{}
|
||||
doneOnce.Do(func() {}) // pre-mark as done so RootPool() returns our pool
|
||||
rootPoolOnce = doneOnce
|
||||
revokedSerials = revoked
|
||||
revokedOnce = sync.Once{}
|
||||
revokedOnce.Do(func() {}) // mark as done
|
||||
doneOnce2 := &sync.Once{}
|
||||
doneOnce2.Do(func() {})
|
||||
revokedOnce = doneOnce2
|
||||
|
||||
t.Cleanup(func() {
|
||||
rootPool = origPool
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ var rootCA2PEM []byte
|
|||
var revokedJSON []byte
|
||||
|
||||
var (
|
||||
rootPoolOnce sync.Once
|
||||
rootPoolOnce = &sync.Once{}
|
||||
rootPool *x509.CertPool
|
||||
|
||||
revokedOnce sync.Once
|
||||
revokedOnce = &sync.Once{}
|
||||
revokedSerials []*big.Int
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue