mirror of https://github.com/status-im/consul.git
Merge pull request #1907 from hashicorp/b-empty-node-name
Node names are not allowed to be empty
This commit is contained in:
commit
9862bb9061
|
@ -164,11 +164,16 @@ func (c *Command) readConfig() *Config {
|
|||
if config.NodeName == "" {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error determining hostname: %s", err))
|
||||
c.Ui.Error(fmt.Sprintf("Error determining node name: %s", err))
|
||||
return nil
|
||||
}
|
||||
config.NodeName = hostname
|
||||
}
|
||||
hostname = strings.TrimSpace(hostname)
|
||||
if hostname == "" {
|
||||
c.Ui.Error("Node name can not be empty")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Ensure we have a data directory
|
||||
if config.DataDir == "" && !dev {
|
||||
|
|
|
@ -114,6 +114,8 @@ func TestReadCliConfig(t *testing.T) {
|
|||
shutdownCh := make(chan struct{})
|
||||
defer close(shutdownCh)
|
||||
|
||||
// Test config parse
|
||||
{
|
||||
tmpDir, err := ioutil.TempDir("", "consul")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
|
@ -135,6 +137,23 @@ func TestReadCliConfig(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// Test empty node name
|
||||
{
|
||||
cmd := &Command{
|
||||
args: []string{
|
||||
"-node", `""`,
|
||||
},
|
||||
ShutdownCh: shutdownCh,
|
||||
Ui: new(cli.MockUi),
|
||||
}
|
||||
|
||||
config := cmd.readConfig()
|
||||
if config != nil {
|
||||
t.Errorf(`Expected -node="" to fail`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetryJoinFail(t *testing.T) {
|
||||
conf := nextConfig()
|
||||
tmpDir, err := ioutil.TempDir("", "consul")
|
||||
|
|
Loading…
Reference in New Issue