func TestZookeeperCluster_EmptyMemberListCallback(t *testing.T) {
	assertion := assert.New(t)
	config := minimalGatewayConfig()
	conn, err := connectToZK()
	assertion.NoError(err)
	searchPath := clustering.CleanPath(config.ZookeeperPrefix) + clustering.CleanPath(clustering.ClusterMemberPath)
	err = conn.Delete(searchPath, 0)
	if err != nil && err != zk.ErrNoNode {
		assertion.NoError(fmt.Errorf("unable to delete test node: %v", err))
	}
	cluster := clustering.NewZookeeperClusterMember(config, conn, ZookeeperIntegrationTestMemberOne)
	assertion.NoError(cluster.MemberListCallback(func(add clustering.MemberID, remove clustering.MemberID) {}))
	conn.Close()
}
TODO (cmcintosh): enable this test
func TestZookeeperCluster_EmptyMemberList(t *testing.T) {
assertion := assert.New(t)

config := minimalGatewayConfig()
conn, err := connectToZK()
assertion.NoError(err)

searchPath := clustering.CleanPath(config.ZookeeperPrefix) + clustering.CleanPath(clustering.ClusterMemberPath)

err = conn.Delete(searchPath, 0)
if err != nil && err != zk.ErrNoNode {
assertion.NoError(fmt.Errorf("unable to delete test node: %v", err))
}

cluster := clustering.NewZookeeperClusterMember(config, conn, ZookeeperIntegrationTestMemberOne)
members, err := cluster.MemberList()
assertion.NoError(err)
assertion.Len(members, 0)

conn.Close()
}
package clustering_test
import (
	"fmt"
	"sync"
	"testing"
	"time"
	"github.com/go-zookeeper/zk"
	"github.com/stretchr/testify/assert"
	"github.com/openconfig/gnmi-gateway/gateway/clustering"
	"github.com/openconfig/gnmi-gateway/gateway/configuration"
)
const ZookeeperIntegrationServerAddress = "127.0.0.1:2181"
const ZookeeperIntegrationServerTimeout = 2 * time.Second
const ZookeeperIntegrationTestMemberOne = "127.0.0.1:2181"
const ZookeeperIntegrationTestMemberTwo = "127.0.0.2:2181"
type ZKLogger struct{}
func (z *ZKLogger) Printf(a string, b ...interface{}) {
	fmt.Println("Zookeeper:", a, b)
}
func connectToZK() (*zk.Conn, error) {
	newConn, _, err := zk.Connect([]string{ZookeeperIntegrationServerAddress}, ZookeeperIntegrationServerTimeout, zk.WithLogger(new(ZKLogger)))
	if err != nil {
		return nil, fmt.Errorf("unable to connect to Zookeeper integration server '%s': %v", ZookeeperIntegrationServerAddress, err)
	}
	start := time.Now()
	var state zk.State
	for time.Now().Before(start.Add(ZookeeperIntegrationServerTimeout)) {
		state = newConn.State()
		if state == zk.StateHasSession || state == zk.StateConnected {
			return newConn, nil
		}
	}
	return newConn, fmt.Errorf("timeout connecting to Zookeeper integration server '%s': %v", ZookeeperIntegrationServerAddress, state)
}
func minimalGatewayConfig() *configuration.GatewayConfig {
	return &configuration.GatewayConfig{
		ZookeeperPrefix:  "/gnmi/testgateway",
		ZookeeperTimeout: 1 * time.Second,
	}
}
func TestZookeeperCluster_Register(t *testing.T) {
	assertion := assert.New(t)
	config := minimalGatewayConfig()
	conn, err := connectToZK()
	assertion.NoError(err)
	cluster := clustering.NewZookeeperClusterMember(config, conn, ZookeeperIntegrationTestMemberOne)
	assertion.NoError(cluster.Register())
	members, err := cluster.MemberList()
	assertion.NoError(err)
	assertion.Len(members, 0)
	conn.Close()
}