mirror of
https://github.com/status-im/consul.git
synced 2025-02-23 02:48:19 +00:00
Merge pull request #1703 from alistanis/fix-issue-#1661
fixes issue #1661 and adds supporting test
This commit is contained in:
commit
052140f8a7
@ -1292,6 +1292,10 @@ func ReadConfigPaths(paths []string) (*Config, error) {
|
|||||||
if !strings.HasSuffix(fi.Name(), ".json") {
|
if !strings.HasSuffix(fi.Name(), ".json") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// If the config file is empty, ignore it
|
||||||
|
if fi.Size() == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
subpath := filepath.Join(path, fi.Name())
|
subpath := filepath.Join(path, fi.Name())
|
||||||
f, err := os.Open(subpath)
|
f, err := os.Open(subpath)
|
||||||
|
@ -1418,6 +1418,13 @@ func TestReadConfigPaths_dir(t *testing.T) {
|
|||||||
t.Fatalf("err: %s", err)
|
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})
|
config, err := ReadConfigPaths([]string{td})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
|
@ -103,3 +103,28 @@ func TestConfigTestCommandSucceedOnMinimalConfigDir(t *testing.T) {
|
|||||||
t.Fatalf("bad: %d", code)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user