puppet-ghostbuster 0.6.0 → 0.7.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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/lib/puppet-ghostbuster/version.rb +1 -1
  4. data/lib/puppet-lint/plugins/check_ghostbuster_facts.rb +39 -0
  5. data/lib/puppet-lint/plugins/check_ghostbuster_functions.rb +31 -0
  6. data/lib/puppet-lint/plugins/check_ghostbuster_types.rb +22 -0
  7. data/puppet-ghostbuster.gemspec +1 -0
  8. data/spec/fixtures/modules/foo/lib/facter/bar.rb +6 -0
  9. data/spec/fixtures/modules/foo/lib/facter/baz.rb +6 -0
  10. data/spec/fixtures/modules/foo/lib/facter/foo.rb +6 -0
  11. data/spec/fixtures/modules/foo/lib/facter/multi.rb +12 -0
  12. data/spec/fixtures/modules/foo/lib/puppet/parser/functions/bar.rb +4 -0
  13. data/spec/fixtures/modules/foo/lib/puppet/parser/functions/baz.rb +4 -0
  14. data/spec/fixtures/modules/foo/lib/puppet/parser/functions/foo.rb +4 -0
  15. data/spec/fixtures/modules/foo/lib/puppet/parser/functions/quux.rb +4 -0
  16. data/spec/fixtures/modules/foo/lib/puppet/type/bar.rb +2 -0
  17. data/spec/fixtures/modules/foo/lib/puppet/type/foo.rb +2 -0
  18. data/spec/fixtures/modules/foo/manifests/bar.pp +5 -0
  19. data/spec/fixtures/modules/foo/templates/foo.erb +3 -0
  20. data/spec/fixtures/nodes.json +17 -0
  21. data/spec/fixtures/resources.json +25 -0
  22. data/spec/puppet-lint/plugins/ghostbuster_classes_spec.rb +0 -6
  23. data/spec/puppet-lint/plugins/ghostbuster_defines_spec.rb +0 -6
  24. data/spec/puppet-lint/plugins/ghostbuster_facts_spec.rb +48 -0
  25. data/spec/puppet-lint/plugins/ghostbuster_files_spec.rb +1 -45
  26. data/spec/puppet-lint/plugins/ghostbuster_functions_spec.rb +44 -0
  27. data/spec/puppet-lint/plugins/ghostbuster_hiera_files_spec.rb +0 -34
  28. data/spec/puppet-lint/plugins/ghostbuster_types_spec.rb +28 -0
  29. data/spec/spec_helper.rb +16 -5
  30. metadata +34 -3
  31. data/spec/lib/puppet-ghostbuster_spec.rb +0 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff46382cda3c0d72b04acb1e62d037820262dfe0
4
- data.tar.gz: 5673735d436e8a3749df668a0a65edf2acf70eb0
3
+ metadata.gz: 0f4d56b90b0f6e22a0f28b01e5ca1bdccc3c3bcc
4
+ data.tar.gz: 75c739ec623682f6eb850ad7559126b67ef7a676
5
5
  SHA512:
