2015-01-06 18:40:00 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2015-01-14 19:30:43 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os/user"
|
|
|
|
"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 {
|
|
|
|
t.Fatal("Could not create a working directory")
|
|
|
|
}
|
|
|
|
|
|
|
|
socket := "unix://" + tempdir + "/unix-http-test.sock"
|
|
|
|
|
|
|
|
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
|
|
|
user, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Could not get current user")
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Addresses == nil {
|
2015-01-14 21:25:12 +00:00
|
|
|
c.Addresses = &testAddressConfig{}
|
2015-01-14 19:30:43 +00:00
|
|
|
}
|
|
|
|
c.Addresses.HTTP = socket + ";" + user.Uid + ";" + user.Gid + ";640"
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ")
|
|
|
|
}
|
|
|
|
}
|