Skip to content

Commit

Permalink
backport of commit 1c44349 (#27388)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Black <[email protected]>
  • Loading branch information
1 parent 322b7f2 commit e171981
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions physical/raft/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,32 @@ import (
)

func GetRaft(t testing.TB, bootstrap bool, noStoreState bool) (*RaftBackend, string) {
return getRaftInternal(t, bootstrap, defaultRaftConfig(t, bootstrap, noStoreState), nil, nil)
return getRaftInternal(t, bootstrap, defaultRaftConfig(t, bootstrap, noStoreState), nil, nil, nil)
}

func GetRaftWithConfig(t testing.TB, bootstrap bool, noStoreState bool, conf map[string]string) (*RaftBackend, string) {
defaultConf := defaultRaftConfig(t, bootstrap, noStoreState)
conf["path"] = defaultConf["path"]
conf["doNotStoreLatestState"] = defaultConf["doNotStoreLatestState"]
return getRaftInternal(t, bootstrap, conf, nil, nil)
return getRaftInternal(t, bootstrap, conf, nil, nil, nil)
}

func GetRaftWithConfigAndSetupOpts(t testing.TB, bootstrap bool, noStoreState bool, conf map[string]string, setupOpts *SetupOpts) (*RaftBackend, string) {
defaultConf := defaultRaftConfig(t, bootstrap, noStoreState)
conf["path"] = defaultConf["path"]
conf["doNotStoreLatestState"] = defaultConf["doNotStoreLatestState"]
return getRaftInternal(t, bootstrap, conf, setupOpts, nil, nil)
}

func GetRaftWithConfigAndInitFn(t testing.TB, bootstrap bool, noStoreState bool, conf map[string]string, initFn func(b *RaftBackend)) (*RaftBackend, string) {
defaultConf := defaultRaftConfig(t, bootstrap, noStoreState)
conf["path"] = defaultConf["path"]
conf["doNotStoreLatestState"] = defaultConf["doNotStoreLatestState"]
return getRaftInternal(t, bootstrap, conf, nil, initFn)
return getRaftInternal(t, bootstrap, conf, nil, nil, initFn)
}

func GetRaftWithLogOutput(t testing.TB, bootstrap bool, noStoreState bool, logOutput io.Writer) (*RaftBackend, string) {
return getRaftInternal(t, bootstrap, defaultRaftConfig(t, bootstrap, noStoreState), logOutput, nil)
return getRaftInternal(t, bootstrap, defaultRaftConfig(t, bootstrap, noStoreState), nil, logOutput, nil)
}

func defaultRaftConfig(t testing.TB, bootstrap bool, noStoreState bool) map[string]string {
Expand All @@ -51,7 +58,7 @@ func defaultRaftConfig(t testing.TB, bootstrap bool, noStoreState bool) map[stri
return conf
}

func getRaftInternal(t testing.TB, bootstrap bool, conf map[string]string, logOutput io.Writer, initFn func(b *RaftBackend)) (*RaftBackend, string) {
func getRaftInternal(t testing.TB, bootstrap bool, conf map[string]string, setupOpts *SetupOpts, logOutput io.Writer, initFn func(b *RaftBackend)) (*RaftBackend, string) {
id, err := uuid.GenerateUUID()
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -85,7 +92,12 @@ func getRaftInternal(t testing.TB, bootstrap bool, conf map[string]string, logOu
t.Fatal(err)
}

err = backend.SetupCluster(context.Background(), SetupOpts{})
so := SetupOpts{}
if setupOpts != nil {
so = *setupOpts
}

err = backend.SetupCluster(context.Background(), so)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit e171981

Please sign in to comment.