From e9e2c599dbed1475a0fcf6f5be4723ef8bae376d Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Mon, 26 Jun 2017 10:44:36 +0200 Subject: [PATCH] rpc: refactor: unify test server setup --- agent/consul/server_test.go | 38 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/agent/consul/server_test.go b/agent/consul/server_test.go index 9dce9dc6d5..36ad92ffce 100644 --- a/agent/consul/server_test.go +++ b/agent/consul/server_test.go @@ -76,36 +76,32 @@ func testServerConfig(t *testing.T, NodeName string) (string, *Config) { } 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) { - 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) { - name := fmt.Sprintf("Node %d", getPort()) - dir, config := testServerConfig(t, name) - config.Datacenter = dc - config.Bootstrap = bootstrap - server, err := NewServer(config) - if err != nil { - t.Fatalf("err: %v", err) - } - return dir, server + return testServerWithConfig(t, func(c *Config) { + c.Datacenter = dc + c.Bootstrap = bootstrap + }) } func testServerDCExpect(t *testing.T, dc string, expect int) (string, *Server) { - name := fmt.Sprintf("Node %d", getPort()) - dir, config := testServerConfig(t, name) - config.Datacenter = dc - config.Bootstrap = false - config.BootstrapExpect = expect - server, err := NewServer(config) - if err != nil { - t.Fatalf("err: %v", err) - } - return dir, server + return testServerWithConfig(t, func(c *Config) { + c.Datacenter = dc + c.Bootstrap = false + c.BootstrapExpect = expect + }) } func testServerWithConfig(t *testing.T, cb func(c *Config)) (string, *Server) {