diff --git a/command/agent/config.go b/command/agent/config.go index f56e3e740f..ba72ddeba1 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -1292,6 +1292,10 @@ func ReadConfigPaths(paths []string) (*Config, error) { if !strings.HasSuffix(fi.Name(), ".json") { continue } + // If the config file is empty, ignore it + if fi.Size() == 0 { + continue + } subpath := filepath.Join(path, fi.Name()) f, err := os.Open(subpath) diff --git a/command/configtest_test.go b/command/configtest_test.go index 43f6295092..65e6e1753b 100644 --- a/command/configtest_test.go +++ b/command/configtest_test.go @@ -103,3 +103,28 @@ func TestConfigTestCommandSucceedOnMinimalConfigDir(t *testing.T) { t.Fatalf("bad: %d", code) } } + +func TestConfigTestCommandSucceedOnConfigDirWithEmptyFile(t *testing.T) { + td, err := ioutil.TempDir("", "consul") + if err != nil { + t.Fatalf("err: %s", err) + } + defer os.RemoveAll(td) + + err = ioutil.WriteFile(filepath.Join(td, "config.json"), []byte{}, 0644) + if err != nil { + t.Fatalf("err: %s", err) + } + + cmd := &ConfigTestCommand{ + Ui: new(cli.MockUi), + } + + args := []string{ + "-config-dir", td, + } + + if code := cmd.Run(args); code != 0 { + t.Fatalf("bad: %d", code) + } +}