From c0a73dbe9896249c4af177dd10677b2279ee4933 Mon Sep 17 00:00:00 2001 From: jaime Date: Thu, 28 Apr 2022 11:17:47 +0800 Subject: [PATCH] Using a temporary dir instead of a specified dir within embed etcd test (#16694) Signed-off-by: yun.zhang --- internal/kv/etcd/embed_etcd_kv_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/kv/etcd/embed_etcd_kv_test.go b/internal/kv/etcd/embed_etcd_kv_test.go index e83e79ad18..b197f32f77 100644 --- a/internal/kv/etcd/embed_etcd_kv_test.go +++ b/internal/kv/etcd/embed_etcd_kv_test.go @@ -18,6 +18,7 @@ package etcdkv_test import ( "errors" + "io/ioutil" "os" "testing" "time" @@ -38,12 +39,18 @@ func TestEmbedEtcd(te *testing.T) { param.Init() param.BaseTable.Save("etcd.use.embed", "true") 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() + //clean up data defer func() { - os.RemoveAll("etcd.test.data.dir") + err = os.RemoveAll(dir) }() + te.Run("EtcdKV SaveAndLoad", func(t *testing.T) { rootPath := "/etcd/test/root/saveandload" metaKv, err := embed_etcd_kv.NewMetaKvFactory(rootPath, ¶m.EtcdCfg)