Skip to content

Commit 1198407

Browse files
committed
base/validate.go: Added switch statement for Validate Resource
base/validate.go: Fix merge report logic
1 parent 3d444ad commit 1198407

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

base/v0_6_exp/validate.go

+17-21
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,33 @@ import (
2727
func (rs Resource) Validate(c path.ContextPath) (r report.Report) {
2828
var field string
2929
sources := 0
30-
if rs.Local != nil {
30+
var config string
31+
switch {
32+
case rs.Local != nil:
3133
sources++
3234
field = "local"
33-
config := *rs.Local
34-
_, report, err := exp.Parse([]byte(config))
35-
if err != nil {
36-
r.Merge(report)
37-
} else {
38-
r.AddOnError(c.Append("ignition", "config", "merge", "local"), common.ErrEmptyReport)
39-
}
40-
}
41-
if rs.Inline != nil {
35+
config = *rs.Local
36+
case rs.Inline != nil:
4237
sources++
4338
field = "inline"
44-
config := *rs.Inline
45-
_, report, err := exp.Parse([]byte(config))
46-
if err != nil {
47-
r.Merge(report)
48-
} else {
49-
r.AddOnError(c.Append("ignition", "config", "merge", "local"), common.ErrEmptyReport)
50-
}
51-
}
52-
if rs.Source != nil {
39+
config = *rs.Inline
40+
case rs.Source != nil:
5341
sources++
5442
field = "source"
5543
}
5644
if sources > 1 {
5745
r.AddOnError(c.Append(field), common.ErrTooManyResourceSources)
46+
} else {
47+
if field == "local" || field == "inline" {
48+
_, report, err := exp.Parse([]byte(config))
49+
if len(report.Entries) > 0 {
50+
r.Merge(report)
51+
} else {
52+
r.AddOnWarn(c.Append("ignition", "config", "merge", field), err)
53+
}
54+
}
5855
}
59-
60-
return r
56+
return
6157
}
6258

6359
func (fs Filesystem) Validate(c path.ContextPath) (r report.Report) {

0 commit comments

Comments
 (0)