open-consul/api/status_test.go

77 lines
1.2 KiB
Go
Raw Normal View History

package api
import (
2015-01-16 01:24:15 +00:00
"fmt"
"io/ioutil"
2015-01-16 01:24:15 +00:00
"os"
"runtime"
"testing"
)
func TestStatusLeaderTCP(t *testing.T) {
c, s := makeClient(t)
defer s.stop()
status := c.Status()
leader, err := status.Leader()
if err != nil {
t.Fatalf("err: %v", err)
}
if leader == "" {
t.Fatalf("Expected leader")
}
}
func TestStatusLeaderUnix(t *testing.T) {
if runtime.GOOS == "windows" {
t.SkipNow()
}
tempdir, err := ioutil.TempDir("", "consul-test-")
if err != nil {
2015-01-16 01:24:15 +00:00
t.Fatalf("err: %s", err)
}
2015-01-16 01:24:15 +00:00
defer os.RemoveAll(tempdir)
socket := fmt.Sprintf("unix://%s/test.sock", tempdir)
clientConfig := func(c *Config) {
c.Address = socket
}
serverConfig := func(c *testServerConfig) {
if c.Addresses == nil {
c.Addresses = &testAddressConfig{}
}
2015-01-16 01:24:15 +00:00
c.Addresses.HTTP = socket
}
c, s := makeClientWithConfig(t, clientConfig, serverConfig)
defer s.stop()
status := c.Status()
leader, err := status.Leader()
if err != nil {
t.Fatalf("err: %v", err)
}
if leader == "" {
t.Fatalf("Expected leader")
}
}
func TestStatusPeers(t *testing.T) {
c, s := makeClient(t)
defer s.stop()
status := c.Status()
peers, err := status.Peers()
if err != nil {
t.Fatalf("err: %v", err)
}
if len(peers) == 0 {
t.Fatalf("Expected peers ")
}
}