health_inspector 0.4.1 → 0.5.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.
data/HISTORY.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.5.0 ( 2012-10-14 )
2
+
3
+ * Switch to RSpec
4
+ * Add some test coverage (still needs much more)
5
+ * Add option to suppress terminal output on successful checks
6
+ * Add option to not use ansi color output
7
+ * Make cookbook version comparison use Chef's native version class
8
+
1
9
  ## 0.4.1 ( 2012-09-28 )
2
10
 
3
11
  * Fix a bug I created in last release when passing no component.
data/Rakefile CHANGED
@@ -1,10 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
- require 'rake/testtask'
2
+ require "rspec/core/rake_task"
3
3
 
4
- Rake::TestTask.new(:test) do |test|
5
- test.libs << 'lib' << 'spec'
6
- test.pattern = 'spec/**/*_spec.rb'
7
- test.verbose = true
4
+ RSpec::Core::RakeTask.new do |t|
5
+ t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
6
+ t.pattern = 'spec/**/*_spec.rb'
8
7
  end
9
8
 
10
- task :default => :test
9
+ task :default => :spec
@@ -18,8 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_development_dependency "minitest"
22
- s.add_development_dependency "mocha"
21
+ s.add_development_dependency "rspec"
23
22
 
24
23
  s.add_runtime_dependency "thor"
25
24
  s.add_runtime_dependency "chef", "~> 10.14"
@@ -13,7 +13,7 @@ require "health_inspector/checklists/roles"
13
13
  require "health_inspector/cli"
14
14
  require 'chef/rest'
15
15
  require 'chef/checksum_cache'
16
- require "json"
16
+ require 'chef/version'
17
17
 
18
18
  module HealthInspector
19
19
  end
@@ -27,6 +27,14 @@ module HealthInspector
27
27
  @context = context
28
28
  end
29
29
 
30
+ # Subclasses should collect all items from the server and the local repo,
31
+ # and for each item pair, yield an object that contains a reference to
32
+ # the server item, and the local repo item. A reference can be nil if it does
33
+ # not exist in one of the locations.
34
+ def each_item
35
+ raise NotImplementedError, "You must implement this method in a subclass"
36
+ end
37
+
30
38
  def run
31
39
  banner "Inspecting #{self.class.title}"
32
40
 
@@ -34,7 +42,7 @@ module HealthInspector
34
42
  failures = run_checks(item)
35
43
 
36
44
  if failures.empty?
37
- print_success(item.name)
45
+ print_success(item.name) unless @context.quiet_success
38
46
  else
39
47
  print_failures(item.name, failures)
40
48
  end
@@ -75,6 +83,7 @@ module HealthInspector
75
83
  memo
76
84
  end
77
85
  end
86
+
78
87
  end
79
88
 
80
89
  def chef_rest
@@ -4,11 +4,11 @@ module HealthInspector
4
4
  class Cookbooks < Base
5
5
 
6
6
  add_check "local copy exists" do
7
- failure( "exists on chef server but not locally" ) if item.path.nil?
7
+ failure( "exists on server but not locally" ) if item.path.nil?
8
8
  end
9
9
 
10
10
  add_check "server copy exists" do
11
- failure( "exists locally but not on chef server" ) if item.server_version.nil?
11
+ failure( "exists locally but not on server" ) if item.server_version.nil?
12
12
  end
13
13
 
14
14
  add_check "versions" do
@@ -65,7 +65,7 @@ module HealthInspector
65
65
  cookbook.path = cookbook_path(name)
66
66
  cookbook.server_version = server_cookbooks[name]
67
67
  cookbook.local_version = local_cookbooks[name]
68
- cookbook.bad_files = checksum_compare(name, cookbook.server_version)
68
+ cookbook.bad_files = checksum_compare(name, cookbook.server_version.inspect)
69
69
  end
70
70
 
71
71
  yield item
@@ -74,7 +74,7 @@ module HealthInspector
74
74
 
75
75
  def cookbooks_on_server
76
76
  chef_rest.get_rest("/cookbooks").inject({}) do |hsh, (name,version)|
77
- hsh[name] = version["versions"].first["version"]
77
+ hsh[name] = Chef::Version.new(version["versions"].first["version"])
78
78
  hsh
79
79
  end
80
80
  end
@@ -89,7 +89,7 @@ module HealthInspector
89
89
  name = File.basename(path)
90
90
  version = (`grep '^version' #{path}/metadata.rb`).split.last[1...-1]
91
91
 
92
- hsh[name] = version
92
+ hsh[name] = Chef::Version.new(version)
93
93
  hsh
