File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33package keyring
44
55import (
6- "crypto/rand"
7- "fmt"
86 "os"
97 "sync"
108
@@ -63,12 +61,13 @@ func (k *Keyring) IsAvailable() bool {
6361}
6462
6563// MockForTesting replaces the keyring backend with an in-memory store
66- // and resets the availability cache so subsequent New() calls reflect
67- // the mock.
64+ // and marks it as available so subsequent New() calls use the mock.
6865func MockForTesting () {
6966 keyring .MockInit ()
7067 keyringAvailableOnce = sync.Once {}
71- keyringAvailable = false
68+ keyringAvailableOnce .Do (func () {
69+ keyringAvailable = true
70+ })
7271}
7372
7473// isKeyringAvailable checks if the system keyring can be used
@@ -80,17 +79,7 @@ func isKeyringAvailable() bool {
8079 return
8180 }
8281
83- // Test if keyring is functional by attempting a dummy operation.
84- // Use a random suffix so a failed delete won't leave a colliding entry.
85- var buf [4 ]byte
86- _ , _ = rand .Read (buf [:])
87- testKey := fmt .Sprintf ("buildkite-cli-keyring-test-%x" , buf )
88- err := keyring .Set (serviceName , testKey , "test" )
89- if err != nil {
90- keyringAvailable = false
91- return
92- }
93- _ = keyring .Delete (serviceName , testKey )
82+ // Assume keyring is available; callers can handle errors
9483 keyringAvailable = true
9584 })
9685 return keyringAvailable
You can’t perform that action at this time.
0 commit comments