Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

spindle/secrets/openbao: speed up openbao unit tests by allowing connectionTimeout override

Signed-off-by: Evan Jarrett <evan@evanjarrett.com>

authored by

Evan Jarrett and committed by
oppiliappan
ed4b1ab1 a60331db

+20 -9
+15 -7
spindle/secrets/openbao.go
··· 13 13 ) 14 14 15 15 type OpenBaoManager struct { 16 - client *vault.Client 17 - mountPath string 18 - logger *slog.Logger 16 + client *vault.Client 17 + mountPath string 18 + logger *slog.Logger 19 + connectionTimeout time.Duration 19 20 } 20 21 21 22 type OpenBaoManagerOpt func(*OpenBaoManager) ··· 24 23 func WithMountPath(mountPath string) OpenBaoManagerOpt { 25 24 return func(v *OpenBaoManager) { 26 25 v.mountPath = mountPath 26 + } 27 + } 28 + 29 + func WithConnectionTimeout(timeout time.Duration) OpenBaoManagerOpt { 30 + return func(v *OpenBaoManager) { 31 + v.connectionTimeout = timeout 27 32 } 28 33 } 29 34 ··· 50 43 } 51 44 52 45 manager := &OpenBaoManager{ 53 - client: client, 54 - mountPath: "spindle", // default KV v2 mount path 55 - logger: logger, 46 + client: client, 47 + mountPath: "spindle", // default KV v2 mount path 48 + logger: logger, 49 + connectionTimeout: 10 * time.Second, // default connection timeout 56 50 } 57 51 58 52 for _, opt := range opts { ··· 70 62 71 63 // testConnection verifies that we can connect to the proxy 72 64 func (v *OpenBaoManager) testConnection() error { 73 - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 65 + ctx, cancel := context.WithTimeout(context.Background(), v.connectionTimeout) 74 66 defer cancel() 75 67 76 68 // try token self-lookup as a quick way to verify proxy works
+5 -2
spindle/secrets/openbao_test.go
··· 152 152 for _, tt := range tests { 153 153 t.Run(tt.name, func(t *testing.T) { 154 154 logger := slog.New(slog.NewTextHandler(os.Stderr, nil)) 155 - manager, err := NewOpenBaoManager(tt.proxyAddr, logger, tt.opts...) 155 + // Use shorter timeout for tests to avoid long waits 156 + opts := append(tt.opts, WithConnectionTimeout(1*time.Second)) 157 + manager, err := NewOpenBaoManager(tt.proxyAddr, logger, opts...) 156 158 157 159 if tt.expectError { 158 160 assert.Error(t, err) ··· 598 596 599 597 // All these will fail because no real proxy is running 600 598 // but we can test that the configuration is properly accepted 601 - manager, err := NewOpenBaoManager(tt.proxyAddr, logger) 599 + // Use shorter timeout for tests to avoid long waits 600 + manager, err := NewOpenBaoManager(tt.proxyAddr, logger, WithConnectionTimeout(1*time.Second)) 602 601 assert.Error(t, err) // Expected because no real proxy 603 602 assert.Nil(t, manager) 604 603 assert.Contains(t, err.Error(), "failed to connect to bao proxy")