knife-inspect 0.8.0 → 0.9.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 (41) hide show
  1. checksums.yaml +5 -13
  2. data/.travis.yml +3 -2
  3. data/HISTORY.md +12 -0
  4. data/README.md +10 -0
  5. data/knife-inspect.gemspec +2 -2
  6. data/lib/chef/knife/cookbook_inspect.rb +4 -27
  7. data/lib/chef/knife/data_bag_inspect.rb +7 -3
  8. data/lib/chef/knife/environment_inspect.rb +4 -16
  9. data/lib/chef/knife/inspect.rb +6 -5
  10. data/lib/chef/knife/role_inspect.rb +4 -16
  11. data/lib/health_inspector.rb +11 -10
  12. data/lib/health_inspector/checklists/base.rb +30 -27
  13. data/lib/health_inspector/checklists/cookbooks.rb +44 -52
  14. data/lib/health_inspector/checklists/data_bag_items.rb +11 -12
  15. data/lib/health_inspector/checklists/data_bags.rb +5 -6
  16. data/lib/health_inspector/checklists/environments.rb +8 -9
  17. data/lib/health_inspector/checklists/roles.rb +6 -7
  18. data/lib/health_inspector/color.rb +18 -19
  19. data/lib/health_inspector/context.rb +1 -1
  20. data/lib/health_inspector/pairing.rb +27 -32
  21. data/lib/health_inspector/runner.rb +29 -0
  22. data/lib/health_inspector/version.rb +1 -1
  23. data/spec/chef-repo/data_bags/data_bag_one/one.json +4 -0
  24. data/spec/chef-repo/data_bags/data_bag_two/two.json +1 -0
  25. data/spec/chef/knife/cookbook_inspect_spec.rb +10 -0
  26. data/spec/chef/knife/data_bag_inspect_spec.rb +79 -0
  27. data/spec/chef/knife/environment_inspect_spec.rb +10 -0
  28. data/spec/chef/knife/inspect_spec.rb +51 -0
  29. data/spec/chef/knife/role_inspect_spec.rb +10 -0
  30. data/spec/health_inspector/checklists/cookbook_spec.rb +23 -21
  31. data/spec/health_inspector/checklists/cookbooks_spec.rb +14 -12
  32. data/spec/health_inspector/checklists/data_bag_item_spec.rb +3 -3
  33. data/spec/health_inspector/checklists/data_bag_items_spec.rb +96 -10
  34. data/spec/health_inspector/checklists/data_bag_spec.rb +3 -3
  35. data/spec/health_inspector/checklists/data_bags_spec.rb +28 -11
  36. data/spec/health_inspector/checklists/environment_spec.rb +6 -7
  37. data/spec/health_inspector/checklists/environments_spec.rb +9 -11
  38. data/spec/health_inspector/checklists/role_spec.rb +3 -3
  39. data/spec/health_inspector/checklists/roles_spec.rb +9 -11
  40. data/spec/spec_helper.rb +122 -56
  41. metadata +37 -26
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe HealthInspector::Checklists::Role do
4
- it_behaves_like "a chef model"
5
- it_behaves_like "a chef model that can be represented in json"
3
+ RSpec.describe HealthInspector::Checklists::Role do
4
+ it_behaves_like 'a chef model'
5
+ it_behaves_like 'a chef model that can be represented in json'
6
6
  end
@@ -1,33 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe HealthInspector::Checklists::Roles do
3
+ RSpec.describe HealthInspector::Checklists::Roles do
4
4
  let :checklist do
5
5
  described_class.new(nil)
6
6
  end
7
7
 
8
8
  before do
9
- expect(HealthInspector::Context).to receive(:new).with(nil).
10
- and_return health_inspector_context
9
+ expect(HealthInspector::Context).to receive(:new).with(nil)
10
+ .and_return health_inspector_context
11
11
  end
12
12
 
13
13
  describe '#server_items' do
14
14
  it 'returns a list of roles from the chef server' do
