diff --git a/api/api_test.go b/api/api_test.go index 722d78b56b..dc25f8b5a4 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -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) + } +} diff --git a/api/status_test.go b/api/status_test.go index 61b0a435e9..096b13da09 100644 --- a/api/status_test.go +++ b/api/status_test.go @@ -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()