94
94
  end
95
95
  end
@@ -24,7 +24,7 @@ module HealthInspector
24
24
  item = DataBag.new.tap do |data_bag|
25
25
  data_bag.name = name
26
26
  data_bag.exists_on_server = data_bags_on_server.include?(name)
27
- data_bag.exists_locally = data_bags_in_repo.include?(name)
27
+ data_bag.exists_locally = data_bags_in_repo.include?(name)
28
28
  end
29
29
 
30
30
  yield item
@@ -4,12 +4,20 @@ module HealthInspector
4
4
  class CLI < Thor
5
5
  class_option 'repopath', :type => :string, :aliases => "-r",
6
6
  :default => ".",
7
- :banner => "Path to your local chef-repo"
7
+ :banner => "Path to your local chef-repo."
8
8
 
9
9
  class_option 'configpath', :type => :string, :aliases => "-c",
10
10
  :default => ".chef/knife.rb",
11
11
  :banner => "Path to your knife config file."
12
12
 
13
+ class_option 'no-color', :type => :boolean,
14
+ :default => false,
15
+ :banner => "Suppress output of ansi color messages."
16
+
17
+ class_option 'quiet-success', :type => :boolean, :aliases => "-q",
18
+ :default => false,
19
+ :banner => "Suppress output of successful checks."
20
+
13
21
  default_task :inspect
14
22
 
15
23
  desc "inspect [COMPONENT]", <<-EOS
@@ -19,7 +27,7 @@ Inspect a chef repo. Optionally, specify one component to inspect:
19
27
 
20
28
  def inspect(component="")
21
29
  checklists = component_to_checklists(component)
22
- Inspector.inspect( checklists ,options[:repopath], options[:configpath])
30
+ Inspector.inspect( checklists, options)
23
31
  end
24
32
 
25
33
  protected
@@ -23,7 +23,11 @@ module HealthInspector
23
23
  'diff removed' => 41
24
24
  }
25
25
 
26
+ if @context.no_color
27
+ str
28
+ else
26
29
  "\e[%sm%s\e[0m" % [ colors[type], str ]
30
+ end
27
31
  end
28
32
  end
29
- end
33
+ end
@@ -2,6 +2,9 @@ require "chef/config"
2
2
 
3
3
  module HealthInspector
4
4
  class Context < Struct.new(:repo_path, :config_path)
5
+
6
+ attr_accessor :no_color, :quiet_success
7
+
5
8
  def cookbook_path
6
9
  Array( config.cookbook_path )
7
10
  end
@@ -1,11 +1,13 @@
1
1
  module HealthInspector
2
2
  class Inspector
3
- def self.inspect(checklists, repo_path, config_path)
4
- new(repo_path, config_path).inspect( checklists )
3
+ def self.inspect(checklists, options)
4
+ new(options).inspect( checklists )
5
5
  end
6
6
 
7
- def initialize(repo_path, config_path)
8
- @context = Context.new( repo_path, config_path )
7
+ def initialize(options)
8
+ @context = Context.new( options[:repopath], options[:configpath] )
9
+ @context.quiet_success = options[:'quiet-success']
10
+ @context.no_color = options[:'no-color']
9
11
  @context.configure
10
12
  end
11
13
 
@@ -1,3 +1,3 @@
1
1
  module HealthInspector
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe "HealthInspector::Checklists::Cookbooks" do
4
+ subject do
5
+ HealthInspector::Checklists::Cookbooks.new(health_inspector_context)
6
+ end
7
+
8
+ # :name, :path, :server_version, :local_version, :bad_files
9
+ let(:item) { HealthInspector::Checklists::Cookbooks::Cookbook }
10
+
11
+ it "should detect if a cookbook does not exist locally" do
12
+ obj = item.new("ruby", nil, "0.0.1", nil, [])
13
+
14
+ failures = subject.run_checks(obj)
15
+ failures.should_not be_empty
16
+ failures.first.should == "exists on server but not locally"
17
+ end
18
+
19
+ it "should detect if a cookbook does not exist on server" do
20
+ obj = item.new("ruby", "cookbooks/ruby", nil, "0.0.1", [])
21
+
22
+ failures = subject.run_checks(obj)
23
+ failures.should_not be_empty
24
+ failures.first.should == "exists locally but not on server"
25
+ end
26
+ end
@@ -5,12 +5,36 @@ describe "HealthInspector::Checklists::DataBagItems" do
5
5
  HealthInspector::Checklists::DataBagItems.new(health_inspector_context)
6
6
  end
7
7
 
