2015-01-06 18:40:00 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2015-01-16 01:24:15 +00:00
|
|
|
"fmt"
|
2015-01-14 19:30:43 +00:00
|
|
|
"io/ioutil"
|
2015-01-16 01:24:15 +00:00
|
|
|
"os"
|
2015-01-14 19:30:43 +00:00
|
|
|
"runtime"
|
2015-01-06 18:40:00 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-01-14 19:30:43 +00:00
|
|
|
func TestStatusLeaderTCP(t *testing.T) {
|
2015-01-06 23:26:50 +00:00
|
|
|
c, s := makeClient(t)
|
|
|
|
defer s.stop()
|
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
status := c.Status()
|
|
|
|
|
|
|
|
leader, err := status.Leader()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if leader == "" {
|
|
|
|
t.Fatalf("Expected leader")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-14 19:30:43 +00:00
|
|
|
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-14 19:30:43 +00:00
|
|
|
}
|
2015-01-16 01:24:15 +00:00
|
|
|
defer os.RemoveAll(tempdir)
|
|
|
|
socket := fmt.Sprintf("unix://%s/test.sock", tempdir)
|
2015-01-14 19:30:43 +00:00
|
|
|
|
|
|
|
clientConfig := func(c *Config) {
|
|
|
|
c.Address = socket
|
|
|
|
}
|
|
|
|
|
2015-01-14 21:25:12 +00:00
|
|
|
serverConfig := func(c *testServerConfig) {
|
2015-01-14 19:30:43 +00:00
|
|
|
if c.Addresses == nil {
|
2015-01-14 21:25:12 +00:00
|
|
|
c.Addresses = &testAddressConfig{}
|
2015-01-14 19:30:43 +00:00
|
|
|
}
|
2015-01-16 01:24:15 +00:00
|
|
|
c.Addresses.HTTP = socket
|
2015-01-14 19:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
func TestStatusPeers(t *testing.T) {
|
2015-01-06 23:26:50 +00:00
|
|
|
c, s := makeClient(t)
|
|
|
|
defer s.stop()
|
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
status := c.Status()
|
|
|
|
|
|
|
|
peers, err := status.Peers()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if len(peers) == 0 {
|
|
|
|
t.Fatalf("Expected peers ")
|
|
|
|
}
|
|
|
|
}
|