puppet-lint 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/lib/puppet-lint.rb +1 -3
  2. data/lib/puppet-lint/configuration.rb +7 -6
  3. data/lib/puppet-lint/plugin.rb +14 -24
  4. data/lib/puppet-lint/plugins/check_classes.rb +14 -10
  5. data/lib/puppet-lint/plugins/check_documentation.rb +10 -14
  6. data/lib/puppet-lint/plugins/check_resources.rb +56 -73
  7. data/lib/puppet-lint/version.rb +1 -1
  8. data/spec/puppet-lint/configuration_spec.rb +4 -1
  9. data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +51 -0
  10. data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +23 -0
  11. data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +45 -0
  12. data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +71 -0
  13. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +67 -0
  14. data/spec/puppet-lint/plugins/check_classes/parameterised_classes_spec.rb +43 -0
  15. data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +23 -0
  16. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +93 -0
  17. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +16 -0
  18. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +19 -0
  19. data/spec/puppet-lint/plugins/{check_conditionals_spec.rb → check_conditionals/case_without_default_spec.rb} +1 -39
  20. data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +33 -0
  21. data/spec/puppet-lint/plugins/{check_documentation_spec.rb → check_documentation/documentation_spec.rb} +1 -9
  22. data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +23 -0
  23. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +43 -0
  24. data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +26 -0
  25. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +43 -0
  26. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +11 -0
  27. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +110 -0
  28. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +83 -0
  29. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +16 -0
  30. data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +55 -0
  31. data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +16 -0
  32. data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +29 -0
  33. data/spec/puppet-lint/plugins/{check_variables_spec.rb → check_variables/variable_contains_dash_spec.rb} +1 -9
  34. data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +20 -0
  35. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +38 -0
  36. data/spec/puppet-lint/plugins/{check_whitespace_spec.rb → check_whitespace/arrow_alignment_spec.rb} +1 -86
  37. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +16 -0
  38. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +16 -0
  39. data/spec/spec_helper.rb +17 -0
  40. metadata +122 -92
  41. data/spec/puppet-lint/plugins/check_classes_spec.rb +0 -390
  42. data/spec/puppet-lint/plugins/check_comments_spec.rb +0 -40
  43. data/spec/puppet-lint/plugins/check_resources_spec.rb +0 -249
  44. data/spec/puppet-lint/plugins/check_strings_spec.rb +0 -175
