Skip to content

Commit

Permalink
fix Namespace in QueryOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
nfi-hashicorp committed Jun 29, 2023
1 parent 137c9db commit fb9b76a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
5 changes: 3 additions & 2 deletions test-integ/peering_commontopo/ac6_failovers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 5 additions & 4 deletions test-integ/peering_commontopo/ac7_2_rotate_leader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
Expand Down
10 changes: 5 additions & 5 deletions test-integ/peering_commontopo/asserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions test-integ/peering_commontopo/commontopo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 7 additions & 7 deletions test/integration/consul-container/libs/utils/tenancy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit fb9b76a

Please sign in to comment.