Skip to content

Commit 252ea51

Browse files
authored
chore: remove keychain warning for local tests (#697)
1 parent cbd2ae7 commit 252ea51

1 file changed

Lines changed: 5 additions & 16 deletions

File tree

pkg/keyring/keyring.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
package keyring
44

55
import (
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.
6865
func 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

0 commit comments

Comments
 (0)