15
- expect(Chef::Role).to receive(:list).and_return({
15
+ expect(Chef::Role).to receive(:list).and_return(
16
16
  'role_one' => 'url',
17
17
  'role_two' => 'url',
18
18
  'role_from_subdir' => 'url'
19
- })
20
- expect(checklist.server_items.sort).to eq [
21
- 'role_from_subdir', 'role_one', 'role_two'
22
- ]
19
+ )
20
+ expect(checklist.server_items.sort)
21
+ .to eq %w(role_from_subdir role_one role_two)
23
22
  end
24
23
  end
25
24
 
26
25
  describe '#local_items' do
27
26
  it 'returns a list of roles from the chef repo' do
28
- expect(checklist.local_items.sort).to eq [
29
- 'role_from_subdir', 'role_one', 'role_two'
30
- ]
27
+ expect(checklist.local_items.sort)
28
+ .to eq %w(role_from_subdir role_one role_two)
31
29
  end
32
30
  end
33
31
  end
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,7 @@ if RUBY_VERSION > '1.9'
6
6
  Coveralls::SimpleCov::Formatter
7
7
  ]
8
8
  SimpleCov.start do
9
- add_filter "/spec/"
9
+ add_filter '/spec/'
10
10
  end
11
11
  end
12
12
 
@@ -14,118 +14,184 @@ require 'rubygems'
14
14
  require 'bundler/setup'
15
15
  require 'health_inspector'
16
16
 
17
- module HealthInspector::SpecHelpers
18
- def repo_path
19
- @repo_path ||= File.expand_path("../chef-repo", __FILE__)
20
- end
21
-
22
- def health_inspector_context
23
- @health_inspector_context ||= double(
24
- :repo_path => repo_path,
25
- :cookbook_path => ["#{repo_path}/cookbooks"]
26
- )
17
+ module HealthInspector
18
+ module SpecHelpers
19
+ def repo_path
20
+ @repo_path ||= File.expand_path('../chef-repo', __FILE__)
21
+ end
22
+
23
+ def health_inspector_context
24
+ @health_inspector_context ||= double(
25
+ :repo_path => repo_path,
26
+ :cookbook_path => ["#{repo_path}/cookbooks"]
27
+ )
28
+ end
27
29
  end
28
30
  end
29
31
 
30
32
  RSpec.configure do |c|
33
+ c.disable_monkey_patching!
34
+ c.expose_dsl_globally = false
31
35
  c.include HealthInspector::SpecHelpers
32
36
  end
33
37
 
34
- shared_examples "a chef model" do
35
- let(:pairing) { described_class.new(health_inspector_context, :name => "dummy") }
38
+ RSpec.shared_examples 'a chef model' do
39
+ let(:pairing) do
40
+ described_class.new(health_inspector_context, :name => 'dummy')
41
+ end
36
42
 
37
- it "should detect if an item does not exist locally" do
43
+ it 'detects if an item does not exist locally' do
38
44
  pairing.server = {}
39
45
  pairing.local = nil
40
46
  pairing.validate
41
47
 
42
- pairing.errors.should_not be_empty
43
- pairing.errors.first.should == "exists on server but not locally"
48
+ expect(pairing.errors).not_to be_empty
49
+ expect(pairing.errors.first).to eq('exists on server but not locally')
44
50
  end
45
51
 
46
- it "should detect if an item does not exist on server" do
52
+ it 'detects if an item does not exist on server' do
47
53
  pairing.server = nil
48
54
  pairing.local = {}
49
55
  pairing.validate
50
56
 
51
- pairing.errors.should_not be_empty
52
- pairing.errors.first.should == "exists locally but not on server"
57
+ expect(pairing.errors).not_to be_empty
58
+ expect(pairing.errors.first).to eq('exists locally but not on server')
53
59
  end
54
60
 
55
- it "should detect if an item does not exist locally or on server" do
61
+ it 'detects if an item does not exist locally or on server' do
56
62
  pairing.server = nil
57
63
  pairing.local = nil
58
64
  pairing.validate
