github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/store/etcdv3/embedded/embeded.go (about)

     1  package embedded
     2  
     3  import (
     4  	"flag"
     5  	"os"
     6  	"testing"
     7  
     8  	"go.etcd.io/etcd/client/v3/namespace"
     9  	"go.etcd.io/etcd/tests/v3/integration"
    10  )
    11  
    12  var clusters map[string]*integration.ClusterV3 = map[string]*integration.ClusterV3{}
    13  
    14  // NewCluster new a embedded cluster
    15  func NewCluster(t *testing.T, prefix string) *integration.ClusterV3 {
    16  	cluster := clusters[t.Name()]
    17  	if cluster == nil {
    18  		os.Args = []string{"test.short=false"}
    19  		testing.Init()
    20  		flag.Parse()
    21  		integration.BeforeTestExternal(t)
    22  		cluster = integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
    23  		t.Cleanup(func() {
    24  			cluster.Terminate(t)
    25  			delete(clusters, t.Name())
    26  		})
    27  		cliv3 := cluster.RandClient()
    28  		cliv3.KV = namespace.NewKV(cliv3.KV, prefix)
    29  		cliv3.Watcher = namespace.NewWatcher(cliv3.Watcher, prefix)
    30  		cliv3.Lease = namespace.NewLease(cliv3.Lease, prefix)
    31  		clusters[t.Name()] = cluster
    32  	}
    33  	return cluster
    34  }