diff --git a/config/validate/rules.go b/config/validate/rules.go index 416e6ec..f8397dc 100644 --- a/config/validate/rules.go +++ b/config/validate/rules.go @@ -34,6 +34,7 @@ var Rules []rule = []rule{ checkStructure, checkValidity, checkWriteFiles, + checkWriteFilesUnderCoreos, } // checkDiscoveryUrl verifies that the string is a valid url. @@ -150,3 +151,12 @@ func checkWriteFiles(cfg node, report *Report) { } } } + +// checkWriteFilesUnderCoreos checks to see if the 'write_files' node is a +// child of 'coreos' (it shouldn't be). +func checkWriteFilesUnderCoreos(cfg node, report *Report) { + c := cfg.Child("coreos").Child("write_files") + if c.IsValid() { + report.Info(c.line, "write_files doesn't belong under coreos") + } +} diff --git a/config/validate/rules_test.go b/config/validate/rules_test.go index c767dff..d37c181 100644 --- a/config/validate/rules_test.go +++ b/config/validate/rules_test.go @@ -319,3 +319,37 @@ func TestCheckWriteFiles(t *testing.T) { } } } + +func TestCheckWriteFilesUnderCoreos(t *testing.T) { + tests := []struct { + config string + + entries []Entry + }{ + {}, + { + config: "write_files:\n - path: /hi", + }, + { + config: "coreos:\n write_files:\n - path: /hi", + entries: []Entry{{entryInfo, "write_files doesn't belong under coreos", 2}}, + }, + { + config: "coreos:\n write-files:\n - path: /hyphen", + entries: []Entry{{entryInfo, "write_files doesn't belong under coreos", 2}}, + }, + } + + for i, tt := range tests { + r := Report{} + n, err := parseCloudConfig([]byte(tt.config), &r) + if err != nil { + panic(err) + } + checkWriteFilesUnderCoreos(n, &r) + + if e := r.Entries(); !reflect.DeepEqual(tt.entries, e) { + t.Errorf("bad report (%d, %q): want %#v, got %#v", i, tt.config, tt.entries, e) + } + } +}