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
|
||||
func (s *Status) Leader() (string, error) {
|
||||
func (s *Status) Leader(q *QueryOptions) (string, error) {
|
||||
r := s.c.newRequest("GET", "/v1/status/leader")
|
||||
r.setQueryOptions(q)
|
||||
_, resp, err := requireOK(s.c.doRequest(r))
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -27,8 +28,9 @@ func (s *Status) Leader() (string, error) {
|
|||
}
|
||||
|
||||
// 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.setQueryOptions(q)
|
||||
_, resp, err := requireOK(s.c.doRequest(r))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -12,7 +13,11 @@ func TestAPI_StatusLeader(t *testing.T) {
|
|||
|
||||
status := c.Status()
|
||||
|
||||
leader, err := status.Leader()
|
||||
opts := QueryOptions{
|
||||
Datacenter: "dc1",
|
||||
}
|
||||
|
||||
leader, err := status.Leader(&opts)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
@ -29,7 +34,10 @@ func TestAPI_StatusPeers(t *testing.T) {
|
|||
|
||||
status := c.Status()
|
||||
|
||||
peers, err := status.Peers()
|
||||
opts := QueryOptions{
|
||||
Datacenter: "dc1",
|
||||
}
|
||||
peers, err := status.Peers(&opts)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
@ -37,3 +45,39 @@ func TestAPI_StatusPeers(t *testing.T) {
|
|||
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