mirror of https://github.com/hashicorp/consul
agent: test agent rpc unix socket create failure
parent
b30af9536d
commit
2530e5ff05
|
@ -1,10 +1,12 @@
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/testutil"
|
"github.com/hashicorp/consul/testutil"
|
||||||
|
@ -163,3 +165,47 @@ func TestRetryJoinWanFail(t *testing.T) {
|
||||||
t.Fatalf("bad: %d", code)
|
t.Fatalf("bad: %d", code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetupAgent_UnixSocket_Fails(t *testing.T) {
|
||||||
|
conf := nextConfig()
|
||||||
|
tmpDir, err := ioutil.TempDir("", "consul")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
tmpFile, err := ioutil.TempFile("", "consul")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
defer os.Remove(tmpFile.Name())
|
||||||
|
socketPath := tmpFile.Name()
|
||||||
|
|
||||||
|
conf.DataDir = tmpDir
|
||||||
|
conf.Server = true
|
||||||
|
conf.Bootstrap = true
|
||||||
|
|
||||||
|
// Set socket address to an existing file. Consul should fail to
|
||||||
|
// start and return an error.
|
||||||
|
conf.Addresses.RPC = "unix://" + socketPath
|
||||||
|
|
||||||
|
shutdownCh := make(chan struct{})
|
||||||
|
defer close(shutdownCh)
|
||||||
|
|
||||||
|
cmd := &Command{
|
||||||
|
ShutdownCh: shutdownCh,
|
||||||
|
Ui: new(cli.MockUi),
|
||||||
|
}
|
||||||
|
|
||||||
|
logWriter := NewLogWriter(512)
|
||||||
|
logOutput := new(bytes.Buffer)
|
||||||
|
|
||||||
|
// Ensure we got an error mentioning the socket file
|
||||||
|
err = cmd.setupAgent(conf, logOutput, logWriter)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("should have failed")
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), socketPath) {
|
||||||
|
t.Fatalf("expected socket file error, got: %q", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue