puppet-ghostbuster 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54bed6f908a3bb9aaae26087248857c8390028b7
4
- data.tar.gz: 3904dae59b8117dfd6233afaf73688ed232c2e6b
3
+ metadata.gz: edacfbf4e6b6535eb54b8ca8ebadf3a52fda9541
4
+ data.tar.gz: 5fc919c331dfe03a3f6e9ce715eae083220be1fa
5
5
  SHA512:
6
- metadata.gz: 0b6a6044ce239fd2aef83b436994b5bff3bb85f5214c3e5537317fa853414c090b517d7e4eea2853df38acab5d5ca1fa6a881366f8817f8f9ff20dd4a9a2b394
7
- data.tar.gz: 68abfdd84fd16af1b06a32c06b6173b90b9b50bf4024d26eb4aca4026d27cf5b75b17ed5bb1ca26b588a5896466678f3067a303eb94620f038dce084f68e4887
6
+ metadata.gz: f432b78f191bcb16104160ef44dca6699da36556ded601664ec4df1acf16737ac287ff46a7ea48bf9c5f377299ce39752809556f6c83341e79163659b4596d59
7
+ data.tar.gz: a98974b7f24d5b42ab99b03e84b7c92701c80d116916bca7eab4afbfe6182c309d165485dc09afde1fe64ef9bcba8c75df7d4c4140ae3cf1e678c022588667a4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## [0.5.1](https://rubygems.org/gems/puppet-ghostbuster/versions/0.5.1) (2016-05-11)
4
+ [Full Changelog](https://github.com/camptocamp/puppet-ghostbuster/compare/0.5.0...0.5.1)
5
+
6
+ **Fixed bugs:**
7
+
8
+ - Detect templates included in templates
9
+
3
10
  ## [0.5.0](https://rubygems.org/gems/puppet-ghostbuster/versions/0.5.0) (2016-05-10)
4
11
  [Full Changelog](https://github.com/camptocamp/puppet-ghostbuster/compare/0.4.5...0.5.0)
5
12
 
@@ -1,3 +1,3 @@
1
1
  class PuppetGhostbuster
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -17,6 +17,10 @@ PuppetLint.new_check(:ghostbuster_templates) do
17
17
  Dir.glob('./**/manifests/**/*.pp')
18
18
  end
19
19
 
20
+ def templates
21
+ Dir.glob('./**/templates/**/*').select{ |f| File.file? f }
22
+ end
23
+
20
24
  def check
21
25
  m = path.match(%r{.*/([^/]+)/templates/(.+)$})
22
26
  return if m.nil?
@@ -32,6 +36,10 @@ PuppetLint.new_check(:ghostbuster_templates) do
32
36
  end
33
37
  end
34
38
 
39
+ templates.each do |template|
40
+ return if File.readlines(template).grep(%r{scope.function_template\(\['#{module_name}/#{template_name}'\]\)}).size > 0
41
+ end
42
+
35
43
  notify :warning, {
36
44
  :message => "Template #{module_name}/#{template_name} seems unused",
37
45
  :line => 1,
@@ -0,0 +1,14 @@
1
+ class foo::bar {
2
+ file { 'used_with_file':
3
+ content => file('foo/used_with_file'),
4
+ }
5
+ file { 'used_with_file_and_module_name':
6
+ content => file("${module_name}/used_with_file_and_module_name"),
7
+ }
8
+ file { 'used_with_template':
9
+ content => template('foo/used_with_template'),
10
+ }
11
+ file { 'used_with_template_and_module_name':
12
+ content => template("${module_name}/used_with_template_and_module_name"),
13
+ }
14
+ }
@@ -0,0 +1 @@
1
+ <%= scope.function_template(['foo/used_in_template.erb']) -%>
@@ -0,0 +1,17 @@
1
+ module PuppetGhostbusterSpec
2
+ class PuppetDBRequest
3
+ def initialize(data)
4
+ @data = data
5
+ end
6
+
7
+ def data
8
+ @data
9
+ end
10
+ end
11
+
12
+ def expect_puppetdb_resources(request, data)
13
+ expect_any_instance_of(PuppetDB::Client).to \
14
+ receive(:request).with('resources', request)
15
+ .and_return(PuppetDBRequest.new(data))
16
+ end
17
+ end
@@ -1,15 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- class PuppetDBRequest
4
- def initialize(data)
5
- @data = data
6
- end
7
-
8
- def data
9
- @data
10
- end
11
- end
12
-
13
3
  describe 'ghostbuster_classes' do
14
4
  #let(:path) { "./manifests/site.pp" }
15
5
  let(:path) { "./modules/foo/manifests/init.pp" }
@@ -1,46 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
- class PuppetDBRequest
4
- def initialize(data)
5
- @data = data
6
- end
7
-
8
- def data
9
- @data
10
- end
11
- end
12
-
13
3
  describe 'ghostbuster_defines' do
14
- let(:path) { "./modules/foo/manifests/init.pp" }
4
+ include PuppetGhostbusterSpec
15
5
 
16
6
  context 'with fix disabled' do
17
7
 
18
8
  context 'when define is used' do
19
9
  let(:code) { "define foo {}" }
20
-
21
- before :each do
22
- expect_any_instance_of(PuppetDB::Client).to \
23
- receive(:request).with('resources', [:'=', 'type', 'Foo'])
24
- .and_return(PuppetDBRequest.new([
25
- {
26
- 'type' => 'Foo',
27
- 'title' => 'bar',
28
- },
29
- ]))
30
- end
10
+ let(:path) { "./modules/foo/manifests/init.pp" }
31
11
 
32
12
  it 'should not detect any problem' do
13
+ expect_puppetdb_resources([:'=', 'type', 'Foo'], [{}])
33
14
  expect(problems).to have(0).problems
34
15
  end
35
16
  end
36
17
 
37
18
  context 'when define is not used' do
38
- let(:code) { "define foo {}" }
19
+ let(:code) { "define bar {}" }
20
+ let(:path) { "./modules/bar/manifests/init.pp" }
39
21
 
40
22
  before :each do
41
- expect_any_instance_of(PuppetDB::Client).to \
42
- receive(:request).with('resources', [:'=', 'type', 'Foo'])
43
- .and_return(PuppetDBRequest.new([]))
23
+ expect_puppetdb_resources([:'=', 'type', 'Bar'], [])
44
24
  end
45
25
 
46
26
  it 'should detect one problem' do
@@ -48,7 +28,7 @@ describe 'ghostbuster_defines' do
48
28
  end
49
29
 
50
30
  it 'should create a warning' do
51
- expect(problems).to contain_warning('Define Foo seems unused')
31
+ expect(problems).to contain_warning('Define Bar seems unused')
52
32
  end
53
33
  end
54
34
  end
@@ -1,109 +1,108 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'ghostbuster_files' do
4
- let(:path) { "./modules/foo/files/bar/baz" }
4
+ include PuppetGhostbusterSpec
5
+
5
6
  let(:code) { "" }
6
7
 
7
8
  context 'with fix disabled' do
8
9
 
9
10
  context 'when file usage is found in puppetdb' do
11
+ let(:path) { "./modules/foo/files/bar" }
10
12
 
11
- before :each do
12
- expect_any_instance_of(PuppetDB::Client).to\
13
- receive(:request).with(
14
- 'resources',
15
- [:'=', ['parameter', 'source'], "puppet:///modules/foo/bar/baz"],
13
+ it 'should not detect any problem' do
14
+ expect_puppetdb_resources(
15
+ [:'=', ['parameter', 'source'], "puppet:///modules/foo/bar"],
16
+ [{}]
16
17
  )
17
- .and_return(PuppetDBRequest.new([{}]))
18
+ expect(problems).to have(0).problems
19
+ end
20
+ end
21
+
22
+ context 'when parent directory with recurse => true usage is found in puppetdb' do
23
+ let(:path) { "./modules/foo/files/bar/baz" }
24
+
25
+ it 'should not detect any problem' do
26
+ expect_puppetdb_resources(
27
+ [:'=', ['parameter', 'source'], "puppet:///modules/foo/bar/baz"],
28
+ [])
29
+ expect_puppetdb_resources(
30
+ [:'and',
31
+ [:'or',
32
+ [:'=', ['parameter', 'source'], "puppet:///modules/foo/bar"],
33
+ [:'=', ['parameter', 'source'], "puppet:///modules/foo/bar/"],
34
+ ],
35
+ [:'=', ['parameter', 'recurse'], true],
36
+ ],
37
+ [{}])
38
+ expect(problems).to have(0).problems
39
+ end
40
+ end
41
+
42
+ context 'when using full module name syntax' do
43
+ let(:path) { "./modules/foo/files/used_with_file" }
44
+
45
+ it 'should not detect any problem' do
46
+ expect_puppetdb_resources(
47
+ [:'=', ['parameter', 'source'], "puppet:///modules/foo/used_with_file"],
48
+ [])
49
+ expect(problems).to have(0).problems
18
50
  end
51
+ end
52
+
53
+ context 'when using $module_name syntax' do
54
+ let(:path) { "./modules/foo/files/used_with_file_and_module_name" }
19
55
 
20
56
  it 'should not detect any problem' do
57
+ expect_puppetdb_resources(
58
+ [:'=', ['parameter', 'source'], "puppet:///modules/foo/used_with_file_and_module_name"],
59
+ [])
21
60
  expect(problems).to have(0).problems
22
61
  end
23
62
  end
24
63
 
25
- context 'when file usage is not found in puppetdb' do
64
+ context 'when file in ROOT is not used' do
65
+ let(:path) { "./modules/bar/files/foo" }
26
66
 
27
67
  before :each do
28
- expect_any_instance_of(PuppetDB::Client).to\
29
- receive(:request).with(
30
- 'resources',
31
- [:'=', ['parameter', 'source'], "puppet:///modules/foo/bar/baz"],
32
- )
33
- .and_return(PuppetDBRequest.new([]))
68
+ expect_puppetdb_resources(
69
+ [:'=', ['parameter', 'source'], "puppet:///modules/bar/foo"],
70
+ [])
71
+ end
72
+
73
+ it 'should detect one problem' do
74
+ expect(problems).to have(1).problems
75
+ end
76
+
77
+ it 'should create a warning' do
78
+ expect(problems).to contain_warning("File bar/foo seems unused")
79
+ end
80
+ end
81
+
82
+ context 'when file in subdir is not used' do
83
+ let(:path) { "./modules/bar/files/foo/bar" }
84
+
85
+ before :each do
86
+ expect_puppetdb_resources(
87
+ [:'=', ['parameter', 'source'], "puppet:///modules/bar/foo/bar"],
88
+ [])
89
+ expect_puppetdb_resources(
90
+ [:'and',
91
+ [:'or',
92
+ [:'=', ['parameter', 'source'], "puppet:///modules/bar/foo"],
93
+ [:'=', ['parameter', 'source'], "puppet:///modules/bar/foo/"],
94
+ ],
95
+ [:'=', ['parameter', 'recurse'], true],
96
+ ],
97
+ [])
34
98
  end
35
99
 
36
- context 'when parent directory with recurse => true usage is found in puppetdb' do
37
- before :each do
38
- expect_any_instance_of(PuppetDB::Client).to \
39
- receive(:request).with(
40
- 'resources',
41
- [:'and',
42
- [:'or',
43
- [:'=', ['parameter', 'source'], "puppet:///modules/foo/bar"],
44
- [:'=', ['parameter', 'source'], "puppet:///modules/foo/bar/"],
45
- ],
46
- [:'=', ['parameter', 'recurse'], true],
47
- ],
48
- )
49
- .and_return(PuppetDBRequest.new([
50
- {
51
- },
52
- ]))
53
- end
54
-
55
- it 'should not detect any problem' do
56
- expect(problems).to have(0).problems
57
- end
100
+ it 'should detect one problem' do
101
+ expect(problems).to have(1).problems
58
102
  end
59
103
 
60
- context 'when parent directory usage is not found in puppetdb' do
61
- before :each do
62
- expect_any_instance_of(PuppetDB::Client).to \
63
- receive(:request).with(
64
- 'resources',
65
- [:'and',
66
- [:'or',
67
- [:'=', ['parameter', 'source'], "puppet:///modules/foo/bar"],
68
- [:'=', ['parameter', 'source'], "puppet:///modules/foo/bar/"],
69
- ],
70
- [:'=', ['parameter', 'recurse'], true],
71
- ],
72
- )
73
- .and_return(PuppetDBRequest.new([]))
74
- end
75
-
76
- context 'when file usage is found in manifests' do
77
-
78
- before :each do
79
- expect(Dir).to receive(:glob){["./modules/foo/manifests/bar.pp" ]}
80
- end
81
-
82
- context 'when using full module name syntax' do
83
- it 'should not detect any problem' do
84
- expect(File).to receive(:readlines).with("./modules/foo/manifests/bar.pp").and_return(["file{'foo':", " content => file('foo/bar/baz'),", " }"])
85
- expect(problems).to have(0).problems
86
- end
87
- end
88
-
89
- context 'when using $module_name syntax' do
90
- it 'should not detect any problem' do
91
- expect(File).to receive(:readlines).with("./modules/foo/manifests/bar.pp").and_return(["file{'foo':", " content => file('bar/foo'),", " }"])
92
- expect(File).to receive(:readlines).with("./modules/foo/manifests/bar.pp").and_return(["file{'foo':", ' content => file("${module_name}/bar/baz"),', " }"])
93
- expect(problems).to have(0).problems
94
- end
95
- end
96
- end
97
-
98
- context 'when file usage is not found in manifests' do
99
- it 'should detect one problem' do
100
- expect(problems).to have(1).problems
101
- end
102
-
103
- it 'should create a warning' do
104
- expect(problems).to contain_warning("File foo/bar/baz seems unused")
105
- end
106
- end
104
+ it 'should create a warning' do
105
+ expect(problems).to contain_warning("File bar/foo/bar seems unused")
107
106
  end
108
107
  end
109
108
  end
@@ -1,40 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'ghostbuster_templates' do
4
- let(:path) { "./modules/foo/templates/bar" }
5
4
  let(:code) { "" }
6
5
 
7
6
  context 'with fix disabled' do
8
7
 
9
- context 'when template usage is found in manifests' do
8
+ context 'when using full module name syntax' do
9
+ let(:path) { "./modules/foo/templates/used_with_template" }
10
10
 
11
- before :each do
12
- expect(Dir).to receive(:glob){["./modules/foo/manifests/bar.pp" ]}
11
+ it 'should not detect any problem' do
12
+ expect(problems).to have(0).problems
13
13
  end
14
+ end
15
+
16
+ context 'when using $module_name syntax' do
17
+ let(:path) { "./modules/foo/templates/used_with_template_and_module_name" }
14
18
 
15
- context 'when using full module name syntax' do
16
- it 'should not detect any problem' do
17
- expect(File).to receive(:readlines).with("./modules/foo/manifests/bar.pp").and_return(["file{'foo':", " content => template('foo/bar'),", " }"])
18
- expect(problems).to have(0).problems
19
- end
19
+ it 'should not detect any problem' do
20
+ expect(problems).to have(0).problems
20
21
  end
22
+ end
21
23
 
22
- context 'when using $module_name syntax' do
23
- it 'should not detect any problem' do
24
- expect(File).to receive(:readlines).with("./modules/foo/manifests/bar.pp").and_return(["file{'foo':", " content => template('bar/foo'),", " }"])
25
- expect(File).to receive(:readlines).with("./modules/foo/manifests/bar.pp").and_return(["file{'foo':", ' content => template("${module_name}/bar"),', " }"])
26
- expect(problems).to have(0).problems
27
- end
24
+ context 'when using template in template' do
25
+ let(:path) { "./modules/foo/templates/used_in_template.erb" }
26
+
27
+ it 'should not detect any problem' do
28
+ expect(problems).to have(0).problems
28
29
  end
29
30
  end
30
31
 
31
32
  context 'when template usage is not found in manifests' do
33
+ let(:path) { "./modules/foo/templates/unused" }
34
+
32
35
  it 'should detect one problem' do
33
36
  expect(problems).to have(1).problems
34
37
  end
35
38
 
36
39
  it 'should create a warning' do
37
- expect(problems).to contain_warning("Template foo/bar seems unused")
40
+ expect(problems).to contain_warning("Template foo/unused seems unused")
38
41
  end
39
42
  end
40
43
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,9 @@
1
1
  require 'puppet-lint'
2
2
 
3
+ require 'pathname'
4
+ dir = Pathname.new(__FILE__).parent
5
+ $LOAD_PATH.unshift(dir, File.join(dir, 'lib'), File.join(dir, '..', 'lib'))
6
+
7
+ require 'puppet-ghostbuster_spec'
8
+
3
9
  PuppetLint::Plugins.load_spec_helper
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-ghostbuster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camptocamp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-10 00:00:00.000000000 Z
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -170,6 +170,9 @@ files:
170
170
  - lib/puppet-lint/plugins/check_ghostbuster_files.rb
171
171
  - lib/puppet-lint/plugins/check_ghostbuster_templates.rb
172
172
  - puppet-ghostbuster.gemspec
173
+ - spec/fixtures/modules/foo/manifests/bar.pp
174
+ - spec/fixtures/modules/foo/templates/foo.erb
175
+ - spec/lib/puppet-ghostbuster_spec.rb
173
176
  - spec/puppet-lint/plugins/ghostbuster_classes_spec.rb
174
177
  - spec/puppet-lint/plugins/ghostbuster_defines_spec.rb
175
178
  - spec/puppet-lint/plugins/ghostbuster_files_spec.rb