59
65
 
60
- pairing.errors.to_a.should == ["does not exist locally or on server"]
66
+ expect(pairing.errors.to_a).to eq(['does not exist locally or on server'])
61
67
  end
62
68
  end
63
69
 
64
- shared_examples "a chef model that can be represented in json" do
65
- let(:pairing) { described_class.new(health_inspector_context, :name => "dummy") }
70
+ RSpec.shared_examples 'a chef model that can be represented in json' do
71
+ let(:pairing) do
72
+ described_class.new(health_inspector_context, :name => 'dummy')
73
+ end
66
74
 
67
- it "should detect if an item is different" do
68
- pairing.server = {"foo" => "bar"}
69
- pairing.local = {"foo" => "baz"}
75
+ it 'detects if an item is different' do
76
+ pairing.server = { 'foo' => 'bar' }
77
+ pairing.local = { 'foo' => 'baz' }
70
78
  pairing.validate
71
79
 
72
- pairing.errors.should_not be_empty
73
- pairing.errors.first.should == {"foo"=>{"server"=>"bar", "local"=>"baz"}}
80
+ expect(pairing.errors).not_to be_empty
81
+ expected_errors = { 'foo' => { 'server' => 'bar', 'local' => 'baz' } }
82
+ expect(pairing.errors.first).to eq(expected_errors)
74
83
  end
75
84
 
76
- it "should detect if an item is the same" do
77
- pairing.server = {"foo" => "bar"}
78
- pairing.local = {"foo" => "bar"}
85
+ it 'detects if a nested hash is different' do
86
+ pairing.server = { 'foo' => { 'bar' => { 'fizz' => 'buzz' } } }
87
+ pairing.local = { 'foo' => { 'baz' => { 'fizz' => 'buzz' } } }
79
88
  pairing.validate
80
89
 
81
- pairing.errors.should be_empty
90
+ expect(pairing.errors).not_to be_empty
91
+ expected_errors = {
92
+ 'foo' => {
93
+ 'bar' => { 'server' => { 'fizz' => 'buzz' }, 'local' => nil },
94
+ 'baz' => { 'server' => nil, 'local' => { 'fizz' => 'buzz' } }
95
+ }
96
+ }
97
+ expect(pairing.errors.first).to eq(expected_errors)
82
98
  end
83
99
 
84
- it "should detect if an string and symbol keys convert to the same values" do
85
- pairing.server = {"foo" => "bar"}
86
- pairing.local = {:foo => "bar"}
100
+ it 'detects if an item is the same' do
101
+ pairing.server = { 'foo' => 'bar' }
102
+ pairing.local = { 'foo' => 'bar' }
87
103
  pairing.validate
88
104
 
89
- pairing.errors.should be_empty
105
+ expect(pairing.errors).to be_empty
90
106
  end
91
107
 
92
- it "should detect if matching hashes are the same" do
93
- pairing.server = {"foo" => {"bar" => "fizz"}}
94
- pairing.local = {"foo" => {"bar" => "fizz"}}
108
+ it 'detects if an string and symbol keys convert to the same values' do
109
+ pairing.server = { 'foo' => 'bar' }
110
+ pairing.local = { :foo => 'bar' }
95
111
  pairing.validate
96
112
 
97
- pairing.errors.should be_empty
113
+ expect(pairing.errors).to be_empty
98
114
  end
99
115
 
100
- it "should detect if matching hashes with mismatched symbols and keys are the same" do
101
- pairing.server = {"foo" => {"bar" => "fizz"}}
102
- pairing.local = {:foo => {:bar => "fizz"}}
116
+ it 'detects if matching hashes are the same' do
117
+ pairing.server = { 'foo' => { 'bar' => 'fizz' } }
118
+ pairing.local = { 'foo' => { 'bar' => 'fizz' } }
103
119
  pairing.validate
104
120
 
105
- pairing.errors.should be_empty
121
+ expect(pairing.errors).to be_empty
106
122
  end
107
123
 
