Skip to content

Commit

Permalink
Merge pull request #1703 from alistanis/fix-issue-#1661
Browse files Browse the repository at this point in the history
fixes issue #1661 and adds supporting test
  • Loading branch information
slackpad committed Feb 17, 2016
2 parents 0562b95 + 2c6f873 commit 052140f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,13 @@ func TestReadConfigPaths_dir(t *testing.T) {
t.Fatalf("err: %s", err)
}

// An empty file shouldn't be read
err = ioutil.WriteFile(filepath.Join(td, "d.json"),
[]byte{}, 0664)
if err != nil {
t.Fatalf("err: %s", err)
}

config, err := ReadConfigPaths([]string{td})
if err != nil {
t.Fatalf("err: %s", err)
Expand Down
25 changes: 25 additions & 0 deletions command/configtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 052140f

Please sign in to comment.