Skip to content

Commit

Permalink
consul/connect: fixup tests to use new consul sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed Aug 24, 2020
1 parent f4ea3a5 commit db8020f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion client/allocrunner/groupservice_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/allocrunner/taskrunner/connect_native_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion client/allocrunner/taskrunner/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion command/agent/consul/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions command/agent/consul/int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -189,24 +189,24 @@ 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[:]

// 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 {
Expand Down Expand Up @@ -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")
}
3 changes: 0 additions & 3 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit db8020f

Please sign in to comment.