func electorBecomesLeader(e *Elector, leader bool) error {
	event, err := getEvent(e, 5*time.Second)
	if err != nil {
		return err
	}
	if event.Err != nil {
		return errors.Wrap(event.Err, "event error")
	}
	if event.Leader != leader {
		return errors.Errorf("expected %v but got %v", leader, event.Leader)
	}
	return nil
}
leaderBecomes verifies that the elector emits a specific leader event
package elector
import (
	"testing"
	"time"
	"github.com/dcos/dcos-go/testutils"
	"github.com/pkg/errors"
	"github.com/stretchr/testify/require"
)
var basePath = "/leader/election/lock"
var opts = ConnectionOpts{}
func TestZookeeperPartition(t *testing.T) {
	require := require.New(t)
	zkCtl, err := testutils.StartZookeeper()
	require.NoError(err)
	defer zkCtl.TeardownPanic()
	e1, err := Start("foo", basePath, nil, NewConnection([]string{zkCtl.Addr()}, opts))
	require.NoError(err)
	defer e1.Close()
	require.NoError(electorBecomesLeader(e1, true))
	require.Equal("foo", e1.LeaderIdent())
	zkCtl.TeardownPanic()
	select {
	case e := <-e1.events:
		require.Error(e.Err)
	case <-time.After(5 * time.Second):
		t.Fatal("Timed out waiting for an error")
	}
}
func TestExpectedBehavior(t *testing.T) {
	require := require.New(t)
	zkCtl, err := testutils.StartZookeeper()
	require.NoError(err)
	defer zkCtl.TeardownPanic()
	e1, err := Start("e1", basePath, nil, NewConnection([]string{zkCtl.Addr()}, opts))
	require.NoError(err)
	defer e1.Close()
	require.NoError(electorBecomesLeader(e1, true))
	require.Equal("e1", e1.LeaderIdent())
	e2, err := Start("e2", basePath, nil, NewConnection([]string{zkCtl.Addr()}, opts))
	require.NoError(err)
	defer e2.Close()
	require.NoError(electorBecomesLeader(e2, false))
	require.Equal("e1", e1.LeaderIdent())
	require.Equal("e1", e2.LeaderIdent())
	require.NoError(e1.Close())
	require.NoError(electorBecomesLeader(e2, true))
	require.Equal("e2", e2.LeaderIdent())
}