mirror of https://github.com/status-im/consul.git
api: simple test for unix socket connectivity
This commit is contained in:
parent
56c3e488a9
commit
4b635738bf
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue