Added QueryOptions for status api (#7818)
* Added QueryOptions & Tests for status api
This commit is contained in:
parent
b3eafef6b0
commit
bad3b6e305
|
@ -11,8 +11,9 @@ func (c *Client) Status() *Status {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leader is used to query for a known leader
|
// Leader is used to query for a known leader
|
||||||
func (s *Status) Leader() (string, error) {
|
func (s *Status) Leader(q *QueryOptions) (string, error) {
|
||||||
r := s.c.newRequest("GET", "/v1/status/leader")
|
r := s.c.newRequest("GET", "/v1/status/leader")
|
||||||
|
r.setQueryOptions(q)
|
||||||
_, resp, err := requireOK(s.c.doRequest(r))
|
_, resp, err := requireOK(s.c.doRequest(r))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -27,8 +28,9 @@ func (s *Status) Leader() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peers is used to query for a known raft peers
|
// Peers is used to query for a known raft peers
|
||||||
func (s *Status) Peers() ([]string, error) {
|
func (s *Status) Peers(q *QueryOptions) ([]string, error) {
|
||||||
r := s.c.newRequest("GET", "/v1/status/peers")
|
r := s.c.newRequest("GET", "/v1/status/peers")
|
||||||
|
r.setQueryOptions(q)
|
||||||
_, resp, err := requireOK(s.c.doRequest(r))
|
_, resp, err := requireOK(s.c.doRequest(r))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,7 +13,11 @@ func TestAPI_StatusLeader(t *testing.T) {
|
||||||
|
|
||||||
status := c.Status()
|
status := c.Status()
|
||||||
|
|
||||||
leader, err := status.Leader()
|
opts := QueryOptions{
|
||||||
|
Datacenter: "dc1",
|
||||||
|
}
|
||||||
|
|
||||||
|
leader, err := status.Leader(&opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +34,10 @@ func TestAPI_StatusPeers(t *testing.T) {
|
||||||
|
|
||||||
status := c.Status()
|
status := c.Status()
|
||||||
|
|
||||||
peers, err := status.Peers()
|
opts := QueryOptions{
|
||||||
|
Datacenter: "dc1",
|
||||||
|
}
|
||||||
|
peers, err := status.Peers(&opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -37,3 +45,39 @@ func TestAPI_StatusPeers(t *testing.T) {
|
||||||
t.Fatalf("Expected peers ")
|
t.Fatalf("Expected peers ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAPI_StatusLeader_WrongDC(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
c, s := makeClient(t)
|
||||||
|
defer s.Stop()
|
||||||
|
s.WaitForSerfCheck(t)
|
||||||
|
|
||||||
|
status := c.Status()
|
||||||
|
|
||||||
|
opts := QueryOptions{
|
||||||
|
Datacenter: "wrong_dc1",
|
||||||
|
}
|
||||||
|
_, err := status.Leader(&opts)
|
||||||
|
require.Error(err)
|
||||||
|
require.Contains(err.Error(), "No path to datacenter")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAPI_StatusPeers_WrongDC(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
c, s := makeClient(t)
|
||||||
|
defer s.Stop()
|
||||||
|
s.WaitForSerfCheck(t)
|
||||||
|
|
||||||
|
status := c.Status()
|
||||||
|
|
||||||
|
opts := QueryOptions{
|
||||||
|
Datacenter: "wrong_dc1",
|
||||||
|
}
|
||||||
|
_, err := status.Peers(&opts)
|
||||||
|
require.Error(err)
|
||||||
|
require.Contains(err.Error(), "No path to datacenter")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue