engine: resources: Add another validation check
This simple check should prevent some silly mistakes and make the logic easier for other parts of the code that won't have to worry about this pattern.
This commit is contained in:
@@ -130,6 +130,10 @@ func (obj *FileRes) Validate() error {
|
|||||||
return fmt.Errorf("the State is invalid")
|
return fmt.Errorf("the State is invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if obj.State == FileStateAbsent && obj.Content != nil {
|
||||||
|
return fmt.Errorf("can't specify content for an absent file")
|
||||||
|
}
|
||||||
|
|
||||||
if obj.Mode != "" {
|
if obj.Mode != "" {
|
||||||
if _, err := obj.mode(); err != nil {
|
if _, err := obj.mode(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ resources:
|
|||||||
state: exists
|
state: exists
|
||||||
- name: file4
|
- name: file4
|
||||||
path: "/tmp/mgmt/f4"
|
path: "/tmp/mgmt/f4"
|
||||||
content: |
|
|
||||||
i am f4 and i should not be here
|
|
||||||
state: absent
|
state: absent
|
||||||
- name: dir1
|
- name: dir1
|
||||||
path: "/tmp/mgmt/dir1/"
|
path: "/tmp/mgmt/dir1/"
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ resources:
|
|||||||
state: exists
|
state: exists
|
||||||
- name: file4
|
- name: file4
|
||||||
path: "/tmp/mgmt/f4"
|
path: "/tmp/mgmt/f4"
|
||||||
content: |
|
|
||||||
i am f4 and i should not be here
|
|
||||||
state: absent
|
state: absent
|
||||||
edges:
|
edges:
|
||||||
- name: e1
|
- name: e1
|
||||||
|
|||||||
Reference in New Issue
Block a user