108
- it "should detect if matching arrays are the same" do
109
- pairing.server = {"foo" => ["bar", "fizz"]}
110
- pairing.local = {"foo" => ["bar", "fizz"]}
124
+ it 'detects if matching hashes with mismatched symbols and keys are the same' do
125
+ pairing.server = { 'foo' => { 'bar' => 'fizz' } }
126
+ pairing.local = { :foo => { :bar => 'fizz' } }
111
127
  pairing.validate
112
128
 
113
- pairing.errors.should be_empty
129
+ expect(pairing.errors).to be_empty
114
130
  end
115
131
 
116
- it "should detect if matching arrays with hashes are the same" do
117
- pairing.server = {"foo" => ["bar", {"fizz" => "buzz"}]}
118
- pairing.local = {"foo" => ["bar", {"fizz" => "buzz"}]}
132
+ it 'detects if matching arrays are the same' do
133
+ pairing.server = { 'foo' => ['bar', 'fizz'] }
134
+ pairing.local = { 'foo' => ['bar', 'fizz'] }
119
135
  pairing.validate
120
136
 
121
- pairing.errors.should be_empty
137
+ expect(pairing.errors).to be_empty
122
138
  end
123
139
 
124
- it "should detect if matching arrays with hashes containing symbols/strings are the same" do
125
- pairing.server = {"foo" => ["bar", {"fizz" => "buzz"}]}
126
- pairing.local = {"foo" => ["bar", {:fizz => "buzz"}]}
140
+ it 'detects if matching arrays with hashes are the same' do
141
+ pairing.server = { 'foo' => ['bar', { 'fizz' => 'buzz' }] }
142
+ pairing.local = { 'foo' => ['bar', { 'fizz' => 'buzz' }] }
127
143
  pairing.validate
128
144
 
129
- pairing.errors.should be_empty
145
+ expect(pairing.errors).to be_empty
146
+ end
147
+
148
+ it 'detects if matching arrays with hashes containing symbols/strings are the same' do
149
+ pairing.server = { 'foo' => ['bar', { 'fizz' => 'buzz' }] }
150
+ pairing.local = { 'foo' => ['bar', { :fizz => 'buzz' }] }
151
+ pairing.validate
152
+
153
+ expect(pairing.errors).to be_empty
154
+ end
155
+ end
156
+
157
+ RSpec.shared_examples 'a knife inspect runner' do
158
+ describe '#run' do
159
+ context 'when passing an item as an argument' do
160
+ let :inspect_runner do
161
+ described_class.new ['some_item']
162
+ end
163
+
164
+ let :validator do
165
+ double
166
+ end
167
+
168
+ let :item do
169
+ double
170
+ end
171
+
172
+ it 'inspects this item' do
173
+ expect(checklist).to receive(:new)
174
+ .with(inspect_runner).and_return validator
175
+ expect(validator).to receive(:load_item)
176
+ .with('some_item').and_return item
177
+ expect(validator).to receive(:validate_item).with(item).and_return true
178
+ expect(inspect_runner).to receive(:exit).with true
179
+
180
+ inspect_runner.run
181
+ end
182
+ end
183
+
184
+ context 'when not passing arguments' do
185
+ let :inspect_runner do
186
+ described_class.new
187
+ end
188
+
189
+ it 'inspects all the items' do
190
+ expect(checklist).to receive(:run).with(inspect_runner).and_return true
191
+ expect(inspect_runner).to receive(:exit).with true
192
+
193
+ inspect_runner.run
194
+ end
195
+ end
130
196
  end
131
197
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-inspect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Karékinian
@@ -9,98 +9,98 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-10 00:00:00.000000000 Z
12
+ date: 2014-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '10.1'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '10.1'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ~>
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '2.14'
34
+ version: 3.0.0
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ~>
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '2.14'
41
+ version: 3.0.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: simplecov
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0.8'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0.8'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: coveralls
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ~>
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0.7'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ~>
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0.7'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: chef
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ! '>='
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: '10'
77
- - - <=
77
+ - - "<="
78
78
  - !ruby/object:Gem::Version
