Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: restore Leader() and Peers() to avoid breaking function signatures #8395

Merged
merged 2 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions api/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ func (c *Client) Status() *Status {
}

// Leader is used to query for a known leader
func (s *Status) Leader(q *QueryOptions) (string, error) {
func (s *Status) LeaderWithQueryOptions(q *QueryOptions) (string, error) {
r := s.c.newRequest("GET", "/v1/status/leader")
r.setQueryOptions(q)

if q != nil {
r.setQueryOptions(q)
}

_, resp, err := requireOK(s.c.doRequest(r))
if err != nil {
return "", err
Expand All @@ -27,10 +31,18 @@ func (s *Status) Leader(q *QueryOptions) (string, error) {
return leader, nil
}

func (s *Status) Leader() (string, error) {
return s.LeaderWithQueryOptions(nil)
}

// Peers is used to query for a known raft peers
func (s *Status) Peers(q *QueryOptions) ([]string, error) {
func (s *Status) PeersWithQueryOptions(q *QueryOptions) ([]string, error) {
r := s.c.newRequest("GET", "/v1/status/peers")
r.setQueryOptions(q)

if q != nil {
r.setQueryOptions(q)
}

_, resp, err := requireOK(s.c.doRequest(r))
if err != nil {
return nil, err
Expand All @@ -43,3 +55,7 @@ func (s *Status) Peers(q *QueryOptions) ([]string, error) {
}
return peers, nil
}

func (s *Status) Peers() ([]string, error) {
return s.PeersWithQueryOptions(nil)
}
29 changes: 22 additions & 7 deletions api/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,28 @@ func TestAPI_StatusLeader(t *testing.T) {

status := c.Status()

leader, err := status.Leader()
if err != nil {
t.Fatalf("err: %v", err)
}
if leader == "" {
t.Fatalf("Expected leader")
}
}

func TestAPI_StatusLeaderWithQueryOptions(t *testing.T) {
t.Parallel()
c, s := makeClient(t)
defer s.Stop()
s.WaitForSerfCheck(t)

status := c.Status()

opts := QueryOptions{
Datacenter: "dc1",
}

leader, err := status.Leader(&opts)
leader, err := status.LeaderWithQueryOptions(&opts)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand All @@ -34,10 +51,7 @@ func TestAPI_StatusPeers(t *testing.T) {

status := c.Status()

opts := QueryOptions{
Datacenter: "dc1",
}
peers, err := status.Peers(&opts)
peers, err := status.Peers()
if err != nil {
t.Fatalf("err: %v", err)
}
Expand All @@ -59,7 +73,8 @@ func TestAPI_StatusLeader_WrongDC(t *testing.T) {
opts := QueryOptions{
Datacenter: "wrong_dc1",
}
_, err := status.Leader(&opts)

_, err := status.LeaderWithQueryOptions(&opts)
require.Error(err)
require.Contains(err.Error(), "No path to datacenter")
}
Expand All @@ -77,7 +92,7 @@ func TestAPI_StatusPeers_WrongDC(t *testing.T) {
opts := QueryOptions{
Datacenter: "wrong_dc1",
}
_, err := status.Peers(&opts)
_, err := status.PeersWithQueryOptions(&opts)
require.Error(err)
require.Contains(err.Error(), "No path to datacenter")
}