From 0285956fac17d3e25d0191338f7cdb1bbd2168f6 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 24 Jun 2020 12:56:46 -0400 Subject: [PATCH] Update TestAgent_GetCoordinate The old test case was a very specific regresion test for a case that is no longer possible. Replaced with a new test that checks the default coordinate is returned. --- agent/agent_test.go | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/agent/agent_test.go b/agent/agent_test.go index c1505d3ec..5bcea2604 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -29,12 +29,14 @@ import ( "github.com/hashicorp/consul/api" "github.com/hashicorp/consul/internal/go-sso/oidcauth/oidcauthtest" "github.com/hashicorp/consul/ipaddr" + "github.com/hashicorp/consul/lib" "github.com/hashicorp/consul/sdk/freeport" "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/sdk/testutil/retry" "github.com/hashicorp/consul/testrpc" "github.com/hashicorp/consul/types" "github.com/hashicorp/go-uuid" + "github.com/hashicorp/serf/coordinate" "github.com/hashicorp/serf/serf" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -3277,30 +3279,19 @@ func TestAgent_purgeCheckState(t *testing.T) { } func TestAgent_GetCoordinate(t *testing.T) { - t.Parallel() - check := func(t *testing.T, server bool) { - a := NewTestAgent(t, fmt.Sprintf(` - server = %v - bootstrap = %v - `, server, server)) - defer a.Shutdown() + a := NewTestAgent(t, ``) + defer a.Shutdown() - // This doesn't verify the returned coordinate, but it makes - // sure that the agent chooses the correct Serf instance, - // depending on how it's configured as a client or a server. - // If it chooses the wrong one, this will crash. - if _, err := a.GetLANCoordinate(); err != nil { - t.Fatalf("err: %s", err) - } + coords, err := a.GetLANCoordinate() + require.NoError(t, err) + expected := lib.CoordinateSet{ + "": &coordinate.Coordinate{ + Error: 1.5, + Height: 1e-05, + Vec: []float64{0, 0, 0, 0, 0, 0, 0, 0}, + }, } - - t.Run("server", func(t *testing.T) { - check(t, true) - }) - t.Run("client", func(t *testing.T) { - check(t, false) - }) - + require.Equal(t, expected, coords) } func TestAgent_reloadWatches(t *testing.T) {