···1313)14141515type OpenBaoManager struct {1616- client *vault.Client1717- mountPath string1818- logger *slog.Logger1616+ client *vault.Client1717+ mountPath string1818+ logger *slog.Logger1919+ connectionTimeout time.Duration1920}20212122type OpenBaoManagerOpt func(*OpenBaoManager)···2423func WithMountPath(mountPath string) OpenBaoManagerOpt {2524 return func(v *OpenBaoManager) {2625 v.mountPath = mountPath2626+ }2727+}2828+2929+func WithConnectionTimeout(timeout time.Duration) OpenBaoManagerOpt {3030+ return func(v *OpenBaoManager) {3131+ v.connectionTimeout = timeout2732 }2833}2934···5043 }51445245 manager := &OpenBaoManager{5353- client: client,5454- mountPath: "spindle", // default KV v2 mount path5555- logger: logger,4646+ client: client,4747+ mountPath: "spindle", // default KV v2 mount path4848+ logger: logger,4949+ connectionTimeout: 10 * time.Second, // default connection timeout5650 }57515852 for _, opt := range opts {···70627163// testConnection verifies that we can connect to the proxy7264func (v *OpenBaoManager) testConnection() error {7373- ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)6565+ ctx, cancel := context.WithTimeout(context.Background(), v.connectionTimeout)7466 defer cancel()75677668 // try token self-lookup as a quick way to verify proxy works
+5-2
spindle/secrets/openbao_test.go
···152152 for _, tt := range tests {153153 t.Run(tt.name, func(t *testing.T) {154154 logger := slog.New(slog.NewTextHandler(os.Stderr, nil))155155- manager, err := NewOpenBaoManager(tt.proxyAddr, logger, tt.opts...)155155+ // Use shorter timeout for tests to avoid long waits156156+ opts := append(tt.opts, WithConnectionTimeout(1*time.Second))157157+ manager, err := NewOpenBaoManager(tt.proxyAddr, logger, opts...)156158157159 if tt.expectError {158160 assert.Error(t, err)···598596599597 // All these will fail because no real proxy is running600598 // but we can test that the configuration is properly accepted601601- manager, err := NewOpenBaoManager(tt.proxyAddr, logger)599599+ // Use shorter timeout for tests to avoid long waits600600+ manager, err := NewOpenBaoManager(tt.proxyAddr, logger, WithConnectionTimeout(1*time.Second))602601 assert.Error(t, err) // Expected because no real proxy603602 assert.Nil(t, manager)604603 assert.Contains(t, err.Error(), "failed to connect to bao proxy")