puppet-lint-wmf_styleguide-check 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,180 @@
1
+ require 'spec_helper'
2
+
3
+ class_ok = <<-EOF
4
+ class foo {
5
+ notice("foo!")
6
+ include ::foo::configuration
7
+ sysctl::setting { 'something':
8
+ value => 10,
9
+ }
10
+ }
11
+ EOF
12
+
13
+ class_ko = <<-EOF
14
+ class foo($t=hiera('foo::title')) {
15
+ $msg = hiera( "foo::bar")
16
+ notice($msg)
17
+ notice($t)
18
+ include ::passwords::redis
19
+ class { 'bar': }
20
+ }
21
+ EOF
22
+
23
+ profile_ok = <<-EOF
24
+ class profile::foobar ($test=hiera('profile::foobar::test')) {
25
+ require ::profile::foo
26
+ include ::passwords::redis
27
+ class { '::bar': }
28
+ }
29
+ EOF
30
+
31
+ profile_ko = <<-EOF
32
+ class profile::fixme (
33
+ $test,
34
+ ) {
35
+ include ::apache2::common
36
+ $role = hiera('role')
37
+ system::role { $role: }
38
+ }
39
+ EOF
40
+
41
+ role_ok = <<-EOF
42
+ class role::fizzbuz {
43
+ include standard
44
+ include ::profile::base
45
+ include ::profile::bar
46
+ system::role { 'fizzbuzz': }
47
+ }
48
+ EOF
49
+
50
+ role_ko = <<-EOF
51
+ class role::fixme () {
52
+ include ::monitoring::host
53
+ include ::profile::base
54
+ class { '::role::something': }
55
+ }
56
+ EOF
57
+
58
+ define_ok = <<-EOF
59
+ define foo::bar (
60
+ sysctl::setting { 'test': }
61
+ file { 'something':
62
+ content => template('something.erb')
63
+ }
64
+ )
65
+ EOF
66
+
67
+ define_ko = <<-EOF
68
+ define foo::fixme ($a=hiera('something')) {
69
+ include ::foo
70
+ class { '::bar': }
71
+ }
72
+ EOF
73
+
74
+ node_ok = <<-EOF
75
+ node /^test1.*\.example\.com$/ {
76
+ role(spare::system)
77
+ }
78
+ EOF
79
+
80
+ node_ko = <<-EOF
81
+ node 'fixme' {
82
+ role(spare::system,
83
+ mediawiki::appserver)
84
+ include base::firewall
85
+ interface::mapped { 'eth0':
86
+ foo => 'bar'
87
+ }
88
+ }
89
+ EOF
90
+
91
+ describe 'wmf_styleguide' do
92
+ context 'class correctly written' do
93
+ let(:code) { class_ok }
94
+ it 'should not detect any problems' do
95
+ puts(problems)
96
+ expect(problems).to have(0).problems
97
+ end
98
+ end
99
+ context 'profile correctly written' do
100
+ let(:code) { profile_ok }
101
+ it 'should not detect any problems' do
102
+ expect(problems).to have(0).problems
103
+ end
104
+ end
105
+ context 'role correctly written' do
106
+ let(:code) { role_ok }
107
+ it 'should not detect any problems' do
108
+ expect(problems).to have(0).problems
109
+ end
110
+ end
111
+
112
+ context 'class with errors' do
113
+ let(:code) { class_ko }
114
+ it 'should create errors for hiera declarations' do
115
+ expect(problems).to contain_error("wmf-style: Found hiera call in class 'foo' for 'foo::title'").on_line(1).in_column(14)
116
+ expect(problems).to contain_error("wmf-style: Found hiera call in class 'foo' for 'foo::bar'").on_line(2).in_column(15)
117
+ end
118
+ it 'should create errors for included classes' do
119
+ expect(problems).to contain_error("wmf-style: class 'foo' includes passwords::redis from another module").on_line(5).in_column(16)
120
+ expect(problems).to contain_error("wmf-style: class 'foo' declares class bar from another module").on_line(6).in_column(16)
121
+ end
122
+ end
123
+
124
+ context 'profile with errors' do
125
+ let(:code) { profile_ko }
126
+ it 'should create errors for parameters without hiera defaults' do
127
+ expect(problems).to contain_error("wmf-style: Parameter 'test' of class 'profile::fixme' has no call to hiera").on_line(2).in_column(7)
128
+ end
129
+ it 'should create errors for hiera calls in body' do
130
+ expect(problems).to contain_error("wmf-style: Found hiera call in class 'profile::fixme' for 'role'").on_line(5).in_column(13)
131
+ end
132
+ it 'should create errors for use of system::role' do
133
+ expect(problems).to contain_error("wmf-style: class 'profile::fixme' declares system::role, which should only be used in roles").on_line(6).in_column(5)
134
+ end
135
+ it 'should create errors for non-explicit class inclusion' do
136
+ expect(problems).to contain_error("wmf-style: profile 'profile::fixme' includes non-profile class apache2::common").on_line(4).in_column(13)
137
+ end
138
+ end
139
+
140
+ context 'role with errors' do
141
+ let(:code) { role_ko }
142
+ it 'should generate errors for non-profile class inclusion' do
143
+ expect(problems).to contain_error("wmf-style: role 'role::fixme' includes monitoring::host which is neither a role nor a profile")
144
+ end
145
+ end
146
+ context 'defined type with no errors' do
147
+ let(:code) { define_ok }
148
+ it 'should not detect any problems' do
149
+ expect(problems).to have(0).problems
150
+ end
151
+ end
152
+ context 'defined type with violations' do
153
+ let(:code) { define_ko }
154
+ it 'should not contain hiera calls' do
155
+ expect(problems).to contain_error("wmf-style: Found hiera call in defined type 'foo::fixme' for 'something'").on_line(1)
156
+ end
157
+ it 'should not include or define any class' do
158
+ expect(problems).to contain_error("wmf-style: defined type 'foo::fixme' declares class bar from another module").on_line(3)
159
+ end
160
+ end
161
+
162
+ context 'node with no errors' do
163
+ let(:code) { node_ok }
164
+ it 'should not detect any problems' do
165
+ expect(problems).to have(0).problems
166
+ end
167
+ end
168
+ context 'node with violations' do
169
+ let(:code) { node_ko }
170
+ it 'should not have multiple roles applied' do
171
+ expect(problems).to contain_error("wmf-style: node 'fixme' includes multiple roles").on_line(2)
172
+ end
173
+ it 'should not include classes directly' do
174
+ expect(problems).to contain_error("wmf-style: node 'fixme' includes class base::firewall")
175
+ end
176
+ it 'should not declare any defined type' do
177
+ expect(problems).to contain_error("wmf-style: node 'fixme' declares interface::mapped")
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,3 @@
1
+ require 'puppet-lint'
2
+
3
+ PuppetLint::Plugins.load_spec_helper
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-wmf_styleguide-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Giuseppe Lavagetto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: puppet-lint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: git
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-collection_matchers
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.49.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.49.1
111
+ description: |2
112
+ A puppet-lint plugin to check that the code adheres to the WMF coding guidelines:
113
+
114
+ * Check for hiera in non-profiles, and in the body of those
115
+ * Check for roles with declared resources that are not profiles
116
+ * Check for parametrized roles
117
+ * Check for node declarations not using the role keyword
118
+ * Check for system::role calls outside of roles
119
+ * Check for cross-module class inclusion
120
+ * Check for the use of the include keyword in profiles
121
+ email: lavagetto@gmail.com
122
+ executables: []
123
+ extensions: []
124
+ extra_rdoc_files: []
125
+ files:
126
+ - LICENSE
127
+ - README.md
128
+ - lib/puppet-lint/plugins/check_wmf_styleguide.rb
129
+ - spec/puppet-lint/plugins/check_wmf_styleguide_check_spec.rb
130
+ - spec/spec_helper.rb
131
+ homepage: https://github.com/wikimedia/operations-puppet-lint-wmf_styleguide-check
132
+ licenses:
133
+ - GPL-3.0
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.5.2.1
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: A puppet-lint plugin to check code adheres to the WMF coding guidelines
155
+ test_files:
156
+ - spec/spec_helper.rb
157
+ - spec/puppet-lint/plugins/check_wmf_styleguide_check_spec.rb