79
79
  version: '12'
80
80
  type: :runtime
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - ! '>='
84
+ - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: '10'
87
- - - <=
87
+ - - "<="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '12'
90
90
  - !ruby/object:Gem::Dependency
91
91
  name: yajl-ruby
92
92
  requirement: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.1'
96
+ version: '1.2'
97
97
  type: :runtime
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.1'
103
+ version: '1.2'
104
104
  description: knife-inspect is a knife plugin to compare the content of your Chef repository
105
105
  and Chef server
106
106
  email:
@@ -109,9 +109,9 @@ executables: []
109
109
  extensions: []
110
110
  extra_rdoc_files: []
111
111
  files:
112
- - .coveralls.yml
113
- - .gitignore
114
- - .travis.yml
112
+ - ".coveralls.yml"
113
+ - ".gitignore"
114
+ - ".travis.yml"
115
115
  - Gemfile
116
116
  - HISTORY.md
117
117
  - MIT-LICENSE
@@ -133,6 +133,7 @@ files:
133
133
  - lib/health_inspector/color.rb
134
134
  - lib/health_inspector/context.rb
135
135
  - lib/health_inspector/pairing.rb
136
+ - lib/health_inspector/runner.rb
136
137
  - lib/health_inspector/version.rb
137
138
  - spec/chef-repo/cookbooks/cookbook_one/metadata.rb
138
139
  - spec/chef-repo/cookbooks/cookbook_two/metadata.rb
@@ -145,6 +146,11 @@ files:
145
146
  - spec/chef-repo/roles/role_one.json
146
147
  - spec/chef-repo/roles/role_two.json
147
148
  - spec/chef-repo/roles/subdir/role_from_subdir.json
149
+ - spec/chef/knife/cookbook_inspect_spec.rb
150
+ - spec/chef/knife/data_bag_inspect_spec.rb
151
+ - spec/chef/knife/environment_inspect_spec.rb
152
+ - spec/chef/knife/inspect_spec.rb
153
+ - spec/chef/knife/role_inspect_spec.rb
148
154
  - spec/health_inspector/checklists/cookbook_spec.rb
149
155
  - spec/health_inspector/checklists/cookbooks_spec.rb
150
156
  - spec/health_inspector/checklists/data_bag_item_spec.rb
@@ -166,17 +172,17 @@ require_paths:
166
172
  - lib
167
173
  required_ruby_version: !ruby/object:Gem::Requirement
168
174
  requirements:
169
- - - ! '>='
175
+ - - ">="
170
176
  - !ruby/object:Gem::Version
171
177
  version: '0'
172
178
  required_rubygems_version: !ruby/object:Gem::Requirement
173
179
  requirements:
174
- - - ! '>='
180
+ - - ">="
175
181
  - !ruby/object:Gem::Version
176
182
  version: '0'
177
183
  requirements: []
178
184
  rubyforge_project:
179
- rubygems_version: 2.2.1
185
+ rubygems_version: 2.2.2
180
186
  signing_key:
181
187
  specification_version: 4
182
188
  summary: Inspect your chef repo as it is compared to what is on your chef server
@@ -192,6 +198,11 @@ test_files:
192
198
  - spec/chef-repo/roles/role_one.json
193
199
  - spec/chef-repo/roles/role_two.json
194
200
  - spec/chef-repo/roles/subdir/role_from_subdir.json
201
+ - spec/chef/knife/cookbook_inspect_spec.rb
202
+ - spec/chef/knife/data_bag_inspect_spec.rb
203
+ - spec/chef/knife/environment_inspect_spec.rb
204
+ - spec/chef/knife/inspect_spec.rb
205
+ - spec/chef/knife/role_inspect_spec.rb
195
206
  - spec/health_inspector/checklists/cookbook_spec.rb
196
207
  - spec/health_inspector/checklists/cookbooks_spec.rb
197
208
  - spec/health_inspector/checklists/data_bag_item_spec.rb