2015-01-06 10:40:00 -08:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-07-28 19:26:50 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
2015-01-06 10:40:00 -08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-06-30 22:58:55 +02:00
|
|
|
func TestAPI_StatusLeader(t *testing.T) {
|
2015-05-08 10:27:24 -07:00
|
|
|
t.Parallel()
|
2015-01-06 15:26:50 -08:00
|
|
|
c, s := makeClient(t)
|
2015-03-02 18:18:38 -08:00
|
|
|
defer s.Stop()
|
2018-12-12 21:09:42 +01:00
|
|
|
s.WaitForSerfCheck(t)
|
2015-01-06 15:26:50 -08:00
|
|
|
|
2015-01-06 10:40:00 -08:00
|
|
|
status := c.Status()
|
|
|
|
|
2020-07-29 12:09:15 -04:00
|
|
|
leader, err := status.Leader()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if leader == "" {
|
|
|
|
t.Fatalf("Expected leader, found empty string")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPI_StatusLeaderWithQueryOptions(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
c, s := makeClient(t)
|
|
|
|
defer s.Stop()
|
|
|
|
s.WaitForSerfCheck(t)
|
|
|
|
|
|
|
|
status := c.Status()
|
|
|
|
|
2020-07-28 19:26:50 +03:00
|
|
|
opts := QueryOptions{
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
|
|
|
|
2020-07-29 12:09:15 -04:00
|
|
|
leader, err := status.LeaderWithQueryOptions(&opts)
|
2015-01-06 10:40:00 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if leader == "" {
|
2020-07-29 12:09:15 -04:00
|
|
|
t.Fatalf("Expected leader, found empty string")
|
2015-01-06 10:40:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-30 22:58:55 +02:00
|
|
|
func TestAPI_StatusPeers(t *testing.T) {
|
2015-05-08 10:27:24 -07:00
|
|
|
t.Parallel()
|
2015-01-06 15:26:50 -08:00
|
|
|
c, s := makeClient(t)
|
2015-03-02 18:18:38 -08:00
|
|
|
defer s.Stop()
|
2018-12-12 21:09:42 +01:00
|
|
|
s.WaitForSerfCheck(t)
|
2015-01-06 15:26:50 -08:00
|
|
|
|
2015-01-06 10:40:00 -08:00
|
|
|
status := c.Status()
|
|
|
|
|
2020-07-29 12:09:15 -04:00
|
|
|
peers, err := status.Peers()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if len(peers) == 0 {
|
|
|
|
t.Fatalf("Expected peers, found %d", len(peers))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPI_StatusPeersWithQueryOptions(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
c, s := makeClient(t)
|
|
|
|
defer s.Stop()
|
|
|
|
s.WaitForSerfCheck(t)
|
|
|
|
|
|
|
|
status := c.Status()
|
|
|
|
|
2020-07-28 19:26:50 +03:00
|
|
|
opts := QueryOptions{
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
2020-07-29 12:09:15 -04:00
|
|
|
|
|
|
|
peers, err := status.PeersWithQueryOptions(&opts)
|
2015-01-06 10:40:00 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if len(peers) == 0 {
|
2020-07-29 12:09:15 -04:00
|
|
|
t.Fatalf("Expected peers, found %d", len(peers))
|
2015-01-06 10:40:00 -08:00
|
|
|
}
|
|
|
|
}
|
2020-07-28 19:26:50 +03:00
|
|
|
|
|
|
|
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",
|
|
|
|
}
|
2020-07-29 12:09:15 -04:00
|
|
|
|
|
|
|
_, err := status.LeaderWithQueryOptions(&opts)
|
2020-07-28 19:26:50 +03:00
|
|
|
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",
|
|
|
|
}
|
2020-07-29 12:09:15 -04:00
|
|
|
_, err := status.PeersWithQueryOptions(&opts)
|
2020-07-28 19:26:50 +03:00
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "No path to datacenter")
|
|
|
|
}
|