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
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'names_containing_dash' do
4
+ describe 'module named foo-bar' do
5
+ let(:code) { 'class foo-bar { }' }
6
+ let(:fullpath) { '/etc/puppet/modules/foo-bar/manifests/init.pp' }
7
+
8
+ its(:problems) do
9
+ should only_have_problem({
10
+ :kind => :warning,
11
+ :message => 'class name containing a dash',
12
+ :linenumber => 1,
13
+ :column => 7,
14
+ })
15
+ end
16
+ end
17
+
18
+ describe 'define named foo-bar' do
19
+ let(:code) { 'define foo::foo-bar { }' }
20
+ let(:fullpath) { '/etc/puppet/modules/foo/manifests/foo-bar.pp' }
21
+
22
+ its(:problems) do
23
+ should only_have_problem({
24
+ :kind => :warning,
25
+ :message => 'defined type name containing a dash',
26
+ :linenumber => 1,
27
+ :column => 8,
28
+ })
29
+ end
30
+ end
31
+
32
+ describe 'class named bar-foo' do
33
+ let(:code) { 'class foo::bar-foo { }' }
34
+ let(:fullpath) { '/etc/puppet/modules/foo/manifests/bar-foo.pp' }
35
+
36
+ its(:problems) do
37
+ should only_have_problem({
38
+ :kind => :warning,
39
+ :message => 'class name containing a dash',
40
+ :linenumber => 1,
41
+ :column => 7,
42
+ })
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'nested_classes_or_defines' do
4
+ describe 'class on its own' do
5
+ let(:code) { "class foo { }" }
6
+
7
+ its(:problems) { should be_empty }
8
+ end
9
+
10
+ describe 'class inside a class' do
11
+ let(:code) { "
12
+ class foo {
13
+ class bar {
14
+ }
15
+ }"
16
+ }
17
+
18
+ its(:problems) {
19
+ should have_problem({
20
+ :kind => :warning,
21
+ :message => "class defined inside a class",
22
+ :linenumber => 3,
23
+ :column => 9,
24
+ })
25
+ should_not have_problem :kind => :error
26
+ }
27
+ end
28
+
29
+ describe 'instantiating a parametised class inside a class' do
30
+ let(:code) { "
31
+ class bar {
32
+ class { 'foo':
33
+ bar => 'foobar'
34
+ }
35
+ }"
36
+ }
37
+
38
+ its(:problems) { should be_empty }
39
+ end
40
+
41
+ describe 'instantiating a parametised class inside a define' do
42
+ let(:code) { "
43
+ define bar() {
44
+ class { 'foo':
45
+ bar => 'foobar'
46
+ }
47
+ }"
48
+ }
49
+
50
+ its(:problems) { should be_empty }
51
+ end
52
+
53
+ describe 'define inside a class' do
54
+ let(:code) { "
55
+ class foo {
56
+ define bar() {
57
+ }
58
+ }"
59
+ }
60
+
61
+ its(:problems) {
62
+ should have_problem({
63
+ :kind => :warning,
64
+ :message => "define defined inside a class",
65
+ :linenumber => 3,
66
+ :column => 9,
67
+ })
68
+ should_not have_problem :kind => :error
69
+ }
70
+ end
71
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'parameter_order' do
4
+ describe 'define with attrs in order' do
5
+ let(:code) { "define foo($bar, $baz='gronk') { }" }
6
+
7
+ its(:problems) { should be_empty }
8
+ end
9
+
10
+ describe 'define with parameter that calls a function' do
11
+ let(:code) { "define foo($bar=extlookup($name)) {}" }
12
+
13
+ its(:problems) { should == [] }
14
+ end
15
+
16
+ describe 'define with attrs out of order' do
17
+ let(:code) { "define foo($bar='baz', $gronk) { }" }
18
+
19
+ its(:problems) {
20
+ should have_problem({
21
+ :kind => :warning,
22
+ :message => "optional parameter listed before required parameter",
23
+ :linenumber => 1,
24
+ :column => 24,
25
+ })
26
+ should_not have_problem :kind => :error
27
+ }
28
+ end
29
+
30
+ describe 'class/define parameter set to another variable' do
31
+ let(:code) { "
32
+ define foo($bar, $baz = $name, $gronk=$::fqdn) {
33
+ }"
34
+ }
35
+
36
+ its(:problems) { should be_empty }
37
+ end
38
+
39
+ describe 'class/define parameter set to another variable with incorrect order' do
40
+ let(:code) { "
41
+ define foo($baz = $name, $bar, $gronk=$::fqdn) {
42
+ }"
43
+ }
44
+
45
+ its(:problems) {
46
+ should have_problem({
47
+ :kind => :warning,
48
+ :message => "optional parameter listed before required parameter",
49
+ :linenumber => 2,
50
+ :column => 32,
51
+ })
52
+ should_not have_problem :kind => :error
53
+ }
54
+ end
55
+
56
+ describe 'issue-101' do
57
+ let(:code) { "
58
+ define b (
59
+ $foo,
60
+ $bar='',
61
+ $baz={}
62
+ ) { }
63
+ " }
64
+
65
+ its(:problems) { should == [] }
66
+ end
67
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'parameterised_classes' do
4
+ describe 'parameterised class with a default value' do
5
+ let(:code) { "class foo($bar, $baz='gronk') { }" }
6
+
7
+ its(:problems) {
8
+ should only_have_problem({
9
+ :kind => :warning,
10
+ :message => 'parameterised class parameter without a default value',
11
+ :linenumber => 1,
12
+ :column => 11,
13
+ })
14
+ }
15
+ end
16
+
17
+ describe 'parameterised class that inherits from a params class' do
18
+ let(:code) { "class foo($bar = $name) inherits foo::params { }" }
19
+
20
+ its(:problems) {
21
+ should have_problem({
22
+ :kind => :warning,
23
+ :message => "class inheriting from params class",
24
+ :linenumber => 1,
25
+ :column => 34,
26
+ })
27
+ should_not have_problem :kind => :error
28
+ }
29
+ end
30
+
31
+ describe 'class without parameters' do
32
+ let(:code) {"
33
+ class myclass {
34
+
35
+ if ( $::lsbdistcodename == 'squeeze' ) {
36
+ #TODO
37
+ }
38
+ }
39
+ "}
40
+
41
+ its(:problems) { should == [] }
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'right_to_left_relationship' do
4
+ describe 'chain 2 resources left to right' do
5
+ let(:code) { "Class[foo] -> Class[bar]" }
6
+
7
+ its(:problems) { should be_empty }
8
+ end
9
+
10
+ describe 'chain 2 resources right to left' do
11
+ let(:code) { "Class[foo] <- Class[bar]" }
12
+
13
+ its(:problems) {
14
+ should have_problem({
15
+ :kind => :warning,
16
+ :message => "right-to-left (<-) relationship",
17
+ :linenumber => 1,
18
+ :column => 12,
19
+ })
20
+ should_not have_problem :kind => :error
21
+ }
22
+ end
23
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'variable_scope' do
4
+ describe 'class with no variables declared accessing top scope' do
5
+ let(:code) { "
6
+ class foo {
7
+ $bar = $baz
8
+ }"
9
+ }
10
+
11
+ its(:problems) {
12
+ should have_problem({
13
+ :kind => :warning,
14
+ :message => "top-scope variable being used without an explicit namespace",
15
+ :linenumber => 3,
16
+ :column => 16,
17
+ })
18
+ should_not have_problem :kind => :error
19
+ }
20
+ end
21
+
22
+ describe 'class with no variables declared accessing top scope explicitly' do
23
+ let(:code) { "
24
+ class foo {
25
+ $bar = $::baz
26
+ }"
27
+ }
28
+
29
+ its(:problems) { should be_empty }
30
+ end
31
+
32
+ describe 'class with variables declared accessing local scope' do
33
+ let(:code) { "
34
+ class foo {
35
+ $bar = 1
36
+ $baz = $bar
37
+ }"
38
+ }
39
+
40
+ its(:problems) { should be_empty }
41
+ end
42
+
43
+ describe 'class with parameters accessing local scope' do
44
+ let(:code) { "
45
+ class foo($bar='UNSET') {
46
+ $baz = $bar
47
+ }"
48
+ }
49
+
50
+ its(:problems) { should be_empty }
51
+ end
52
+
53
+ describe 'defined type with no variables declared accessing top scope' do
54
+ let(:code) { "
55
+ define foo() {
56
+ $bar = $fqdn
57
+ }"
58
+ }
59
+
60
+ its(:problems) {
61
+ should have_problem({
62
+ :kind => :warning,
63
+ :message => "top-scope variable being used without an explicit namespace",
64
+ :linenumber => 3,
65
+ :column => 16,
66
+ })
67
+ should_not have_problem :kind => :error
68
+ }
69
+ end
70
+
71
+ describe 'defined type with no variables declared accessing top scope explicitly' do
72
+ let(:code) { "
73
+ define foo() {
74
+ $bar = $::fqdn
75
+ }"
76
+ }
77
+
78
+ its(:problems) { should be_empty }
79
+ end
80
+
81
+ describe '$name should be auto defined' do
82
+ let(:code) { "
83
+ define foo() {
84
+ $bar = $name
85
+ $baz = $title
86
+ $gronk = $module_name
87
+ $meep = $1
88
+ }"
89
+ }
90
+
91
+ its(:problems) { should be_empty }
92
+ end
93
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'slash_comments' do
4
+ describe 'slash comments' do
5
+ let(:code) { "// foo" }
6
+
7
+ its(:problems) do
8
+ should only_have_problem({
9
+ :kind => :warning,
10
+ :message => '// comment found',
11
+ :linenumber => 1,
12
+ :column => 1,
13
+ })
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'star_comments' do
4
+ describe 'slash asterisk comment' do
5
+ let(:code) { "
6
+ /* foo
7
+ */
8
+ "}
9
+
10
+ its(:problems) do
11
+ should only_have_problem({
12
+ :kind => :warning,
13
+ :message => '/* */ comment found',
14
+ :linenumber => 2,
15
+ :column => 7,
16
+ })
17
+ end
18
+ end
19
+ end
@@ -1,44 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe PuppetLint::Plugins::CheckConditionals 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 'resource with a selector' do
13
- let(:code) { "
14
- file { 'foo':
15
- ensure => $bar ? {
16
- true => present,
17
- default => absent,
18
- },
19
- }"
20
- }
21
-
22
- its(:problems) do
23
- should only_have_problem({
24
- :kind => :warning,
25
- :message => 'selector inside resource block',
26
- :linenumber => 3,
27
- :column => 16,
28
- })
29
- end
30
- end
31
-
32
- describe 'resource with a variable as a attr value' do
33
- let(:code) { "
34
- file { 'foo',
35
- ensure => $bar,
36
- }"
37
- }
38
-
39
- its(:problems) { should be_empty }
40
- end
41
-
3
+ describe 'case_without_default' do
42
4
  describe 'case statement with a default case' do
43
5
  let(:code) { "
44
6
  case $foo {
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'selector_inside_resource' do
4
+ describe 'resource with a selector' do
5
+ let(:code) { "
6
+ file { 'foo':
7
+ ensure => $bar ? {
8
+ true => present,
9
+ default => absent,
10
+ },
11
+ }"
12
+ }
13
+
14
+ its(:problems) do
15
+ should only_have_problem({
16
+ :kind => :warning,
17
+ :message => 'selector inside resource block',
18
+ :linenumber => 3,
19
+ :column => 16,
20
+ })
21
+ end
22
+ end
23
+
24
+ describe 'resource with a variable as a attr value' do
25
+ let(:code) { "
26
+ file { 'foo',
27
+ ensure => $bar,
28
+ }"
29
+ }
30
+
31
+ its(:problems) { should be_empty }
32
+ end
33
+ end