kvdb/etcd: replace defer cleanup with t.Cleanup

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun committed 2022-10-13 17:47:03 +08:00
1 parent 945180f0ea
commit 889cb0af47
5 files changed
+17 -34

No files matched your search

+7 -14
View File
@@ -21,10 +21,9 @@ const (
// EtcdTestFixture holds internal state of the etcd test fixture.
type EtcdTestFixture struct {
t *testing.T
cli *clientv3.Client
config *Config
cleanup func()
t *testing.T
cli *clientv3.Client
config *Config
}
// NewTestEtcdInstance creates an embedded etcd instance for testing, listening
@@ -47,6 +46,7 @@ func NewEtcdTestFixture(t *testing.T) *EtcdTestFixture {
tmpDir := t.TempDir()
config, etcdCleanup := NewTestEtcdInstance(t, tmpDir)
t.Cleanup(etcdCleanup)
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{config.Host},
@@ -63,10 +63,9 @@ func NewEtcdTestFixture(t *testing.T) *EtcdTestFixture {
cli.Lease = namespace.NewLease(cli.Lease, defaultNamespace)
return &EtcdTestFixture{
t: t,
cli: cli,
config: config,
cleanup: etcdCleanup,
t: t,
cli: cli,
config: config,
}
}
@@ -133,9 +132,3 @@ func (f *EtcdTestFixture) Dump() map[string]string {
func (f *EtcdTestFixture) BackendConfig() Config {
return *f.config
}
// Cleanup should be called at test fixture teardown to stop the embedded
// etcd instance and remove all temp db files form the filesystem.
func (f *EtcdTestFixture) Cleanup() {
f.cleanup()
}