Using a temporary dir instead of a specified dir within embed etcd test (#16694)

Signed-off-by: yun.zhang <yun.zhang@zilliz.com>
This commit is contained in:
jaime 2022-04-28 11:17:47 +08:00 committed by GitHub
parent 7017756601
commit c0a73dbe98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ package etcdkv_test
import ( import (
"errors" "errors"
"io/ioutil"
"os" "os"
"testing" "testing"
"time" "time"
@ -38,12 +39,18 @@ func TestEmbedEtcd(te *testing.T) {
param.Init() param.Init()
param.BaseTable.Save("etcd.use.embed", "true") param.BaseTable.Save("etcd.use.embed", "true")
param.BaseTable.Save("etcd.config.path", "../../../configs/advanced/etcd.yaml") param.BaseTable.Save("etcd.config.path", "../../../configs/advanced/etcd.yaml")
param.BaseTable.Save("etcd.data.dir", "etcd.test.data.dir")
dir, err := ioutil.TempDir(os.TempDir(), "kv_etcd")
assert.Nil(te, err)
param.BaseTable.Save("etcd.data.dir", dir)
param.EtcdCfg.LoadCfgToMemory() param.EtcdCfg.LoadCfgToMemory()
//clean up data //clean up data
defer func() { defer func() {
os.RemoveAll("etcd.test.data.dir") err = os.RemoveAll(dir)
}() }()
te.Run("EtcdKV SaveAndLoad", func(t *testing.T) { te.Run("EtcdKV SaveAndLoad", func(t *testing.T) {
rootPath := "/etcd/test/root/saveandload" rootPath := "/etcd/test/root/saveandload"
metaKv, err := embed_etcd_kv.NewMetaKvFactory(rootPath, &param.EtcdCfg) metaKv, err := embed_etcd_kv.NewMetaKvFactory(rootPath, &param.EtcdCfg)