Skip to content

Commit 1fb82ee

Browse files
committed
etcd: New function signature updated
Now etcd.New accepts a minimal interface instead of a concrete implementation. This makes it easier to use mocks when etcd.New is called inside some code.
1 parent 9601e22 commit 1fb82ee

2 files changed

Lines changed: 12 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
### Changed
1313

14+
- driver.etcd: etcd.New now accepts an interface that is compatible with
15+
`*etcdclientv3.Client` instead of the concrete type, which should not cause
16+
any issues when upgrading the version.
17+
1418
### Fixed
1519

1620
## [v1.1.2] - 2026-03-30

driver/etcd/etcd.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ import (
1818
"github.com/tarantool/go-storage/watch"
1919
)
2020

21-
// Client defines the minimal interface needed for etcd operations.
21+
// Client defines the minimal interface needed for etcd operations. It
22+
// is compatible with etcdclientv3.Client.
23+
//
2224
// This allows for easier testing and mock implementations.
2325
type Client interface {
26+
Watcher
27+
2428
// Txn creates a new transaction.
2529
Txn(ctx context.Context) etcd.Txn
2630
}
@@ -59,15 +63,6 @@ var (
5963
errUnsupportedOperationType = errors.New("unsupported operation type")
6064
)
6165

62-
// etcdClientAdapter wraps etcd.Client to implement our Client interface.
63-
type etcdClientAdapter struct {
64-
client *etcd.Client
65-
}
66-
67-
func (a *etcdClientAdapter) Txn(ctx context.Context) etcd.Txn {
68-
return a.client.Txn(ctx)
69-
}
70-
7166
// etcdWatcherAdapter wraps etcd.Watcher to implement our Watcher interface.
7267
type etcdWatcherAdapter struct {
7368
watcher etcd.Watcher
@@ -85,15 +80,7 @@ func (a *etcdWatcherAdapter) Close() error {
8580
type etcdWatcherFactory struct{}
8681

8782
func (f *etcdWatcherFactory) NewWatcher(client Client) Watcher {
88-
// For etcd clients, we need access to the underlying client.
89-
if adapter, ok := client.(*etcdClientAdapter); ok {
90-
return &etcdWatcherAdapter{
91-
watcher: etcd.NewWatcher(adapter.client),
92-
}
93-
}
94-
95-
// For other implementations, return a no-op watcher.
96-
return &noopWatcher{}
83+
return client
9784
}
9885

9986
// noopWatcher is a no-op implementation of Watcher for non-etcd clients.
@@ -112,9 +99,9 @@ func (w *noopWatcher) Close() error {
11299

113100
// New creates a new etcd driver instance using an existing etcd client.
114101
// The client should be properly configured and connected to an etcd cluster.
115-
func New(client *etcd.Client) *Driver {
102+
func New(client Client) *Driver {
116103
return &Driver{
117-
client: &etcdClientAdapter{client: client},
104+
client: client,
118105
watcherFactory: &etcdWatcherFactory{},
119106
}
120107
}

0 commit comments

Comments
 (0)