2015-01-06 18:40:00 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-07-28 16:26:50 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2015-01-06 18:40:00 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-06-30 20:58:55 +00:00
|
|
|
func TestAPI_StatusLeader(t *testing.T) {
|
2015-05-08 17:27:24 +00:00
|
|
|
t.Parallel()
|
2015-01-06 23:26:50 +00:00
|
|
|
c, s := makeClient(t)
|
2015-03-03 02:18:38 +00:00
|
|
|
defer s.Stop()
|
2018-12-12 20:09:42 +00:00
|
|
|
s.WaitForSerfCheck(t)
|
2015-01-06 23:26:50 +00:00
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
status := c.Status()
|
|
|
|
|
2020-07-28 16:26:50 +00:00
|
|
|
opts := QueryOptions{
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
|
|
|
|
|
|
|
leader, err := status.Leader(&opts)
|
2015-01-06 18:40:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if leader == "" {
|
|
|
|
t.Fatalf("Expected leader")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-30 20:58:55 +00:00
|
|
|
func TestAPI_StatusPeers(t *testing.T) {
|
2015-05-08 17:27:24 +00:00
|
|
|
t.Parallel()
|
2015-01-06 23:26:50 +00:00
|
|
|
c, s := makeClient(t)
|
2015-03-03 02:18:38 +00:00
|
|
|
defer s.Stop()
|
2018-12-12 20:09:42 +00:00
|
|
|
s.WaitForSerfCheck(t)
|
2015-01-06 23:26:50 +00:00
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
status := c.Status()
|
|
|
|
|
2020-07-28 16:26:50 +00:00
|
|
|
opts := QueryOptions{
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
|
|
|
peers, err := status.Peers(&opts)
|
2015-01-06 18:40:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if len(peers) == 0 {
|
|
|
|
t.Fatalf("Expected peers ")
|
|
|
|
}
|
|
|
|
}
|
2020-07-28 16:26:50 +00: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",
|
|
|
|
}
|
|
|
|
_, 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")
|
|
|
|
}
|