api: simple test for unix socket connectivity

This commit is contained in:
Ryan Uber 2015-01-16 10:56:47 -08:00
parent 328204f535
commit 7c6455e1ba
2 changed files with 35 additions and 42 deletions

View File

@ -8,6 +8,8 @@ import (
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
"time"
@ -287,3 +289,35 @@ func TestParseQueryMeta(t *testing.T) {
t.Fatalf("Bad: %v", qm)
}
}
func TestAPI_UnixSocket(t *testing.T) {
if runtime.GOOS == "windows" {
t.SkipNow()
}
tempDir, err := ioutil.TempDir("", "consul")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.RemoveAll(tempDir)
socket := filepath.Join(tempDir, "test.sock")
c, s := makeClientWithConfig(t, func(c *Config) {
c.Address = "unix://" + socket
}, func(c *testServerConfig) {
c.Addresses = &testAddressConfig{
HTTP: "unix://" + socket,
}
})
defer s.stop()
agent := c.Agent()
info, err := agent.Self()
if err != nil {
t.Fatalf("err: %s", err)
}
if info["Config"]["NodeName"] == "" {
t.Fatalf("bad: %v", info)
}
}

View File

@ -1,14 +1,10 @@
package api
import (
"fmt"
"io/ioutil"
"os"
"runtime"
"testing"
)
func TestStatusLeaderTCP(t *testing.T) {
func TestStatusLeader(t *testing.T) {
c, s := makeClient(t)
defer s.stop()
@ -23,43 +19,6 @@ func TestStatusLeaderTCP(t *testing.T) {
}
}
func TestStatusLeaderUnix(t *testing.T) {
if runtime.GOOS == "windows" {
t.SkipNow()
}
tempdir, err := ioutil.TempDir("", "consul-test-")
if err != nil {
t.Fatalf("err: %s", err)
}
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{}
}
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()