9
9
include ParserRspecHelper
11
11
context "When parsing regular resource" do
12
it "file { 'title': }" do
13
dump(parse("file { 'title': }")).should == [
19
it "file { 'title': path => '/somewhere', mode => 0777}" do
20
dump(parse("file { 'title': path => '/somewhere', mode => 0777}")).should == [
23
" (path => '/somewhere')",
28
it "file { 'title': path => '/somewhere', }" do
29
dump(parse("file { 'title': path => '/somewhere', }")).should == [
32
" (path => '/somewhere')))"
36
it "file { 'title': , }" do
37
dump(parse("file { 'title': , }")).should == [
43
it "file { 'title': ; }" do
44
dump(parse("file { 'title': ; }")).should == [
50
it "file { 'title': ; 'other_title': }" do
51
dump(parse("file { 'title': ; 'other_title': }")).should == [
58
it "file { 'title1': path => 'x'; 'title2': path => 'y'}" do
59
dump(parse("file { 'title1': path => 'x'; 'title2': path => 'y'}")).should == [
12
["File", "file"].each do |word|
13
it "#{word} { 'title': }" do
14
dump(parse("#{word} { 'title': }")).should == [
20
it "#{word} { 'title': path => '/somewhere', mode => '0777'}" do
21
dump(parse("#{word} { 'title': path => '/somewhere', mode => '0777'}")).should == [
24
" (path => '/somewhere')",
29
it "#{word} { 'title': path => '/somewhere', }" do
30
dump(parse("#{word} { 'title': path => '/somewhere', }")).should == [
33
" (path => '/somewhere')))"
37
it "#{word} { 'title': , }" do
38
dump(parse("#{word} { 'title': , }")).should == [
44
it "#{word} { 'title': ; }" do
45
dump(parse("#{word} { 'title': ; }")).should == [
51
it "#{word} { 'title': ; 'other_title': }" do
52
dump(parse("#{word} { 'title': ; 'other_title': }")).should == [
59
# PUP-2898, trailing ';'
60
it "#{word} { 'title': ; 'other_title': ; }" do
61
dump(parse("#{word} { 'title': ; 'other_title': ; }")).should == [
68
it "#{word} { 'title1': path => 'x'; 'title2': path => 'y'}" do
69
dump(parse("#{word} { 'title1': path => 'x'; 'title2': path => 'y'}")).should == [
78
it "#{word} { title: * => {mode => '0777'} }" do
79
dump(parse("#{word} { title: * => {mode => '0777'}}")).should == [
82
" (* => ({} (mode '0777')))))"
69
context "When parsing resource defaults" do
88
context "When parsing (type based) resource defaults" do
71
90
dump(parse("File { }")).should == "(resource-defaults file)"
74
it "File { mode => 0777 }" do
75
dump(parse("File { mode => 0777}")).should == [
76
"(resource-defaults file",
93
it "File { mode => '0777' }" do
94
dump(parse("File { mode => '0777'}")).should == [
95
"(resource-defaults file",
100
it "File { * => {mode => '0777'} } (even if validated to be illegal)" do
101
dump(parse("File { * => {mode => '0777'}}")).should == [
102
"(resource-defaults file",
103
" (* => ({} (mode '0777'))))"
87
113
it "File['x'] { x => 1 }" do
88
dump(parse("File['x'] { x => 1}")).should == "(override (slice file 'x')\n (x => 1))"
114
dump(parse("File['x'] { x => 1}")).should == [
115
"(override (slice file 'x')",
91
121
it "File['x', 'y'] { x => 1 }" do
92
dump(parse("File['x', 'y'] { x => 1}")).should == "(override (slice file ('x' 'y'))\n (x => 1))"
122
dump(parse("File['x', 'y'] { x => 1}")).should == [
123
"(override (slice file ('x' 'y'))",
95
128
it "File['x'] { x => 1, y => 2 }" do
96
dump(parse("File['x'] { x => 1, y=> 2}")).should == "(override (slice file 'x')\n (x => 1)\n (y => 2))"
129
dump(parse("File['x'] { x => 1, y=> 2}")).should == [
130
"(override (slice file 'x')",
99
136
it "File['x'] { x +> 1 }" do
100
dump(parse("File['x'] { x +> 1}")).should == "(override (slice file 'x')\n (x +> 1))"
137
dump(parse("File['x'] { x +> 1}")).should == [
138
"(override (slice file 'x')",
143
it "File['x'] { * => {mode => '0777'} } (even if validated to be illegal)" do
144
dump(parse("File['x'] { * => {mode => '0777'}}")).should == [
145
"(override (slice file 'x')",
146
" (* => ({} (mode '0777'))))"
104
151
context "When parsing virtual and exported resources" do
105
it "@@file { 'title': }" do
152
it "parses exported @@file { 'title': }" do
106
153
dump(parse("@@file { 'title': }")).should == "(exported-resource file\n ('title'))"
109
it "@file { 'title': }" do
156
it "parses virtual @file { 'title': }" do
110
157
dump(parse("@file { 'title': }")).should == "(virtual-resource file\n ('title'))"
113
it "@file { mode => 0777 }" do
114
# Defaults are not virtualizeable
116
dump(parse("@file { mode => 0777 }")).should == ""
117
}.to raise_error(Puppet::ParseError, /Defaults are not virtualizable/)
160
it "nothing before the title colon is a syntax error" do
162
parse("@file {: mode => '0777' }")
163
end.to raise_error(/Syntax error/)
166
it "raises error for user error; not a resource" do
167
# The expression results in VIRTUAL, CALL FUNCTION('file', HASH) since the resource body has
170
parse("@file { mode => '0777' }")
171
end.to raise_error(/Virtual \(@\) can only be applied to a Resource Expression/)
174
it "parses global defaults with @ (even if validated to be illegal)" do
175
dump(parse("@File { mode => '0777' }")).should == [
176
"(virtual-resource-defaults file",
181
it "parses global defaults with @@ (even if validated to be illegal)" do
182
dump(parse("@@File { mode => '0777' }")).should == [
183
"(exported-resource-defaults file",
188
it "parses override with @ (even if validated to be illegal)" do
189
dump(parse("@File[foo] { mode => '0777' }")).should == [
190
"(virtual-override (slice file foo)",
195
it "parses override combined with @@ (even if validated to be illegal)" do
196
dump(parse("@@File[foo] { mode => '0777' }")).should == [
197
"(exported-override (slice file foo)",
220
302
dump(parse("File <| tag == 'foo' |>")).should == "(collect file\n (<| |> (== tag 'foo')))"
223
it "File <| tag == 'foo' and mode != 0777 |>" do
224
dump(parse("File <| tag == 'foo' and mode != 0777 |>")).should == "(collect file\n (<| |> (&& (== tag 'foo') (!= mode 0777))))"
227
it "File <| tag == 'foo' or mode != 0777 |>" do
228
dump(parse("File <| tag == 'foo' or mode != 0777 |>")).should == "(collect file\n (<| |> (|| (== tag 'foo') (!= mode 0777))))"
231
it "File <| tag == 'foo' or tag == 'bar' and mode != 0777 |>" do
232
dump(parse("File <| tag == 'foo' or tag == 'bar' and mode != 0777 |>")).should ==
233
"(collect file\n (<| |> (|| (== tag 'foo') (&& (== tag 'bar') (!= mode 0777)))))"
236
it "File <| (tag == 'foo' or tag == 'bar') and mode != 0777 |>" do
237
dump(parse("File <| (tag == 'foo' or tag == 'bar') and mode != 0777 |>")).should ==
238
"(collect file\n (<| |> (&& (|| (== tag 'foo') (== tag 'bar')) (!= mode 0777))))"
305
it "File <| tag == 'foo' and mode != '0777' |>" do
306
dump(parse("File <| tag == 'foo' and mode != '0777' |>")).should == "(collect file\n (<| |> (&& (== tag 'foo') (!= mode '0777'))))"
309
it "File <| tag == 'foo' or mode != '0777' |>" do
310
dump(parse("File <| tag == 'foo' or mode != '0777' |>")).should == "(collect file\n (<| |> (|| (== tag 'foo') (!= mode '0777'))))"
313
it "File <| tag == 'foo' or tag == 'bar' and mode != '0777' |>" do
314
dump(parse("File <| tag == 'foo' or tag == 'bar' and mode != '0777' |>")).should ==
315
"(collect file\n (<| |> (|| (== tag 'foo') (&& (== tag 'bar') (!= mode '0777')))))"
318
it "File <| (tag == 'foo' or tag == 'bar') and mode != '0777' |>" do
319
dump(parse("File <| (tag == 'foo' or tag == 'bar') and mode != '0777' |>")).should ==
320
"(collect file\n (<| |> (&& (|| (== tag 'foo') (== tag 'bar')) (!= mode '0777'))))"