~ubuntu-branches/ubuntu/wily/puppet/wily-proposed

« back to all changes in this revision

Viewing changes to spec/unit/pops/parser/parse_resource_spec.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2014-10-24 13:47:15 UTC
  • mfrom: (3.1.64 sid)
  • Revision ID: package-import@ubuntu.com-20141024134715-6ig54u0c4gar36ss
Tags: 3.7.2-1
* Imported upstream release 3.7.2
* Declare compliance with Debian Policy 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
  include ParserRspecHelper
10
10
 
11
11
  context "When parsing regular resource" do
12
 
    it "file { 'title': }" do
13
 
      dump(parse("file { 'title': }")).should == [
14
 
        "(resource file",
15
 
        "  ('title'))"
16
 
      ].join("\n")
17
 
    end
18
 
 
19
 
    it "file { 'title': path => '/somewhere', mode => 0777}" do
20
 
      dump(parse("file { 'title': path => '/somewhere', mode => 0777}")).should == [
21
 
        "(resource file",
22
 
        "  ('title'",
23
 
        "    (path => '/somewhere')",
24
 
        "    (mode => 0777)))"
25
 
      ].join("\n")
26
 
    end
27
 
 
28
 
    it "file { 'title': path => '/somewhere', }" do
29
 
      dump(parse("file { 'title': path => '/somewhere', }")).should == [
30
 
        "(resource file",
31
 
        "  ('title'",
32
 
        "    (path => '/somewhere')))"
33
 
      ].join("\n")
34
 
    end
35
 
 
36
 
    it "file { 'title': , }" do
37
 
      dump(parse("file { 'title': , }")).should == [
38
 
        "(resource file",
39
 
        "  ('title'))"
40
 
      ].join("\n")
41
 
    end
42
 
 
43
 
    it "file { 'title': ; }" do
44
 
      dump(parse("file { 'title': ; }")).should == [
45
 
        "(resource file",
46
 
        "  ('title'))"
47
 
      ].join("\n")
48
 
    end
49
 
 
50
 
    it "file { 'title': ; 'other_title': }" do
51
 
      dump(parse("file { 'title': ; 'other_title': }")).should == [
52
 
        "(resource file",
53
 
        "  ('title')",
54
 
        "  ('other_title'))"
55
 
      ].join("\n")
56
 
    end
57
 
 
58
 
    it "file { 'title1': path => 'x'; 'title2': path => 'y'}" do
59
 
      dump(parse("file { 'title1': path => 'x'; 'title2': path => 'y'}")).should == [
60
 
        "(resource file",
61
 
        "  ('title1'",
62
 
        "    (path => 'x'))",
63
 
        "  ('title2'",
64
 
        "    (path => 'y')))",
65
 
      ].join("\n")
 
12
    ["File", "file"].each do |word|
 
13
      it "#{word} { 'title': }" do
 
14
        dump(parse("#{word} { 'title': }")).should == [
 
15
          "(resource file",
 
16
          "  ('title'))"
 
17
        ].join("\n")
 
18
      end
 
19
 
 
20
      it "#{word} { 'title': path => '/somewhere', mode => '0777'}" do
 
21
        dump(parse("#{word} { 'title': path => '/somewhere', mode => '0777'}")).should == [
 
22
          "(resource file",
 
23
          "  ('title'",
 
24
          "    (path => '/somewhere')",
 
25
          "    (mode => '0777')))"
 
26
        ].join("\n")
 
27
      end
 
28
 
 
29
      it "#{word} { 'title': path => '/somewhere', }" do
 
30
        dump(parse("#{word} { 'title': path => '/somewhere', }")).should == [
 
31
          "(resource file",
 
32
          "  ('title'",
 
33
          "    (path => '/somewhere')))"
 
34
        ].join("\n")
 
35
      end
 
36
 
 
37
      it "#{word} { 'title': , }" do
 
38
        dump(parse("#{word} { 'title': , }")).should == [
 
39
          "(resource file",
 
40
          "  ('title'))"
 
41
        ].join("\n")
 
42
      end
 
43
 
 
44
      it "#{word} { 'title': ; }" do
 
45
        dump(parse("#{word} { 'title': ; }")).should == [
 
46
          "(resource file",
 
47
          "  ('title'))"
 
48
        ].join("\n")
 
49
      end
 
50
 
 
51
      it "#{word} { 'title': ; 'other_title': }" do
 
52
        dump(parse("#{word} { 'title': ; 'other_title': }")).should == [
 
53
          "(resource file",
 
54
          "  ('title')",
 
55
          "  ('other_title'))"
 
56
        ].join("\n")
 
