2013-12-23 21:52:10 +00:00
|
|
|
package agent
|
|
|
|
|
2017-09-26 06:11:19 +00:00
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
2018-11-20 11:27:26 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/consul/testrpc"
|
2017-09-26 06:11:19 +00:00
|
|
|
)
|
2013-12-23 21:52:10 +00:00
|
|
|
|
|
|
|
func TestStatusLeader(t *testing.T) {
|
2017-05-21 07:54:40 +00:00
|
|
|
t.Parallel()
|
2019-02-14 15:59:14 +00:00
|
|
|
a := NewTestAgent(t, t.Name(), "")
|
2017-05-21 07:11:09 +00:00
|
|
|
defer a.Shutdown()
|
2018-11-20 11:27:26 +00:00
|
|
|
testrpc.WaitForLeader(t, a.RPC, "dc1")
|
2013-12-23 21:52:10 +00:00
|
|
|
|
2017-09-26 06:11:19 +00:00
|
|
|
req, _ := http.NewRequest("GET", "/v1/status/leader", nil)
|
|
|
|
obj, err := a.srv.StatusLeader(nil, req)
|
2013-12-23 21:52:10 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Err: %v", err)
|
|
|
|
}
|
|
|
|
val := obj.(string)
|
|
|
|
if val == "" {
|
|
|
|
t.Fatalf("bad addr: %v", obj)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStatusPeers(t *testing.T) {
|
2017-05-21 07:54:40 +00:00
|
|
|
t.Parallel()
|
2019-02-14 15:59:14 +00:00
|
|
|
a := NewTestAgent(t, t.Name(), "")
|
2017-05-21 07:11:09 +00:00
|
|
|
defer a.Shutdown()
|
2013-12-23 21:52:10 +00:00
|
|
|
|
2017-09-26 06:11:19 +00:00
|
|
|
req, _ := http.NewRequest("GET", "/v1/status/peers", nil)
|
|
|
|
obj, err := a.srv.StatusPeers(nil, req)
|
2013-12-23 21:52:10 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
peers := obj.([]string)
|
|
|
|
if len(peers) != 1 {
|
|
|
|
t.Fatalf("bad peers: %v", peers)
|
|
|
|
}
|
|
|
|
}
|