@@ -1,390 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PuppetLint::Plugins::CheckClasses do
4
- subject do
5
- klass = described_class.new
6
- fileinfo = {}
7
- fileinfo[:fullpath] = defined?(fullpath).nil? ? '' : fullpath
8
- klass.run(fileinfo, code)
9
- klass
10
- end
11
-
12
- describe 'chain 2 resources left to right' do
13
- let(:code) { "Class[foo] -> Class[bar]" }
14
-
15
- its(:problems) { should be_empty }
16
- end
17
-
18
- describe 'chain 2 resources right to left' do
19
- let(:code) { "Class[foo] <- Class[bar]" }
20
-
21
- its(:problems) {
22
- should have_problem({
23
- :kind => :warning,
24
- :message => "right-to-left (<-) relationship",
25
- :linenumber => 1,
26
- :column => 12,
27
- })
28
- should_not have_problem :kind => :error
29
- }
30
- end
31
-
32
- describe 'class on its own' do
33
- let(:code) { "class foo { }" }
34
-
35
- its(:problems) { should be_empty }
36
- end
37
-
38
- describe 'class inside a class' do
39
- let(:code) { "
40
- class foo {
41
- class bar {
42
- }
43
- }"
44
- }
45
-
46
- its(:problems) {
47
- should have_problem({
48
- :kind => :warning,
49
- :message => "class defined inside a class",
50
- :linenumber => 3,
51
- :column => 9,
52
- })
53
- should_not have_problem :kind => :error
54
- }
55
- end
56
-
57
- describe 'define inside a class' do
58
- let(:code) { "
59
- class foo {
60
- define bar() {
61
- }
62
- }"
63
- }
64
-
65
- its(:problems) {
66
- should have_problem({
67
- :kind => :warning,
68
- :message => "define defined inside a class",
69
- :linenumber => 3,
70
- :column => 9,
71
- })
72
- should_not have_problem :kind => :error
73
- }
74
- end
75
-
76
- describe 'class inheriting from its namespace' do
77
- let(:code) { "class foo::bar inherits foo { }" }
78
-
79
- its(:problems) { should be_empty }
80
- end
81
-
82
- describe 'class inheriting from another namespace' do
83
- let(:code) { "class foo::bar inherits baz { }" }
84
-
85
- its(:problems) {
86
- should have_problem({
87
- :kind => :warning,
88
- :message => "class inherits across namespaces",
89
- :linenumber => 1,
90
- :column => 25,
91
- })
92
- should_not have_problem :kind => :error
93
- }
94
- end
95
-
96
- describe 'parameterised class with a default value' do
97
- let(:code) { "class foo($bar, $baz='gronk') { }" }
98
-
99
- its(:problems) {
100
- should only_have_problem({
101
- :kind => :warning,
102
- :message => 'parameterised class parameter without a default value',
103
- :linenumber => 1,
104
- :column => 11,
105
- })
106
- }
107
- end
108
-
109
- describe 'parameterised class that inherits from a params class' do
110
- let(:code) { "class foo($bar = $name) inherits foo::params { }" }
111
-
112
- its(:problems) {
113
- should have_problem({
114
- :kind => :warning,
115
- :message => "class inheriting from params class",
116
- :linenumber => 1,
117
- :column => 34,
118
- })
119
- should_not have_problem :kind => :error
120
- }
121
- end
122
-
123
- describe 'define with attrs in order' do
124
- let(:code) { "define foo($bar, $baz='gronk') { }" }
125
-
126
- its(:problems) { should be_empty }
127
- end
128
-
129
- describe 'define with parameter that calls a function' do
130
- let(:code) { "define foo($bar=extlookup($name)) {}" }
131
-
132
- its(:problems) { should == [] }
133
- end
134
-
135
- describe 'define with attrs out of order' do
136
- let(:code) { "define foo($bar='baz', $gronk) { }" }
137
-
138
- its(:problems) {
139
- should have_problem({
140
- :kind => :warning,
141
- :message => "optional parameter listed before required parameter",
142
- :linenumber => 1,
143
- :column => 24,
144
- })
145
- should_not have_problem :kind => :error
146
- }
147
- end
148
-
149
- describe 'class with no variables declared accessing top scope' do
150
- let(:code) { "
151
- class foo {
152
- $bar = $baz
153
- }"
154
- }
155
-
156
- its(:problems) {
157
- should have_problem({
158
- :kind => :warning,
159
- :message => "top-scope variable being used without an explicit namespace",
160
- :linenumber => 3,
161
- :column => 16,
162
- })
163
- should_not have_problem :kind => :error
164
- }
165
- end
166
-
167
- describe 'class with no variables declared accessing top scope explicitly' do
168
- let(:code) { "
169
- class foo {
170
- $bar = $::baz
171
- }"
172
- }
173
-
174
- its(:problems) { should be_empty }
175
- end
176
-
177
- describe 'class with variables declared accessing local scope' do
178
- let(:code) { "
179
- class foo {
180
- $bar = 1
181
- $baz = $bar
182
- }"
183
- }
184
-
185
- its(:problems) { should be_empty }
186
- end
187
-
188
- describe 'class with parameters accessing local scope' do
189
- let(:code) { "
190
- class foo($bar='UNSET') {
191
- $baz = $bar
192
- }"
193
- }
194
-
195
- its(:problems) { should be_empty }
196
- end
197
-
198
- describe 'defined type with no variables declared accessing top scope' do
199
- let(:code) { "
200
- define foo() {
201
- $bar = $fqdn
202
- }"
203
- }
204
-
205
- its(:problems) {
206
- should have_problem({
207
- :kind => :warning,
208
- :message => "top-scope variable being used without an explicit namespace",
209
- :linenumber => 3,
210
- :column => 16,
211
- })
212
- should_not have_problem :kind => :error
213
- }
214
- end
215
-
216
- describe 'defined type with no variables declared accessing top scope explicitly' do
217
- let(:code) { "
218
- define foo() {
219
- $bar = $::fqdn
220
- }"
221
- }
222
-
223
- its(:problems) { should be_empty }
224
- end
225
-
226
- describe '$name should be auto defined' do
227
- let(:code) { "
228
- define foo() {
229
- $bar = $name
230
- $baz = $title
231
- $gronk = $module_name
232
- $meep = $1
233
- }"
234
- }
235
-
236
- its(:problems) { should be_empty }
237
- end
238
-
239
- describe 'instantiating a parametised class inside a class' do
240
- let(:code) { "
241
- class bar {
242
- class { 'foo':
243
- bar => 'foobar'
244
- }
245
- }"
246
- }
247
-
248
- its(:problems) { should be_empty }
249
- end
250
-
251
- describe 'instantiating a parametised class inside a define' do
252
- let(:code) { "
253
- define bar() {
254
- class { 'foo':
255
- bar => 'foobar'
256
- }
257
- }"
258
- }
259
-
260
- its(:problems) { should be_empty }
261
- end
262
-
263
- describe 'class/define parameter set to another variable' do
264
- let(:code) { "
265
- define foo($bar, $baz = $name, $gronk=$::fqdn) {
266
- }"
267
- }
268
-
269
- its(:problems) { should be_empty }
270
- end
271
-
272
- describe 'class/define parameter set to another variable with incorrect order' do
273
- let(:code) { "
274
- define foo($baz = $name, $bar, $gronk=$::fqdn) {
275
- }"
276
- }
277
-
278
- its(:problems) {
279
- should have_problem({
280
- :kind => :warning,
281
- :message => "optional parameter listed before required parameter",
282
- :linenumber => 2,
283
- :column => 32,
284
- })
285
- should_not have_problem :kind => :error
286
- }
287
- end
288
-
289
- describe 'foo::bar in foo/manifests/bar.pp' do
290
- let(:code) { "class foo::bar { }" }
291
- let(:fullpath) { '/etc/puppet/modules/foo/manifests/bar.pp' }
292
-
293
- its(:problems) { should be_empty }
294
- end
295
-
296
- describe 'foo::bar::baz in foo/manifests/bar/baz.pp' do
297
- let(:code) { 'define foo::bar::baz() { }' }
298
- let(:fullpath) { '/etc/puppet/modules/foo/manifests/bar/baz.pp' }
299
-
300
- its(:problems) { should be_empty }
301
- end
302
-
303
- describe 'foo in foo/manifests/init.pp' do
304
- let(:code) { 'class foo { }' }
305
- let(:fullpath) { '/etc/puppet/modules/foo/manifests/init.pp' }
306
-
307
- its(:problems) { should be_empty }
308
- end
309
-
310
- describe 'foo::bar in foo/manifests/init.pp' do
311
- let(:code) { 'class foo::bar { }' }
312
- let(:fullpath) { '/etc/puppet/modules/foo/manifests/init.pp' }
313
-
314
- its(:problems) {
315
- should only_have_problem({
316
- :kind => :error,
317
- :message => "foo::bar not in autoload module layout",
318
- :linenumber => 1,
319
- :column => 7,
320
- })
321
- }
322
- end
323
-
324
- describe 'foo included in bar/manifests/init.pp' do
325
- let(:code) { "
326
- class bar {
327
- class {'foo':
328
- someparam => 'somevalue',
329
- }
330
- }
331
- "
332
- }
333
- let(:fullpath) { '/etc/puppet/modules/bar/manifests/init.pp' }
334
- its(:problems) { should be_empty }
335
- end
336
-
337
- describe 'issue-101' do
338
- let(:code) { "
339
- define b (
340
- $foo,
341
- $bar='',
342
- $baz={}
343
- ) { }
344
- " }
345
-
346
- its(:problems) { should == [] }
347
- end
348
-
349
- describe 'module named foo-bar' do
350
- let(:code) { 'class foo-bar { }' }
351
- let(:fullpath) { '/etc/puppet/modules/foo-bar/manifests/init.pp' }
352
-
353
- its(:problems) do
354
- should only_have_problem({
355
- :kind => :warning,
356
- :message => 'class name containing a dash',
357
- :linenumber => 1,
358
- :column => 7,
359
- })
360
- end
361
- end
362
-
363
- describe 'define named foo-bar' do
364
- let(:code) { 'define foo::foo-bar { }' }
365
- let(:fullpath) { '/etc/puppet/modules/foo/manifests/foo-bar.pp' }
366
-
367
- its(:problems) do
368
- should only_have_problem({
369
- :kind => :warning,
370
- :message => 'defined type name containing a dash',
371
- :linenumber => 1,
372
- :column => 8,
373
- })
374
- end
375
- end
376
-
377
- describe 'class named bar-foo' do
378
- let(:code) { 'class foo::bar-foo { }' }
379
- let(:fullpath) { '/etc/puppet/modules/foo/manifests/bar-foo.pp' }
380
-
381
- its(:problems) do
382
- should only_have_problem({
383
- :kind => :warning,
384
- :message => 'class name containing a dash',
385
- :linenumber => 1,
386
- :column => 7,
387
- })
388
- end
389
- end
390
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PuppetLint::Plugins::CheckComments do
4
- subject do
5
- klass = described_class.new
6
- fileinfo = {}
7
- fileinfo[:fullpath] = defined?(fullpath).nil? ? '' : fullpath
8
- klass.run(fileinfo, code)
9
- klass
10
- end
11
-
12
- describe 'slash comments' do
13
- let(:code) { "// foo" }
14
-
15
- its(:problems) do
16
- should only_have_problem({
17
- :kind => :warning,
18
- :message => '// comment found',
19
- :linenumber => 1,
20
- :column => 1,
21
- })
22
- end
23
- end
24
-
25
- describe 'slash asterisk comment' do
26
- let(:code) { "
27
- /* foo
28
- */
29
- "}
30
-
31
- its(:problems) do
32
- should only_have_problem({
33
- :kind => :warning,
34
- :message => '/* */ comment found',
35
- :linenumber => 2,
36
- :column => 7,
37
- })
38
- end
39
- end
40
- end
@@ -1,249 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PuppetLint::Plugins::CheckResources do
4
- subject do
5
- klass = described_class.new
6
- klass.run(defined?(fullpath).nil? ? {:fullpath => ''} : {:fullpath => fullpath}, code)
7
- klass
8
- end
9
-
10
- describe '3 digit file mode' do
11
- let(:code) { "file { 'foo': mode => '777' }" }
12
-
13
- its(:problems) {
14
- should only_have_problem :kind => :warning, :message => "mode should be represented as a 4 digit octal value or symbolic mode", :linenumber => 1
15
- }
16
- end
17
-
18
- describe '4 digit file mode' do
19
- let(:code) { "file { 'foo': mode => '0777' }" }
20
-
21
- its(:problems) { should be_empty }
22
- end
23
-
24
- describe '4 digit unquoted file mode' do
25
- let(:code) { "file { 'foo': mode => 0777 }" }
26
-
27
- its(:problems) {
28
- should only_have_problem :kind => :warning, :message => "unquoted file mode"
29
- }
30
- end
31
-
32
- describe 'file mode as a variable' do
33
- let(:code) { "file { 'foo': mode => $file_mode }" }
34
-
35
- its(:problems) { should be_empty }
36
- end
37
-
38
- describe 'symbolic file mode' do
39
- let(:code) { "file { 'foo': mode => 'u=rw,og=r' }" }
40
-
41
- its(:problems) { should be_empty }
42
- end
43
-
44
- describe 'file mode undef unquoted' do
45
- let(:code) { "file { 'foo': mode => undef }" }
46
-
47
- its(:problems) { should be_empty }
48
- end
49
-
50
- describe 'file mode undef quoted' do
51
- let(:code) { "file { 'foo': mode => 'undef' }" }
52
-
53
- its(:problems) {
54
- should only_have_problem :kind => :warning, :message => "mode should be represented as a 4 digit octal value or symbolic mode", :linenumber => 1
55
- }
56
- end
57
-
58
- describe 'ensure as only attr in a single line resource' do
59
- let(:code) { "file { 'foo': ensure => present }" }
60
-
61
- its(:problems) { should be_empty }
62
- end
63
-
64
- describe 'ensure as only attr in a multi line resource' do
65
- let(:code) { "
66
- file { 'foo':
67
- ensure => present,
68
- }"
69
- }
70
-
71
- its(:problems) { should be_empty }
72
- end
73
-
74
- describe 'ensure as second attr in a multi line resource' do
75
- let(:code) { "
76
- file { 'foo':
77
- mode => '0000',
78
- ensure => present,
79
- }"
80
- }
81
-
82
- its(:problems) {
83
- should only_have_problem :kind => :warning, :message => "ensure found on line but it's not the first attribute", :linenumber => 4
84
- }
85
- end
86
-
87
- describe 'ensure as first attr in a multi line resource' do
88
- let(:code) { "
89
- file { 'foo':
90
- ensure => present,
91
- mode => '0000',
92
- }"
93
- }
94
-
95
- its(:problems) { should be_empty }
96
- end
97
-
98
- describe 'quoted resource title on single line resource' do
99
- let(:code) { "file { 'foo': }" }
100
-
101
- its(:problems) { should be_empty }
102
- end
103
-
104
- describe 'unquoted resource title on single line resource' do
105
- let(:code) { "file { foo: }" }
106
-
107
- its(:problems) {
108
- should only_have_problem :kind => :warning, :message => "unquoted resource title", :linenumber => 1
109
- }
110
- end
111
-
112
- describe 'quoted resource title on multi line resource' do
113
- let(:code) { "
114
- file { 'foo':
115
- }"
116
- }
117
-
118
- its(:problems) { should be_empty }
119
- end
120
-
121
- describe 'unquoted resource title on multi line resource' do
122
- let(:code) { "
123
- file { foo:
124
- }"
125
- }
126
-
127
- its(:problems) {
128
- should only_have_problem :kind => :warning, :message => "unquoted resource title", :linenumber => 2
129
- }
130
- end
131
-
132
- describe 'condensed resources with quoted titles' do
133
- let(:code) { "
134
- file {
135
- 'foo': ;
136
- 'bar': ;
137
- }"
138
- }
139
-
140
- its(:problems) { should be_empty }
141
- end
142
-
143
- describe 'condensed resources with an unquoted title' do
144
- let(:code) { "
145
- file {
146
- 'foo': ;
147
- bar: ;
148
- }"
149
- }
150
-
151
- its(:problems) {
152
- should only_have_problem :kind => :warning, :message => "unquoted resource title", :linenumber => 4
153
- }
154
- end
155
-
156
- describe 'single line resource with an array of titles (all quoted)' do
157
- let(:code) { "file { ['foo', 'bar']: }" }
158
-
159
- its(:problems) { should be_empty }
160
- end
161
-
162
- describe 'resource inside a case statement' do
163
- let(:code) { "
164
- case $ensure {
165
- 'absent': {
166
- file { \"some_file_${name}\":
167
- ensure => absent,
168
- }
169
- }
170
- }"
171
- }
172
-
173
- its(:problems) { should == [] }
174
- end
175
-
176
- describe 'file resource creating a symlink with seperate target attr' do
177
- let(:code) { "
178
- file { 'foo':
179
- ensure => link,
180
- target => '/foo/bar',
181
- }"
182
- }
183
-
184
- its(:problems) { should be_empty }
185
- end
186
-
187
- describe 'file resource creating a symlink with target specified in ensure' do
188
- let(:code) { "
189
- file { 'foo':
190
- ensure => '/foo/bar',
191
- }"
192
- }
193
-
194
- its(:problems) {
195
- should only_have_problem :kind => :warning, :message => "symlink target specified in ensure attr", :linenumber => 3
196
- }
197
- end
198
-
199
- # This should really be a lexer test, but I haven't had time to write that
200
- # test suite yet.
201
- describe 'issue #116' do
202
- let(:code) { "
203
- $config_file_init = $::operatingsystem ? {
204
- /(?i:Debian|Ubuntu|Mint)/ => '/etc/default/foo',
205
- default => '/etc/sysconfig/foo',
206
- }"
207
- }
208
-
209
- its(:problems) { should == [] }
210
- end
211
-
212
- describe 'resource with duplicate parameters' do
213
- let(:code) { "
214
- file { '/tmp/foo':
215
- ensure => present,
216
- foo => bar,
217
- baz => gronk,
218
- foo => meh,
219
- }"
220
- }
221
-
222
- its(:problems) {
223
- should only_have_problem({
224
- :kind => :error,
225
- :message => 'duplicate parameter found in resource',
226
- :linenumber => 6,
227
- :column => 9,
228
- })
229
- }
230
- end
231
-
232
- describe 'case statement' do
233
- let(:code) { %{
234
- case $operatingsystem {
235
- centos: {
236
- $version = '1.2.3'
237
- }
238
- solaris: {
239
- $version = '3.2.1'
240
- }
241
- default: {
242
- fail("Module ${module_name} is not supported on ${operatingsystem}")
243
- }
244
- }}
245
- }
246
-
247
- its(:problems) { should == [] }
248
- end
249
- end