6
- metadata.gz: 4c4205f32f8a76054b8a0f5f634f58d4a3510493387defcb9104e9d8b729e0e9e056931e197d66b05ce208b2cba7ae77035b3966b30d13c0b7c386948e9eb63b
7
- data.tar.gz: 0023f1fd6afc36b7fe6ce75752e0d9308e884a35a4fc9b25fc58e186c0d580039f4978e492a47cdde62b1bb1905b493dfe15eaf6bbf5661582104e24384516cb
6
+ metadata.gz: 1a49b28f9dfe55668e828d06f05f0c564718c13ffa913c28318445c17f701d861e5da4a3d2daecd94320c2702fbea8bd5affac28d9cd189e877af8ae83ebd50d
7
+ data.tar.gz: d040b8d124939e48574cabd486f625bda849216e6fd9e6bc461080fde2cfd02abb16dba06f519f9c2ed4a55d258637013f28267842b26aa9cf7e14c86c09d24b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## [0.7.0](https://rubygems.org/gems/puppet-ghostbuster/versions/0.7.0) (2016-05-16)
4
+ [Full Changelog](https://github.com/camptocamp/puppet-ghostbuster/compare/0.6.0...0.7.0)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - Detect unused facts.
9
+ - Detect unused functions.
10
+ - Detect unused types.
11
+
3
12
  ## [0.6.0](https://rubygems.org/gems/puppet-ghostbuster/versions/0.6.0) (2016-05-12)
4
13
  [Full Changelog](https://github.com/camptocamp/puppet-ghostbuster/compare/0.5.1...0.6.0)
5
14
 
@@ -1,3 +1,3 @@
1
1
  class PuppetGhostbuster
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -0,0 +1,39 @@
1
+ PuppetLint.new_check(:ghostbuster_facts) do
2
+ def manifests
3
+ Dir.glob('./**/manifests/**/*.pp')
4
+ end
5
+
6
+ def templates
7
+ Dir.glob('./**/templates/**/*').select{ |f| File.file? f }
8
+ end
9
+
10
+ def check
11
+ m = path.match(%r{.*/([^/]+)/lib/facter/(.+)$})
12
+ return if m.nil?
13
+
14
+ File.readlines(path).grep(%r{Facter.add\(["']([^"']+)["']\)}).each do |line|
15
+ fact_name = line.match(%r{Facter.add\(["']([^"']+)["']\)}).captures[0]
16
+
17
+ found = false
18
+
19
+ manifests.each do |manifest|
20
+ found = true if File.readlines(manifest).grep(%r{\$\{?::#{fact_name}\}?}).size > 0
21
+ break if found
22
+ end
23
+
24
+ templates.each do |template|
25
+ found = true if File.readlines(template).grep(%r{@#{fact_name}}).size > 0
26
+ break if found
27
+ end
28
+
29
+ unless found
30
+ notify :warning, {
31
+ :message => "Fact #{fact_name} seems unused",
32
+ :line => 1,
33
+ :column => 1,
34
+ }
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,31 @@
1
+ PuppetLint.new_check(:ghostbuster_functions) do
2
+ def manifests
3
+ Dir.glob('./**/manifests/**/*.pp')
4
+ end
5
+
6
+ def templates
7
+ Dir.glob('./**/templates/**/*').select{ |f| File.file? f }
8
+ end
9
+
10
+ def check
11
+ m = path.match(%r{.*/[^/]+/lib/puppet/parser/functions/(.+)\.rb$})
12
+ return if m.nil?
13
+
14
+ function_name = m.captures[0]
15
+
16
+ manifests.each do |manifest|
17
+ return if File.readlines(manifest).grep(%r{#{function_name}\(}).size > 0
18
+ end
19
+
20
+ templates.each do |template|
21
+ return if File.readlines(template).grep(%r{scope.function_#{function_name}\(}).size > 0
22
+ return if File.readlines(template).grep(%r{Puppet::Parser::Functions.function\(:#{function_name}}).size > 0
23
+ end
24
+
25
+ notify :warning, {
26
+ :message => "Function #{function_name} seems unused",
27
+ :line => 1,
28
+ :column => 1,
29
+ }
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ PuppetLint.new_check(:ghostbuster_types) do
2
+ def manifests
3
+ Dir.glob('./**/manifests/**/*.pp')
4
+ end
5
+
6
+ def check
7
+ m = path.match(%r{.*/[^/]+/lib/puppet/type/(.+)\.rb$})
8
+ return if m.nil?
9
+
10
+ type_name = m.captures[0]
11
+
12
+ manifests.each do |manifest|
13
+ return if File.readlines(manifest).grep(%r{^\s*#{type_name}\s*\{}).size > 0
14
+ end
15
+
16
+ notify :warning, {
17
+ :message => "Type #{type_name.capitalize} seems unused",
18
+ :line => 1,
19
+ :column => 1,
20
+ }
21
+ end
22
+ end
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency 'rspec-its', '~> 1.0'
22
22
  s.add_development_dependency 'rspec-collection_matchers', '~> 1.0'
23
23
  s.add_development_dependency 'github_changelog_generator'
24
+ s.add_development_dependency 'jgrep'
24
25
  s.add_runtime_dependency 'json'
25
26
  s.add_runtime_dependency 'puppet'
26
27
  s.add_dependency 'puppet-lint', '~> 1.0'
@@ -0,0 +1,6 @@
1
+ # Fact used in manifest
2
+ Facter.add('bar') do
3
+ setcode do
4
+ 'bar'
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # Fact used in template
2
+ Facter.add('baz') do
3
+ setcode do
4
+ 'baz'
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # Fact used in a string
2
+ Facter.add('foo') do
3
+ setcode do
4
+ 'foo'
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ # Unused facts
2
+ Facter.add('multi1') do
3
+ setcode do
4
+ 'multi1'
5
+ end
6
+ end
7
+
8
+ Facter.add('multi2') do
9
+ setcode do
10
+ 'multi2'
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module Puppet::Parser::Functions
2
+ newfunction(:bar, :type => :rvalue) do |arguments|
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Puppet::Parser::Functions
2
+ newfunction(:baz, :type => :rvalue) do |arguments|
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Puppet::Parser::Functions
2
+ newfunction(:foo, :type => :rvalue) do |arguments|
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Puppet::Parser::Functions
2
+ newfunction(:quux, :type => :rvalue) do |arguments|
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ Puppet::Type.newtype(:bar) do
2
+ end
@@ -0,0 +1,2 @@
1
+ Puppet::Type.newtype(:foo) do
2
+ end
@@ -11,4 +11,9 @@ class foo::bar {
11
11
  file { 'used_with_template_and_module_name':
12
12
  content => template("${module_name}/used_with_template_and_module_name"),
13
13
  }
14
+ if $::bar {
15
+ $foo = "Hello ${::foo}"
16
+ }
17
+ $foo = bar('baz')
18
+ bar { 'bar': }
14
19
  }
@@ -1 +1,4 @@
1
1
  <%= scope.function_template(['foo/used_in_template.erb']) -%>
2
+ <%= @baz -%>
3
+ <%= scope.function_baz() -%>
4
+ <%= Puppet::Parser::Functions.function(:quux) -%>
@@ -0,0 +1,17 @@
1
+ [
2
+ {
3
+ "certname": "bar.example.com"
4
+ },
5
+ {
6
+ "certname": "virtual.example.com",
7
+ "fact": {
8
+ "is_virtual": "true"
9
+ }
10
+ },
11
+ {
12
+ "certname": "prod.example.com",
13
+ "fact": {
14
+ "environment": "production"
15
+ }
16
+ }
17
+ ]
@@ -0,0 +1,25 @@
1
+ [
2
+ {
3
+ "type": "Foo"
4
+ },
5
+ {
6
+ "type": "Foo::Foo"
7
+ },
8
+ {
9
+ "type": "Class",
10
+ "title": "Foo"
11
+ },
12
+ {
13
+ "type": "File",
14
+ "parameter": {
15
+ "source": "puppet:///modules/foo/bar"
16
+ }
17
+ },
18
+ {
19
+ "type": "File",
20
+ "parameter": {
21
+ "source": "puppet:///modules/foo/baz",
22
+ "recurse": "true"
23
+ }
24
+ }
25
+ ]
@@ -1,16 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'ghostbuster_classes' do
4
- #let(:path) { "./manifests/site.pp" }
5
4
  let(:path) { "./modules/foo/manifests/init.pp" }
6
5
 
7
6
  context 'with fix disabled' do
8
7
 
9
- before :each do
10
- expect(PuppetGhostbuster::PuppetDB).to \
11
- receive(:classes).and_return(['Foo'])
12
- end
13
-
14
8
  context 'when class is used' do
15
9
  let(:code) { "class foo {}" }
16
10
 
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'ghostbuster_defines' do
4
- include PuppetGhostbusterSpec
5
4
 
6
5
  context 'with fix disabled' do
7
6
 
@@ -10,7 +9,6 @@ describe 'ghostbuster_defines' do
10
9
  let(:path) { "./modules/foo/manifests/init.pp" }
11
10
 
12
11
  it 'should not detect any problem' do
13
- expect_puppetdb_resources([:'=', 'type', 'Foo'], [{}])
14
12
  expect(problems).to have(0).problems
15
13
  end
16
14
  end
@@ -19,10 +17,6 @@ describe 'ghostbuster_defines' do
19
17
  let(:code) { "define bar {}" }
20
18
  let(:path) { "./modules/bar/manifests/init.pp" }
21
19
 
22
- before :each do
23
- expect_puppetdb_resources([:'=', 'type', 'Bar'], [])
24
- end
25
-
26
20
  it 'should detect one problem' do
27
21
  expect(problems).to have(1).problems
28
22
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ghostbuster_facts' do
4
+ let(:code) { "Facter.add('foo')" }
5
+
6
+ context 'with fix disabled' do
7
+
8
+ context 'when fact is not used' do
9
+ let(:path) { "./spec/fixtures/modules/foo/lib/facter/multi.rb" }
10
+
11
+ it 'should detect one problem' do
12
+ expect(problems).to have(2).problems
13
+ end
14
+
15
+ it 'should create a warning' do
16
+ expect(problems).to contain_warning("Fact multi1 seems unused")
17
+ end
18
+
19
+ it 'should create a warning' do
20
+ expect(problems).to contain_warning("Fact multi2 seems unused")
21
+ end
22
+ end
23
+
24
+ context 'when fact is used in a string' do
25
+ let(:path) { "./spec/fixtures/modules/foo/lib/facter/foo.rb" }
26
+
27
+ it 'should not detect any problem' do
28
+ expect(problems).to have(0).problems
29
+ end
30
+ end
31
+
32
+ context 'when fact is used in manifest' do
33
+ let(:path) { "./spec/fixtures/modules/foo/lib/facter/bar.rb" }
34
+
35
+ it 'should not detect any problem' do
36
+ expect(problems).to have(0).problems
37
+ end
38
+ end
39
+
40
+ context 'when fact is used in a template' do
41
+ let(:path) { "./spec/fixtures/modules/foo/lib/facter/baz.rb" }
42
+
43
+ it 'should not detect any problem' do
44
+ expect(problems).to have(0).problems
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'ghostbuster_files' do
4
- include PuppetGhostbusterSpec
5
4
 
6
5
  let(:code) { "" }
7
6
 
@@ -11,30 +10,14 @@ describe 'ghostbuster_files' do
11
10
  let(:path) { "./modules/foo/files/bar" }
12
11
 
13
12
  it 'should not detect any problem' do
14
- expect_puppetdb_resources(
15
- [:'=', ['parameter', 'source'], "puppet:///modules/foo/bar"],
16
- [{}]
17
- )
18
13
  expect(problems).to have(0).problems
19
14
  end
20
15
  end
21
16
 
22
17
  context 'when parent directory with recurse => true usage is found in puppetdb' do
23
- let(:path) { "./modules/foo/files/bar/baz" }
18
+ let(:path) { "./modules/foo/files/baz/baz" }
24
19
 
25
20
  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
21
  expect(problems).to have(0).problems
39
22
  end
40
23
  end
@@ -43,9 +26,6 @@ describe 'ghostbuster_files' do
43
26
  let(:path) { "./modules/foo/files/used_with_file" }
44
27
 
45
28
  it 'should not detect any problem' do
46
- expect_puppetdb_resources(
47
- [:'=', ['parameter', 'source'], "puppet:///modules/foo/used_with_file"],
48
- [])
49
29
  expect(problems).to have(0).problems
50
30
  end
51
31
  end
@@ -54,9 +34,6 @@ describe 'ghostbuster_files' do
54
34
  let(:path) { "./modules/foo/files/used_with_file_and_module_name" }
55
35
 
56
36
  it 'should not detect any problem' do
57
- expect_puppetdb_resources(
58
- [:'=', ['parameter', 'source'], "puppet:///modules/foo/used_with_file_and_module_name"],
59
- [])
60
37
  expect(problems).to have(0).problems
61
38
  end
62
39
  end
@@ -64,12 +41,6 @@ describe 'ghostbuster_files' do
64
41
  context 'when file in ROOT is not used' do
65
42
  let(:path) { "./modules/bar/files/foo" }
66
43
 
67
- before :each do
68
- expect_puppetdb_resources(
69
- [:'=', ['parameter', 'source'], "puppet:///modules/bar/foo"],
70
- [])
71
- end
72
-
73
44
  it 'should detect one problem' do
74
45
  expect(problems).to have(1).problems
75
46
  end
@@ -82,21 +53,6 @@ describe 'ghostbuster_files' do
82
53
  context 'when file in subdir is not used' do
83
54
  let(:path) { "./modules/bar/files/foo/bar" }
84
55
 
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
- [])
98
- end
99
-
100
56
  it 'should detect one problem' do
101
57
  expect(problems).to have(1).problems
102
58
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ghostbuster_functions' do
4
+ let(:code) { '' }
5
+
6
+ context 'with fix disabled' do
7
+
8
+ context 'when function is not used' do
9
+ let(:path) { "./spec/fixtures/modules/foo/lib/puppet/parser/functions/foo.rb" }
10
+
11
+ it 'should detect one problem' do
12
+ expect(problems).to have(1).problems
13
+ end
14
+
15
+ it 'should create a warning' do
16
+ expect(problems).to contain_warning("Function foo seems unused")
17
+ end
18
+ end
19
+
20
+ context 'when function is used in a manifest' do
21
+ let(:path) { "./spec/fixtures/modules/foo/lib/puppet/parser/functions/bar.rb" }
22
+
23
+ it 'should not detect any problem' do
24
+ expect(problems).to have(0).problems
25
+ end
26
+ end
27
+
28
+ context 'when function is used in a template using scope.function_baz()' do
29
+ let(:path) { "./spec/fixtures/modules/foo/lib/puppet/parser/functions/baz.rb" }
30
+
31
+ it 'should not detect any problem' do
32
+ expect(problems).to have(0).problems
33
+ end
34
+ end
35
+
36
+ context 'when function is used in a template using Puppet::Parser::Functions.function(:quux)' do
37
+ let(:path) { "./spec/fixtures/modules/foo/lib/puppet/parser/functions/quux.rb" }
38
+
39
+ it 'should not detect any problem' do
40
+ expect(problems).to have(0).problems
41
+ end
42
+ end
43
+ end
44
+ end
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  ENV['HIERA_YAML_PATH'] = './spec/fixtures/hiera.yaml'
4
4
 
5
5
  describe 'ghostbuster_hiera_files' do
6
- include PuppetGhostbusterSpec
7
6
 
8
7
  let(:code) { "" }
9
8
 
@@ -12,13 +11,6 @@ describe 'ghostbuster_hiera_files' do
12
11
  context 'when a certname file is NOT used' do
13
12
  let(:path) { "./hieradata/nodes/foo.example.com.yaml" }
14
13
 
15
- before :each do
16
- expect_puppetdb_nodes(
17
- [:'=', 'certname', 'foo.example.com'],
18
- []
19
- )
20
- end
21
-
22
14
  it 'should detect one problem' do
23
15
  expect(problems).to have(1).problems
24
16
  end
@@ -32,10 +24,6 @@ describe 'ghostbuster_hiera_files' do
32
24
  let(:path) { "./hieradata/nodes/bar.example.com.yaml" }
33
25
 
34
26
  it 'should not detect any problem' do
35
- expect_puppetdb_nodes(
36
- [:'=', 'certname', 'bar.example.com'],
37
- [{}]
38
- )
39
27
  expect(problems).to have(0).problems
40
28
  end
41
29
  end
@@ -43,13 +31,6 @@ describe 'ghostbuster_hiera_files' do
43
31
  context 'when an environment file is NOT used' do
44
32
  let(:path) { "./hieradata/environment/foo.yaml" }
45
33
 
46
- before :each do
47
- expect_puppetdb_nodes(
48
- [:'=', ['fact', 'environment'], 'foo'],
49
- []
50
- )
51
- end
52
-
53
34
  it 'should detect one problem' do
54
35
  expect(problems).to have(1).problems
55
36
  end
@@ -63,10 +44,6 @@ describe 'ghostbuster_hiera_files' do
63
44
  let(:path) { "./hieradata/environment/production.yaml" }
64
45
 
65
46
  it 'should not detect any problem' do
66
- expect_puppetdb_nodes(
67
- [:'=', ['fact', 'environment'], 'production'],
68
- [{}]
69
- )
70
47
  expect(problems).to have(0).problems
71
48
  end
72
49
  end
@@ -74,13 +51,6 @@ describe 'ghostbuster_hiera_files' do
74
51
  context 'when an fact is NOT used' do
75
52
  let(:path) { "./hieradata/virtual/false.yaml" }
76
53
 
77
- before :each do
78
- expect_puppetdb_nodes(
79
- [:'=', ['fact', 'is_virtual'], 'false'],
80
- []
81
- )
82
- end
83
-
84
54
  it 'should detect one problem' do
85
55
  expect(problems).to have(1).problems
86
56
  end
@@ -94,10 +64,6 @@ describe 'ghostbuster_hiera_files' do
94
64
  let(:path) { "./hieradata/virtual/true.yaml" }
95
65
 
96
66
  it 'should not detect any problem' do
97
- expect_puppetdb_nodes(
98
- [:'=', ['fact', 'is_virtual'], 'true'],
99
- [{}]
100
- )
101
67
  expect(problems).to have(0).problems
102
68
  end
103
69
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ghostbuster_types' do
4
+ let(:code) { '' }
5
+
6
+ context 'with fix disabled' do
7
+
8
+ context 'when type is not used' do
9
+ let(:path) { "./spec/fixtures/modules/foo/lib/puppet/type/foo.rb" }
10
+
11
+ it 'should detect one problem' do
12
+ expect(problems).to have(1).problems
13
+ end
14
+
15
+ it 'should create a warning' do
16
+ expect(problems).to contain_warning("Type Foo seems unused")
17
+ end
18
+ end
19
+
20
+ context 'when type is used in a manifest' do
21
+ let(:path) { "./spec/fixtures/modules/foo/lib/puppet/type/bar.rb" }
22
+
23
+ it 'should not detect any problem' do
24
+ expect(problems).to have(0).problems
25
+ end
26
+ end
27
+ end
28
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,20 @@
1
1
  require 'puppet-lint'
2
+ require 'jgrep'
2
3
 
3
- require 'pathname'
4
- dir = Pathname.new(__FILE__).parent
5
- $LOAD_PATH.unshift(dir, File.join(dir, 'lib'), File.join(dir, '..', 'lib'))
4
+ PuppetLint::Plugins.load_spec_helper
6
5
 
7
- require 'puppet-ghostbuster_spec'
6
+ class PuppetDB::Client
7
+ def puppetdb_to_jgrep(query)
8
+ if query[0] == :'and' || query[0] == :'or'
9
+ "(#{puppetdb_to_jgrep(query[1])} #{query[0]} #{puppetdb_to_jgrep(query[2])})"
10
+ else
11
+ "#{[query[1]].flatten.join('.')}#{query[0]}#{query[2]}"
12
+ end
13
+ end
14
+
15
+ def request(endpoint, query, opts={})
16
+ ret = JGrep.jgrep(File.read("spec/fixtures/#{endpoint}.json"), puppetdb_to_jgrep(query))
17
+ PuppetDB::Response.new(ret, ret.size)
18
+ end
19
+ end
8
20
 
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.6.0
4
+ version: 0.7.0
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-12 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jgrep
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: json
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -167,19 +181,36 @@ files:
167
181
  - lib/puppet-ghostbuster/version.rb
168
182
  - lib/puppet-lint/plugins/check_ghostbuster_classes.rb
169
183
  - lib/puppet-lint/plugins/check_ghostbuster_defines.rb
184
+ - lib/puppet-lint/plugins/check_ghostbuster_facts.rb
170
185
  - lib/puppet-lint/plugins/check_ghostbuster_files.rb
186
+ - lib/puppet-lint/plugins/check_ghostbuster_functions.rb
171
187
  - lib/puppet-lint/plugins/check_ghostbuster_hiera_files.rb
172
188
  - lib/puppet-lint/plugins/check_ghostbuster_templates.rb
189
+ - lib/puppet-lint/plugins/check_ghostbuster_types.rb
173
190
  - puppet-ghostbuster.gemspec
174
191
  - spec/fixtures/hiera.yaml
192
+ - spec/fixtures/modules/foo/lib/facter/bar.rb
193
+ - spec/fixtures/modules/foo/lib/facter/baz.rb
194
+ - spec/fixtures/modules/foo/lib/facter/foo.rb
195
+ - spec/fixtures/modules/foo/lib/facter/multi.rb
196
+ - spec/fixtures/modules/foo/lib/puppet/parser/functions/bar.rb
197
+ - spec/fixtures/modules/foo/lib/puppet/parser/functions/baz.rb
198
+ - spec/fixtures/modules/foo/lib/puppet/parser/functions/foo.rb
199
+ - spec/fixtures/modules/foo/lib/puppet/parser/functions/quux.rb
200
+ - spec/fixtures/modules/foo/lib/puppet/type/bar.rb
201
+ - spec/fixtures/modules/foo/lib/puppet/type/foo.rb
175
202
  - spec/fixtures/modules/foo/manifests/bar.pp
176
203
  - spec/fixtures/modules/foo/templates/foo.erb
177
- - spec/lib/puppet-ghostbuster_spec.rb
204
+ - spec/fixtures/nodes.json
205
+ - spec/fixtures/resources.json
178
206
  - spec/puppet-lint/plugins/ghostbuster_classes_spec.rb
179
207
  - spec/puppet-lint/plugins/ghostbuster_defines_spec.rb
208
+ - spec/puppet-lint/plugins/ghostbuster_facts_spec.rb
180
209
  - spec/puppet-lint/plugins/ghostbuster_files_spec.rb
210
+ - spec/puppet-lint/plugins/ghostbuster_functions_spec.rb
181
211
  - spec/puppet-lint/plugins/ghostbuster_hiera_files_spec.rb
182
212
  - spec/puppet-lint/plugins/ghostbuster_templates_spec.rb
213
+ - spec/puppet-lint/plugins/ghostbuster_types_spec.rb
183
214
  - spec/spec_helper.rb
184
215
  homepage: http://github.com/camptocamp/puppet-ghostbuster
185
216
  licenses:
@@ -1,23 +0,0 @@
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_nodes(request, data)
13
- expect_any_instance_of(PuppetDB::Client).to \
14
- receive(:request).with('nodes', request)
15
- .and_return(PuppetDBRequest.new(data))
16
- end
17
-
18
- def expect_puppetdb_resources(request, data)
19
- expect_any_instance_of(PuppetDB::Client).to \
20
- receive(:request).with('resources', request)
21
- .and_return(PuppetDBRequest.new(data))
22
- end
23
- end