57
      end
 
58
 
 
59
      # PUP-2898, trailing ';'
 
60
      it "#{word} { 'title': ; 'other_title': ; }" do
 
61
        dump(parse("#{word} { 'title': ; 'other_title': ; }")).should == [
 
62
          "(resource file",
 
63
          "  ('title')",
 
64
          "  ('other_title'))"
 
65
        ].join("\n")
 
66
      end
 
67
 
 
68
      it "#{word} { 'title1': path => 'x'; 'title2': path => 'y'}" do
 
69
        dump(parse("#{word} { 'title1': path => 'x'; 'title2': path => 'y'}")).should == [
 
70
          "(resource file",
 
71
          "  ('title1'",
 
72
          "    (path => 'x'))",
 
73
          "  ('title2'",
 
74
          "    (path => 'y')))",
 
75
        ].join("\n")
 
76
      end
 
77
 
 
78
      it "#{word} { title: * => {mode => '0777'} }" do
 
79
        dump(parse("#{word} { title: * => {mode => '0777'}}")).should == [
 
80
          "(resource file",
 
81
          "  (title",
 
82
          "    (* => ({} (mode '0777')))))"
 
83
        ].join("\n")
 
84
      end
66
85
    end
67
86
  end
68
87
 
69
 
  context "When parsing resource defaults" do
 
88
  context "When parsing (type based) resource defaults" do
70
89
    it "File {  }" do
71
90
      dump(parse("File { }")).should == "(resource-defaults file)"
72
91
    end
73
92
 
74
 
    it "File { mode => 0777 }" do
75
 
      dump(parse("File { mode => 0777}")).should == [
76
 
        "(resource-defaults file",
77
 
        "  (mode => 0777))"
 
93
    it "File { mode => '0777' }" do
 
94
      dump(parse("File { mode => '0777'}")).should == [
 
95
        "(resource-defaults file",
 
96
        "  (mode => '0777'))"
 
97
      ].join("\n")
 
98
    end
 
99
 
 
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'))))"
78
104
      ].join("\n")
79
105
    end
80
106
  end
85
111
    end
86
112
 
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')",
 
116
        "  (x => 1))"
 
117
        ].join("\n")
89
118
    end
90
119
 
 
120
 
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'))",
 
124
        "  (x => 1))"
 
125
        ].join("\n")
93
126
    end
94
127
 
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')",
 
131
        "  (x => 1)",
 
132
        "  (y => 2))"
 
133
        ].join("\n")
97
134
    end
98
135
 
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')",
 
139
        "  (x +> 1))"
 
140
        ].join("\n")
 
141
    end
 
142
 
 
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'))))"
 
147
      ].join("\n")
101
148
    end
102
149
  end
103
150
 
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'))"
107
154
    end
108
155
 
109
 
    it "@file { 'title': }" do
 
156
    it "parses virtual @file { 'title': }" do
110
157
      dump(parse("@file { 'title': }")).should ==  "(virtual-resource file\n  ('title'))"
111
158
    end
112
159
 
113
 
    it "@file { mode => 0777 }" do
114
 
      # Defaults are not virtualizeable
115
 
      expect {
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
 
161
      expect do
 
162
        parse("@file {: mode => '0777' }")
 
163
      end.to raise_error(/Syntax error/)
 
164
    end
 
165
 
 
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
 
168
      # no title.
 
169
      expect do
 
170
        parse("@file { mode => '0777' }")
 
171
      end.to raise_error(/Virtual \(@\) can only be applied to a Resource Expression/)
 
172
    end
 
173
 
 
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",
 
177
        "  (mode => '0777'))"
 
178
        ].join("\n")
 
179
    end
 
180
 
 
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",
 
184
        "  (mode => '0777'))"
 
185
        ].join("\n")
 
186
    end
 
187
 
 
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)",
 
191
        "  (mode => '0777'))"
 
192
        ].join("\n")
 
193
    end
 
194
 
 
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)",
 
198
        "  (mode => '0777'))"
 
199
        ].join("\n")
118
200
    end
119
201
  end
120
202
 
220
302
        dump(parse("File <| tag == 'foo' |>")).should == "(collect file\n  (<| |> (== tag 'foo')))"
221
303
      end
222
304
 
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))))"
225
 
      end
226
 
 
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))))"
229
 
      end
230
 
 
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)))))"
234
 
      end
235
 
 
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'))))"
 
307
      end
 
308
 
 
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'))))"
 
311
      end
 
312
 
 
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')))))"
 
316
      end
 
317
 
 
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'))))"
239
321
      end
240
322
    end
241
323
  end