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 1f62594deb
commit 2a4d420c96
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
Datacenter string
// Providing a peer name in the query option
Peer string
// AllowStale allows any Consul server (non-leader) to service
// a read. This allows for lower latency and higher throughput
AllowStale bool
@ -812,6 +815,9 @@ func (r *request) setQueryOptions(q *QueryOptions) {
if q.Datacenter != "" {
r.params.Set("dc", q.Datacenter)
}
if q.Peer != "" {
r.params.Set("peer", q.Peer)
}
if q.AllowStale {
r.params.Set("stale", "")
}

View File

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