From db8020f4ebe0d81e6bab1dd34a4d0e5af694c069 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Mon, 24 Aug 2020 11:35:14 -0500 Subject: [PATCH] consul/connect: fixup tests to use new consul sdk --- client/allocrunner/groupservice_hook_test.go | 2 +- .../taskrunner/connect_native_hook_test.go | 2 +- .../taskrunner/template/template_test.go | 4 ++- command/agent/consul/group_test.go | 2 +- command/agent/consul/int_test.go | 26 +++++++++---------- nomad/structs/structs.go | 3 --- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/client/allocrunner/groupservice_hook_test.go b/client/allocrunner/groupservice_hook_test.go index 812d0a42f8b..405a2c8337b 100644 --- a/client/allocrunner/groupservice_hook_test.go +++ b/client/allocrunner/groupservice_hook_test.go @@ -203,7 +203,7 @@ func TestGroupServiceHook_getWorkloadServices(t *testing.T) { // COMPAT(0.11) Only valid for upgrades from 0.8. func TestGroupServiceHook_Update08Alloc(t *testing.T) { // Create an embedded Consul server - testconsul, err := ctestutil.NewTestServerConfig(func(c *ctestutil.TestServerConfig) { + testconsul, err := ctestutil.NewTestServerConfigT(t, func(c *ctestutil.TestServerConfig) { // If -v wasn't specified squelch consul logging if !testing.Verbose() { c.Stdout = ioutil.Discard diff --git a/client/allocrunner/taskrunner/connect_native_hook_test.go b/client/allocrunner/taskrunner/connect_native_hook_test.go index 9b12c89fa61..b4e420f6a4e 100644 --- a/client/allocrunner/taskrunner/connect_native_hook_test.go +++ b/client/allocrunner/taskrunner/connect_native_hook_test.go @@ -24,7 +24,7 @@ import ( ) func getTestConsul(t *testing.T) *consultest.TestServer { - testConsul, err := consultest.NewTestServerConfig(func(c *consultest.TestServerConfig) { + testConsul, err := consultest.NewTestServerConfigT(t, func(c *consultest.TestServerConfig) { if !testing.Verbose() { // disable consul logging if -v not set c.Stdout = ioutil.Discard c.Stderr = ioutil.Discard diff --git a/client/allocrunner/taskrunner/template/template_test.go b/client/allocrunner/taskrunner/template/template_test.go index 459149ca4fd..7c9db136856 100644 --- a/client/allocrunner/taskrunner/template/template_test.go +++ b/client/allocrunner/taskrunner/template/template_test.go @@ -154,7 +154,9 @@ func newTestHarness(t *testing.T, templates []*structs.Template, consul, vault b harness.taskDir = d if consul { - harness.consul, err = ctestutil.NewTestServer() + harness.consul, err = ctestutil.NewTestServerConfigT(t, func(c *ctestutil.TestServerConfig) { + // defaults + }) if err != nil { t.Fatalf("error starting test Consul server: %v", err) } diff --git a/command/agent/consul/group_test.go b/command/agent/consul/group_test.go index 2c9d33b5d80..9c38207fd2f 100644 --- a/command/agent/consul/group_test.go +++ b/command/agent/consul/group_test.go @@ -16,7 +16,7 @@ import ( func TestConsul_Connect(t *testing.T) { // Create an embedded Consul server - testconsul, err := testutil.NewTestServerConfig(func(c *testutil.TestServerConfig) { + testconsul, err := testutil.NewTestServerConfigT(t, func(c *testutil.TestServerConfig) { // If -v wasn't specified squelch consul logging if !testing.Verbose() { c.Stdout = ioutil.Discard diff --git a/command/agent/consul/int_test.go b/command/agent/consul/int_test.go index 76266bcb699..b4760a768f8 100644 --- a/command/agent/consul/int_test.go +++ b/command/agent/consul/int_test.go @@ -39,10 +39,10 @@ func TestConsul_Integration(t *testing.T) { if testing.Short() { t.Skip("-short set; skipping") } - require := require.New(t) + r := require.New(t) // Create an embedded Consul server - testconsul, err := testutil.NewTestServerConfig(func(c *testutil.TestServerConfig) { + testconsul, err := testutil.NewTestServerConfigT(t, func(c *testutil.TestServerConfig) { // If -v wasn't specified squelch consul logging if !testing.Verbose() { c.Stdout = ioutil.Discard @@ -133,7 +133,7 @@ func TestConsul_Integration(t *testing.T) { taskDir := allocDir.NewTaskDir(task.Name) vclient := vaultclient.NewMockVaultClient() consulClient, err := consulapi.NewClient(consulConfig) - require.Nil(err) + r.Nil(err) serviceClient := consul.NewServiceClient(consulClient.Agent(), testlog.HCLogger(t), true) defer serviceClient.Shutdown() // just-in-case cleanup @@ -165,7 +165,7 @@ func TestConsul_Integration(t *testing.T) { } tr, err := taskrunner.NewTaskRunner(config) - require.NoError(err) + r.NoError(err) go tr.Run() defer func() { // Make sure we always shutdown task runner when the test exits @@ -180,7 +180,7 @@ func TestConsul_Integration(t *testing.T) { // Block waiting for the service to appear catalog := consulClient.Catalog() res, meta, err := catalog.Service("httpd2", "test", nil) - require.Nil(err) + r.Nil(err) for i := 0; len(res) == 0 && i < 10; i++ { //Expected initial request to fail, do a blocking query @@ -189,7 +189,7 @@ func TestConsul_Integration(t *testing.T) { t.Fatalf("error querying for service: %v", err) } } - require.Len(res, 1) + r.Len(res, 1) // Truncate results res = res[:] @@ -197,16 +197,16 @@ func TestConsul_Integration(t *testing.T) { // Assert the service with the checks exists for i := 0; len(res) == 0 && i < 10; i++ { res, meta, err = catalog.Service("httpd", "http", &consulapi.QueryOptions{WaitIndex: meta.LastIndex + 1, WaitTime: 3 * time.Second}) - require.Nil(err) + r.Nil(err) } - require.Len(res, 1) + r.Len(res, 1) // Assert the script check passes (mock_driver script checks always // pass) after having time to run once time.Sleep(2 * time.Second) checks, _, err := consulClient.Health().Checks("httpd", nil) - require.Nil(err) - require.Len(checks, 2) + r.Nil(err) + r.Len(checks, 2) for _, check := range checks { if expected := "httpd"; check.ServiceName != expected { @@ -261,7 +261,7 @@ func TestConsul_Integration(t *testing.T) { // Ensure Consul is clean services, _, err := catalog.Services(nil) - require.Nil(err) - require.Len(services, 1) - require.Contains(services, "consul") + r.Nil(err) + r.Len(services, 1) + r.Contains(services, "consul") } diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 4da2c879544..ae555693465 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2518,16 +2518,13 @@ func (ns Networks) Copy() Networks { // Port assignment and IP for the given label or empty values. func (ns Networks) Port(label string) (string, int) { - fmt.Println("NS port label:", label) for _, n := range ns { for _, p := range n.ReservedPorts { - fmt.Println("reserved port, p:", p) if p.Label == label { return n.IP, p.Value } } for _, p := range n.DynamicPorts { - fmt.Println("dynamic port, p:", p) if p.Label == label { return n.IP, p.Value }