fix(api): missing peer name in query option (#14835)

This commit is contained in:
cskh 2022-10-05 10:04:08 -04:00 committed by GitHub
parent 6fbe799178
commit 995671ff6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -111,6 +111,9 @@ type QueryOptions struct {
// by the Config // by the Config
Datacenter string Datacenter string
// Providing a peer name in the query option
Peer string
// AllowStale allows any Consul server (non-leader) to service // AllowStale allows any Consul server (non-leader) to service
// a read. This allows for lower latency and higher throughput // a read. This allows for lower latency and higher throughput
AllowStale bool AllowStale bool
@ -812,6 +815,9 @@ func (r *request) setQueryOptions(q *QueryOptions) {
if q.Datacenter != "" { if q.Datacenter != "" {
r.params.Set("dc", q.Datacenter) r.params.Set("dc", q.Datacenter)
} }
if q.Peer != "" {
r.params.Set("peer", q.Peer)
}
if q.AllowStale { if q.AllowStale {
r.params.Set("stale", "") r.params.Set("stale", "")
} }

View File

@ -763,6 +763,7 @@ func TestAPI_SetQueryOptions(t *testing.T) {
Namespace: "operator", Namespace: "operator",
Partition: "asdf", Partition: "asdf",
Datacenter: "foo", Datacenter: "foo",
Peer: "dc10",
AllowStale: true, AllowStale: true,
RequireConsistent: true, RequireConsistent: true,
WaitIndex: 1000, WaitIndex: 1000,
@ -779,6 +780,9 @@ func TestAPI_SetQueryOptions(t *testing.T) {
if r.params.Get("partition") != "asdf" { if r.params.Get("partition") != "asdf" {
t.Fatalf("bad: %v", r.params) t.Fatalf("bad: %v", r.params)
} }
if r.params.Get("peer") != "dc10" {
t.Fatalf("bad: %v", r.params)
}
if r.params.Get("dc") != "foo" { if r.params.Get("dc") != "foo" {
t.Fatalf("bad: %v", r.params) t.Fatalf("bad: %v", r.params)
} }