Browse Source

api: simple test for unix socket connectivity

pull/612/head
Ryan Uber 10 years ago
parent
commit
4b635738bf
  1. 34
      api/api_test.go
  2. 43
      api/status_test.go

34
api/api_test.go

@ -8,6 +8,8 @@ import (
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"runtime"
"testing" "testing"
"time" "time"
@ -287,3 +289,35 @@ func TestParseQueryMeta(t *testing.T) {
t.Fatalf("Bad: %v", qm) 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)
}
}

43
api/status_test.go

@ -1,14 +1,10 @@
package api package api
import ( import (
"fmt"
"io/ioutil"
"os"
"runtime"
"testing" "testing"
) )
func TestStatusLeaderTCP(t *testing.T) { func TestStatusLeader(t *testing.T) {
c, s := makeClient(t) c, s := makeClient(t)
defer s.stop() 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) { func TestStatusPeers(t *testing.T) {
c, s := makeClient(t) c, s := makeClient(t)
defer s.stop() defer s.stop()

Loading…
Cancel
Save