8
+ let(:item) { HealthInspector::Checklists::DataBagItems::DataBagItem }
9
+
8
10
  it "should detect if a data bag item does not exist locally" do
9
- item = HealthInspector::Checklists::DataBagItems::DataBagItem.new(
10
- :name => "apps", :server => ["apps/app1"], :local => nil
11
- )
11
+ obj = item.new("apps", {"foo" => "bar"}, nil)
12
+
13
+ failures = subject.run_checks(obj)
14
+ failures.should_not be_empty
15
+ failures.first.should == "exists on server but not locally"
16
+ end
17
+
18
+ it "should detect if a data bag item does not exist on server" do
19
+ obj = item.new("apps", nil, {"foo" => "bar"})
20
+
21
+ failures = subject.run_checks(obj)
22
+ failures.should_not be_empty
23
+ failures.first.should == "exists locally but not on server"
24
+ end
25
+
26
+ it "should detect if a data bag item is different" do
27
+ obj = item.new("apps", {"foo" => "bar"}, {"foo" => "baz"})
28
+
29
+ failures = subject.run_checks(obj)
30
+ failures.should_not be_empty
31
+ failures.first.should == {"foo" => {"server" => "bar", "local" => "baz"}}
32
+ end
33
+
34
+ it "should detect if a data bag item is the same" do
35
+ obj = item.new("apps", {"foo" => "bar"}, {"foo" => "bar"})
12
36
 
13
- failures = subject.run_checks(item)
14
- failures.first.include?("exists on server but not locally").must_equal true
37
+ failures = subject.run_checks(obj)
38
+ failures.should be_empty
15
39
  end
16
40
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe "HealthInspector::Checklists::DataBags" do
4
+ subject do
5
+ HealthInspector::Checklists::DataBags.new(health_inspector_context)
6
+ end
7
+
8
+ let(:item) { HealthInspector::Checklists::DataBags::DataBag }
9
+
10
+ it "should detect if a data bag does not exist locally" do
11
+ obj = item.new("users", true, false)
12
+
13
+ failures = subject.run_checks(obj)
14
+ failures.should_not be_empty
15
+ failures.first.should == "exists on server but not locally"
16
+ end
17
+
18
+ it "should detect if a data bag does not exist on server" do
19
+ obj = item.new("users", false, true)
20
+
21
+ failures = subject.run_checks(obj)
22
+ failures.should_not be_empty
23
+ failures.first.should == "exists locally but not on server"
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe "HealthInspector::Checklists::Environments" do
4
+ subject do
5
+ HealthInspector::Checklists::Environments.new(health_inspector_context)
6
+ end
7
+
8
+ let(:item) { HealthInspector::Checklists::Environments::Environment }
9
+
10
+ it "should detect if an environment does not exist locally" do
11
+ obj = item.new("production", {}, nil)
12
+
13
+ failures = subject.run_checks(obj)
14
+ failures.should_not be_empty
15
+ failures.first.should == "exists on server but not locally"
16
+ end
17
+
18
+ it "should detect if an environment does not exist on server" do
19
+ obj = item.new("production", nil, {})
20
+
21
+ failures = subject.run_checks(obj)
22
+ failures.should_not be_empty
23
+ failures.first.should == "exists locally but not on server"
24
+ end
25
+
26
+ it "should detect if an environment is different" do
27
+ obj = item.new("production", {"foo" => "bar"}, {"foo" => "baz"})
28
+
29
+ failures = subject.run_checks(obj)
30
+ failures.should_not be_empty
31
+ failures.first.should == {"foo"=>{"server"=>"bar", "local"=>"baz"}}
32
+ end
33
+
34
+ it "should detect if an environment is the same" do
35
+ obj = item.new("production", {}, {})
36
+
37
+ failures = subject.run_checks(obj)
38
+ failures.should be_empty
39
+ end
40
+
41
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe "HealthInspector::Checklists::Roles" do
4
+ subject do
5
+ HealthInspector::Checklists::Roles.new(health_inspector_context)
6
+ end
7
+
8
+ let(:item) { HealthInspector::Checklists::Roles::Role }
9
+
10
+ it "should detect if an role does not exist locally" do
11
+ obj = item.new("app-server", {}, nil)
12
+
13
+ failures = subject.run_checks(obj)
14
+ failures.should_not be_empty
15
+ failures.first.should == "exists on server but not locally"
16
+ end
17
+
18
+ it "should detect if an role does not exist on server" do
19
+ obj = item.new("app-server", nil, {})
20
+
21
+ failures = subject.run_checks(obj)
22
+ failures.should_not be_empty
23
+ failures.first.should == "exists locally but not on server"
24
+ end
25
+
26
+ it "should detect if an role is different" do
27
+ obj = item.new("app-server", {"foo" => "bar"}, {"foo" => "baz"})
28
+
29
+ failures = subject.run_checks(obj)
30
+ failures.should_not be_empty
31
+ failures.first.should == {"foo"=>{"server"=>"bar", "local"=>"baz"}}
32
+ end
33
+
34
+ it "should detect if an role is the same" do
35
+ obj = item.new("app-server", {}, {})
36
+
37
+ failures = subject.run_checks(obj)
38
+ failures.should be_empty
39
+ end
40
+
41
+ end
@@ -1,7 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
- require 'minitest/autorun'
4
- require 'mocha'
5
3
  require 'health_inspector'
