rpc: refactor: unify test server setup

This commit is contained in:
Frank Schroeder 2017-06-26 10:44:36 +02:00 committed by Frank Schröder
parent c803146550
commit e9e2c599db
1 changed files with 17 additions and 21 deletions

View File

@ -76,36 +76,32 @@ func testServerConfig(t *testing.T, NodeName string) (string, *Config) {
} }
func testServer(t *testing.T) (string, *Server) { func testServer(t *testing.T) (string, *Server) {
return testServerDC(t, "dc1") return testServerWithConfig(t, func(c *Config) {
c.Datacenter = "dc1"
c.Bootstrap = true
})
} }
func testServerDC(t *testing.T, dc string) (string, *Server) { func testServerDC(t *testing.T, dc string) (string, *Server) {
return testServerDCBootstrap(t, dc, true) return testServerWithConfig(t, func(c *Config) {
c.Datacenter = dc
c.Bootstrap = true
})
} }
func testServerDCBootstrap(t *testing.T, dc string, bootstrap bool) (string, *Server) { func testServerDCBootstrap(t *testing.T, dc string, bootstrap bool) (string, *Server) {
name := fmt.Sprintf("Node %d", getPort()) return testServerWithConfig(t, func(c *Config) {
dir, config := testServerConfig(t, name) c.Datacenter = dc
config.Datacenter = dc c.Bootstrap = bootstrap
config.Bootstrap = bootstrap })
server, err := NewServer(config)
if err != nil {
t.Fatalf("err: %v", err)
}
return dir, server
} }
func testServerDCExpect(t *testing.T, dc string, expect int) (string, *Server) { func testServerDCExpect(t *testing.T, dc string, expect int) (string, *Server) {
name := fmt.Sprintf("Node %d", getPort()) return testServerWithConfig(t, func(c *Config) {
dir, config := testServerConfig(t, name) c.Datacenter = dc
config.Datacenter = dc c.Bootstrap = false
config.Bootstrap = false c.BootstrapExpect = expect
config.BootstrapExpect = expect })
server, err := NewServer(config)
if err != nil {
t.Fatalf("err: %v", err)
}
return dir, server
} }
func testServerWithConfig(t *testing.T, cb func(c *Config)) (string, *Server) { func testServerWithConfig(t *testing.T, cb func(c *Config)) (string, *Server) {