From 80a171fc0df91e3a4c49e2cc53f8a2178aab43f6 Mon Sep 17 00:00:00 2001 From: Victor Castell Date: Thu, 12 Mar 2020 13:54:05 +0100 Subject: [PATCH] Fix tests --- dkron/agent_test.go | 43 ++++++++++++++++++++++++++++++++----------- dkron/api_test.go | 5 ++++- dkron/grpc_test.go | 4 +++- dkron/queries_test.go | 4 +++- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/dkron/agent_test.go b/dkron/agent_test.go index 7278b2dcc..222d8ee17 100644 --- a/dkron/agent_test.go +++ b/dkron/agent_test.go @@ -22,8 +22,12 @@ func TestAgentCommand_runForElection(t *testing.T) { a1Name := "test1" a2Name := "test2" - a1Addr := testutil.GetBindAddr().String() - a2Addr := testutil.GetBindAddr().String() + ip1, returnFn1 := testutil.TakeIP() + a1Addr := ip1.String() + defer returnFn1() + ip2, returnFn2 := testutil.TakeIP() + a2Addr := ip2.String() + defer returnFn2() shutdownCh := make(chan struct{}) defer close(shutdownCh) @@ -72,7 +76,9 @@ func TestAgentCommand_runForElection(t *testing.T) { // Start another agent c = DefaultConfig() - c.BindAddr = testutil.GetBindAddr().String() + ip3, returnFn3 := testutil.TakeIP() + defer returnFn3() + c.BindAddr = ip3.String() c.StartJoin = []string{a1Addr + ":8946"} c.NodeName = "test3" c.Server = true @@ -103,8 +109,13 @@ func Test_processFilteredNodes(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - a1Addr := testutil.GetBindAddr().String() - a2Addr := testutil.GetBindAddr().String() + ip1, returnFn1 := testutil.TakeIP() + defer returnFn1() + a1Addr := ip1.String() + + ip2, returnFn2 := testutil.TakeIP() + defer returnFn2() + a2Addr := ip2.String() c := DefaultConfig() c.BindAddr = a1Addr @@ -166,8 +177,11 @@ func TestEncrypt(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) + ip1, returnFn1 := testutil.TakeIP() + defer returnFn1() + c := DefaultConfig() - c.BindAddr = testutil.GetBindAddr().String() + c.BindAddr = ip1.String() c.NodeName = "test1" c.Server = true c.Tags = map[string]string{"role": "test"} @@ -190,10 +204,12 @@ func Test_getRPCAddr(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - a1Addr := testutil.GetBindAddr() + ip1, returnFn1 := testutil.TakeIP() + defer returnFn1() + a1Addr := ip1.String() c := DefaultConfig() - c.BindAddr = a1Addr.String() + ":5000" + c.BindAddr = a1Addr + ":5000" c.NodeName = "test1" c.Server = true c.Tags = map[string]string{"role": "test"} @@ -207,7 +223,7 @@ func Test_getRPCAddr(t *testing.T) { time.Sleep(2 * time.Second) getRPCAddr := a.getRPCAddr() - exRPCAddr := a1Addr.String() + ":6868" + exRPCAddr := a1Addr + ":6868" assert.Equal(t, exRPCAddr, getRPCAddr) a.Stop() @@ -218,10 +234,15 @@ func TestAgentConfig(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - advAddr := testutil.GetBindAddr().String() + ip1, returnFn1 := testutil.TakeIP() + defer returnFn1() + advAddr := ip1.String() + + ip2, returnFn2 := testutil.TakeIP() + defer returnFn2() c := DefaultConfig() - c.BindAddr = testutil.GetBindAddr().String() + c.BindAddr = ip2.String() c.AdvertiseAddr = advAddr c.LogLevel = logLevel c.DataDir = dir diff --git a/dkron/api_test.go b/dkron/api_test.go index 45047c88f..fd04a9a2e 100644 --- a/dkron/api_test.go +++ b/dkron/api_test.go @@ -19,8 +19,11 @@ func setupAPITest(t *testing.T, port string) (dir string, a *Agent) { dir, err := ioutil.TempDir("", "dkron-test") require.NoError(t, err) + ip1, returnFn1 := testutil.TakeIP() + defer returnFn1() + c := DefaultConfig() - c.BindAddr = testutil.GetBindAddr().String() + c.BindAddr = ip1.String() c.HTTPAddr = fmt.Sprintf("127.0.0.1:%s", port) c.NodeName = "test" c.Server = true diff --git a/dkron/grpc_test.go b/dkron/grpc_test.go index b9fa0b7bd..063ee216f 100644 --- a/dkron/grpc_test.go +++ b/dkron/grpc_test.go @@ -19,7 +19,9 @@ func TestGRPCExecutionDone(t *testing.T) { viper.Reset() - aAddr := testutil.GetBindAddr().String() + ip1, returnFn1 := testutil.TakeIP() + defer returnFn1() + aAddr := ip1.String() c := DefaultConfig() c.BindAddr = aAddr diff --git a/dkron/queries_test.go b/dkron/queries_test.go index 11f090dfe..ee1b1efa6 100644 --- a/dkron/queries_test.go +++ b/dkron/queries_test.go @@ -18,7 +18,9 @@ func TestRunQuery(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - advAddr := testutil.GetBindAddr().String() + ip1, returnFn1 := testutil.TakeIP() + defer returnFn1() + advAddr := ip1.String() c := DefaultConfig() c.BindAddr = advAddr + ":5000"