func Mock(codec codec.Codec, logger log.Logger) (*Client, io.Closer, error) {
	dir, err := ioutil.TempDir("", "etcd")
	if err != nil {
		return nil, nil, err
	}

	cfg := embed.NewConfig()
	cfg.Logger = "zap"
	cfg.Dir = dir
	lpurl, _ := url.Parse("http://localhost:0")
	lcurl, _ := url.Parse("http://localhost:0")
	cfg.LPUrls = []url.URL{*lpurl}
	cfg.LCUrls = []url.URL{*lcurl}

	etcd, err := embed.StartEtcd(cfg)
	if err != nil {
		return nil, nil, err
	}

	select {
	case <-etcd.Server.ReadyNotify():
	case <-time.After(etcdStartTimeout):
		etcd.Server.Stop() // trigger a shutdown
		return nil, nil, fmt.Errorf("server took too long to start")
	}

	closer := CloserFunc(func() error {
		etcd.Server.Stop()
		return nil
	})

	var config Config
	flagext.DefaultValues(&config)

	client := &Client{
		cfg:    config,
		codec:  codec,
		cli:    v3client.New(etcd.Server),
		logger: logger,
	}

	return client, closer, nil
}
// Mock returns a Mock Etcd client.
// Inspired by https://github.com/ligato/cn-infra/blob/master/db/keyval/etcd/mocks/embeded_etcd.go.
Mock returns a Mock Etcd client.
// Mock returns a Mock Etcd client . // Inspired by https : // github . com / ligato / cn - infra / blob / master / db / keyval / etcd / mocks / embeded_etcd . go .
func Mock(codec codec.Codec, logger log.Logger) (*Client, io.Closer, error) {
	dir, err := ioutil.TempDir("", "etcd")
	if err != nil {
		return nil, nil, err
	}
	cfg := embed.NewConfig()
	cfg.Logger = "zap"
	cfg.Dir = dir
	lpurl, _ := url.Parse("http://localhost:0")
	lcurl, _ := url.Parse("http://localhost:0")
	cfg.LPUrls = []url.URL{*lpurl}
	cfg.LCUrls = []url.URL{*lcurl}
	etcd, err := embed.StartEtcd(cfg)
	if err != nil {
		return nil, nil, err
	}
	select {
	case <-etcd.Server.ReadyNotify():
	case <-time.After(etcdStartTimeout):
		etcd.Server.Stop() 
		return nil, nil, fmt.Errorf("server took too long to start")
	}
	closer := CloserFunc(func() error {
		etcd.Server.Stop()
		return nil
	})
	var config Config
	flagext.DefaultValues(&config)
	client := &Client{
		cfg:    config,
		codec:  codec,
		cli:    v3client.New(etcd.Server),
		logger: logger,
	}
	return client, closer, nil
}
func Mock ( codec codec . Codec , logger log . Logger ) ( * Client , io . Closer , error ) { dir , err := ioutil . TempDir ( " " , " " ) if err != nil { return nil , nil , err } cfg := embed . NewConfig ( ) cfg . Logger = " " cfg . Dir = dir lpurl , _ := url . Parse ( " " ) lcurl , _ := url . Parse ( " " ) cfg . LPUrls = [ ] url . URL { * lpurl } cfg . LCUrls = [ ] url . URL { * lcurl } etcd , err := embed . StartEtcd ( cfg ) if err != nil { return nil , nil , err } select { case <- etcd . Server . ReadyNotify ( ) : case <- time . After ( etcdStartTimeout ) : etcd . Server . Stop ( ) return nil , nil , fmt . Errorf ( " " ) } closer := CloserFunc ( func ( ) error { etcd . Server . Stop ( ) return nil } ) var config Config flagext . DefaultValues ( & config ) client := & Client { cfg : config , codec : codec , cli : v3client . New ( etcd . Server ) , logger : logger , } return client , closer , nil }
Mock returns a Mock Etcd client.
Mock returns a Mock Etcd client .
// trigger a shutdown