6
4
 
7
5
  module HealthInspector::SpecHelpers
@@ -16,6 +14,6 @@ module HealthInspector::SpecHelpers
16
14
  end
17
15
  end
18
16
 
19
- class MiniTest::Unit::TestCase
20
- include HealthInspector::SpecHelpers
17
+ RSpec.configure do |c|
18
+ c.include HealthInspector::SpecHelpers
21
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: health_inspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-28 00:00:00.000000000 Z
12
+ date: 2012-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: minitest
16
- requirement: &70160890038160 !ruby/object:Gem::Requirement
15
+ name: rspec
16
+ requirement: &70309192996340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70160890038160
25
- - !ruby/object:Gem::Dependency
26
- name: mocha
27
- requirement: &70160890037480 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70160890037480
24
+ version_requirements: *70309192996340
36
25
  - !ruby/object:Gem::Dependency
37
26
  name: thor
38
- requirement: &70160890053240 !ruby/object:Gem::Requirement
27
+ requirement: &70309192995660 !ruby/object:Gem::Requirement
39
28
  none: false
40
29
  requirements:
41
30
  - - ! '>='
@@ -43,10 +32,10 @@ dependencies:
43
32
  version: '0'
44
33
  type: :runtime
45
34
  prerelease: false
46
- version_requirements: *70160890053240
35
+ version_requirements: *70309192995660
47
36
  - !ruby/object:Gem::Dependency
48
37
  name: chef
49
- requirement: &70160890052420 !ruby/object:Gem::Requirement
38
+ requirement: &70309192994720 !ruby/object:Gem::Requirement
50
39
  none: false
51
40
  requirements:
52
41
  - - ~>
@@ -54,10 +43,10 @@ dependencies:
54
43
  version: '10.14'
55
44
  type: :runtime
56
45
  prerelease: false
57
- version_requirements: *70160890052420
46
+ version_requirements: *70309192994720
58
47
  - !ruby/object:Gem::Dependency
59
48
  name: yajl-ruby
60
- requirement: &70160890051640 !ruby/object:Gem::Requirement
49
+ requirement: &70309192994080 !ruby/object:Gem::Requirement
61
50
  none: false
62
51
  requirements:
63
52
  - - ! '>='
@@ -65,7 +54,7 @@ dependencies:
65
54
  version: '0'
66
55
  type: :runtime
67
56
  prerelease: false
68
- version_requirements: *70160890051640
57
+ version_requirements: *70309192994080
69
58
  description: A tool to inspect your chef repo as is compares to what is on your chef
70
59
  server
71
60
  email:
@@ -98,8 +87,11 @@ files:
98
87
  - lib/health_inspector/version.rb
99
88
  - spec/chef-repo/.chef/client.pem
100
89
  - spec/chef-repo/.chef/knife.rb
101
- - spec/chef-repo/data_bags/.gitkeep
90
+ - spec/cookbook_spec.rb
102
91
  - spec/data_bag_item_spec.rb
92
+ - spec/data_bag_spec.rb
93
+ - spec/environment_spec.rb
94
+ - spec/role_spec.rb
103
95
  - spec/spec_helper.rb
104
96
  homepage: https://github.com/bmarini/health_inspector
105
97
  licenses: []
@@ -128,6 +120,9 @@ summary: A tool to inspect your chef repo as is compares to what is on your chef
128
120
  test_files:
129
121
  - spec/chef-repo/.chef/client.pem
130
122
  - spec/chef-repo/.chef/knife.rb
131
- - spec/chef-repo/data_bags/.gitkeep
123
+ - spec/cookbook_spec.rb
132
124
  - spec/data_bag_item_spec.rb
125
+ - spec/data_bag_spec.rb
126
+ - spec/environment_spec.rb
127
+ - spec/role_spec.rb
133
128
  - spec/spec_helper.rb
File without changes