consul/agent/status_endpoint_test.go

43 lines
806 B
Go
Raw Normal View History

2013-12-23 21:52:10 +00:00
package agent
import (
"net/http"
"testing"
"github.com/hashicorp/consul/testrpc"
)
2013-12-23 21:52:10 +00:00
func TestStatusLeader(t *testing.T) {
t.Parallel()
a := NewTestAgent(t, t.Name(), "")
defer a.Shutdown()
testrpc.WaitForLeader(t, a.RPC, "dc1")
2013-12-23 21:52:10 +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) {
t.Parallel()
a := NewTestAgent(t, t.Name(), "")
defer a.Shutdown()
2013-12-23 21:52:10 +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)
}
}