open-consul/command/agent/status_endpoint_test.go

44 lines
736 B
Go
Raw Normal View History

2013-12-23 21:52:10 +00:00
package agent
import (
"os"
"testing"
"time"
)
func TestStatusLeader(t *testing.T) {
dir, srv := makeHTTPServer(t)
defer os.RemoveAll(dir)
defer srv.Shutdown()
defer srv.agent.Shutdown()
// Wait for a leader
time.Sleep(100 * time.Millisecond)
2013-12-24 00:20:51 +00:00
obj, err := srv.StatusLeader(nil, nil)
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) {
dir, srv := makeHTTPServer(t)
defer os.RemoveAll(dir)
defer srv.Shutdown()
defer srv.agent.Shutdown()
2013-12-24 00:20:51 +00:00
obj, err := srv.StatusPeers(nil, nil)
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)
}
}