From 978841199538f073753b80c8d9d1a316ac84ac54 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 8 Sep 2019 04:43:56 -0400 Subject: [PATCH] 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. --- engine/resources/file.go | 4 ++++ test/shell/t2.yaml | 2 -- test/shell/t6.yaml | 2 -- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/resources/file.go b/engine/resources/file.go index 47d3304c..f704517c 100644 --- a/engine/resources/file.go +++ b/engine/resources/file.go @@ -130,6 +130,10 @@ func (obj *FileRes) Validate() error { 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 _, err := obj.mode(); err != nil { return err diff --git a/test/shell/t2.yaml b/test/shell/t2.yaml index 09bfcca8..98be0930 100644 --- a/test/shell/t2.yaml +++ b/test/shell/t2.yaml @@ -21,8 +21,6 @@ resources: state: exists - name: file4 path: "/tmp/mgmt/f4" - content: | - i am f4 and i should not be here state: absent - name: dir1 path: "/tmp/mgmt/dir1/" diff --git a/test/shell/t6.yaml b/test/shell/t6.yaml index f69394ee..295dc5c1 100644 --- a/test/shell/t6.yaml +++ b/test/shell/t6.yaml @@ -21,8 +21,6 @@ resources: state: exists - name: file4 path: "/tmp/mgmt/f4" - content: | - i am f4 and i should not be here state: absent edges: - name: e1