From 11984079a204d0f7db5372da1c27890ae90a0edd Mon Sep 17 00:00:00 2001 From: Adam0Brien Date: Thu, 10 Aug 2023 13:32:01 +0100 Subject: [PATCH] base/validate.go: Added switch statement for Validate Resource base/validate.go: Fix merge report logic --- base/v0_6_exp/validate.go | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/base/v0_6_exp/validate.go b/base/v0_6_exp/validate.go index 70874df5..715043a9 100644 --- a/base/v0_6_exp/validate.go +++ b/base/v0_6_exp/validate.go @@ -27,37 +27,33 @@ import ( func (rs Resource) Validate(c path.ContextPath) (r report.Report) { var field string sources := 0 - if rs.Local != nil { + var config string + switch { + case rs.Local != nil: sources++ field = "local" - config := *rs.Local - _, report, err := exp.Parse([]byte(config)) - if err != nil { - r.Merge(report) - } else { - r.AddOnError(c.Append("ignition", "config", "merge", "local"), common.ErrEmptyReport) - } - } - if rs.Inline != nil { + config = *rs.Local + case rs.Inline != nil: sources++ field = "inline" - config := *rs.Inline - _, report, err := exp.Parse([]byte(config)) - if err != nil { - r.Merge(report) - } else { - r.AddOnError(c.Append("ignition", "config", "merge", "local"), common.ErrEmptyReport) - } - } - if rs.Source != nil { + config = *rs.Inline + case rs.Source != nil: sources++ field = "source" } if sources > 1 { r.AddOnError(c.Append(field), common.ErrTooManyResourceSources) + } else { + if field == "local" || field == "inline" { + _, report, err := exp.Parse([]byte(config)) + if len(report.Entries) > 0 { + r.Merge(report) + } else { + r.AddOnWarn(c.Append("ignition", "config", "merge", field), err) + } + } } - - return r + return } func (fs Filesystem) Validate(c path.ContextPath) (r report.Report) {