From fb9b76a02b685b33c815ab16f4e60a89f8c6aacc Mon Sep 17 00:00:00 2001 From: Nick Irvine <115657443+nfi-hashicorp@users.noreply.github.com> Date: Thu, 29 Jun 2023 11:51:41 -0700 Subject: [PATCH] fix Namespace in QueryOptions --- .../peering_commontopo/ac6_failovers_test.go | 5 +++-- .../peering_commontopo/ac7_2_rotate_leader_test.go | 9 +++++---- test-integ/peering_commontopo/asserter.go | 10 +++++----- test-integ/peering_commontopo/commontopo.go | 8 ++++---- .../consul-container/libs/utils/tenancy.go | 14 +++++++------- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/test-integ/peering_commontopo/ac6_failovers_test.go b/test-integ/peering_commontopo/ac6_failovers_test.go index 8fef666828f4..7b0a925520fa 100644 --- a/test-integ/peering_commontopo/ac6_failovers_test.go +++ b/test-integ/peering_commontopo/ac6_failovers_test.go @@ -348,8 +348,9 @@ func (s *ac6FailoversSuite) test(t *testing.T, ct *commonTopo) { require.Len(t, client.Upstreams, 1, "expected one upstream for client") u := client.Upstreams[0] - opts := utils.PartitionQueryOptions(u.ID.Partition) - ct.Assert.CatalogServiceExists(t, clu.Name, u.ID.Name, opts) + ct.Assert.CatalogServiceExists(t, clu.Name, u.ID.Name, utils.CompatQueryOpts(&api.QueryOptions{ + Partition: u.ID.Partition, + })) t.Cleanup(func() { cfg := ct.Sprawl.Config() diff --git a/test-integ/peering_commontopo/ac7_2_rotate_leader_test.go b/test-integ/peering_commontopo/ac7_2_rotate_leader_test.go index 3b6e3600688b..267e491ff51f 100644 --- a/test-integ/peering_commontopo/ac7_2_rotate_leader_test.go +++ b/test-integ/peering_commontopo/ac7_2_rotate_leader_test.go @@ -186,10 +186,11 @@ func (s *ac7_2RotateLeaderSuite) test(t *testing.T, ct *commonTopo) { // expect health entry in for peer to disappear retry.RunWith(&retry.Timer{Timeout: time.Minute, Wait: time.Millisecond * 500}, t, func(r *retry.R) { - opts := utils.PartitionQueryOptions(s.sidServer.Partition) - opts.Namespace = s.sidServer.Namespace - opts.Peer = LocalPeerName(peer, "default") - svcs, _, err := clDC.Health().Service(s.sidServer.Name, "", true, opts) + svcs, _, err := clDC.Health().Service(s.sidServer.Name, "", true, utils.CompatQueryOpts(&api.QueryOptions{ + Partition: s.sidServer.Partition, + Namespace: s.sidServer.Namespace, + Peer: LocalPeerName(peer, "default"), + })) require.NoError(r, err) assert.Equal(r, len(svcs), 0, "health entry for imported service gone") }) diff --git a/test-integ/peering_commontopo/asserter.go b/test-integ/peering_commontopo/asserter.go index a4586b542559..8540bf6bfd16 100644 --- a/test-integ/peering_commontopo/asserter.go +++ b/test-integ/peering_commontopo/asserter.go @@ -185,15 +185,15 @@ func (a *asserter) HealthyWithPeer(t *testing.T, cluster string, sid topology.Se t.Helper() cl := a.mustGetAPIClient(t, cluster) retry.RunWith(&retry.Timer{Timeout: time.Minute * 1, Wait: time.Millisecond * 500}, t, func(r *retry.R) { - opts := utils.PartitionQueryOptions(sid.Partition) - opts.Namespace = sid.Namespace - opts.Peer = peerName - svcs, _, err := cl.Health().Service( sid.Name, "", true, - opts, + utils.CompatQueryOpts(&api.QueryOptions{ + Partition: sid.Partition, + Namespace: sid.Namespace, + Peer: peerName, + }), ) require.NoError(r, err) assert.GreaterOrEqual(r, len(svcs), 1) diff --git a/test-integ/peering_commontopo/commontopo.go b/test-integ/peering_commontopo/commontopo.go index 378c189c460a..3bfb6bab0250 100644 --- a/test-integ/peering_commontopo/commontopo.go +++ b/test-integ/peering_commontopo/commontopo.go @@ -158,10 +158,10 @@ func (ct *commonTopo) postLaunchChecks(t *testing.T) { // TODO: these could probably be done in parallel for k, v := range eepp { retry.RunWith(&retry.Timer{Timeout: 30 * time.Second, Wait: 500 * time.Millisecond}, t, func(r *retry.R) { - opts := utils.PartitionQueryOptions(k.partition) - // not sure if we need to do a similar DefaultOrEmpty for namespace? - opts.Namespace = k.namespace - peering, _, err := cl.Peerings().Read(context.Background(), k.peer, opts) + peering, _, err := cl.Peerings().Read(context.Background(), k.peer, utils.CompatQueryOpts(&api.QueryOptions{ + Partition: k.partition, + Namespace: k.namespace, + })) require.Nil(r, err, "reading peering data") require.NotNilf(r, peering, "peering not found %q", k.peer) assert.Len(r, peering.StreamStatus.ExportedServices, v, "peering exported services") diff --git a/test/integration/consul-container/libs/utils/tenancy.go b/test/integration/consul-container/libs/utils/tenancy.go index c116a55a4c27..2254341ab59d 100644 --- a/test/integration/consul-container/libs/utils/tenancy.go +++ b/test/integration/consul-container/libs/utils/tenancy.go @@ -22,11 +22,11 @@ func DefaultToEmpty(name string) string { return name } -// PartitionQueryOptions returns an *api.QueryOptions with the given partition -// field set only if the partition is non-default. This helps when writing -// tests for joint use in OSS and ENT. -func PartitionQueryOptions(partition string) *api.QueryOptions { - return &api.QueryOptions{ - Partition: DefaultToEmpty(partition), - } +// CompatQueryOpts cleans a QueryOptions so that Partition and Namespace fields +// are compatible with OSS or ENT +// TODO: not sure why we can't do this server-side +func CompatQueryOpts(opts *api.QueryOptions) *api.QueryOptions { + opts.Partition = DefaultToEmpty(opts.Partition) + opts.Namespace = DefaultToEmpty(opts.Namespace) + return opts }