knife-inspect 0.6.0 → 0.6.2

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,7 @@
1
+ ## 0.6.2 ( 2013-02-27 )
2
+
3
+ * Be indifferent about symbols and strings for hash keys when diff'ing
4
+
1
5
  ## 0.6.0 ( 2012-11-1 )
2
6
 
3
7
  * Add knife plugins for all existing functionality:
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
- [![Build Status](https://secure.travis-ci.org/bmarini/health_inspector.png)](http://travis-ci.org/bmarini/health_inspector)
1
+ [![Build Status](https://secure.travis-ci.org/bmarini/knife-inspect.png)](http://travis-ci.org/bmarini/knife-inspect)
2
2
 
3
3
  ## Summary
4
4
 
5
- `health_inspector` is a knife plugin that inspects your chef repo as it
5
+ `knife-inspect` is a knife plugin that inspects your chef repo as it
6
6
  compares to what is on your chef server. You can inspect your entire repo,
7
7
  or individual components.
8
8
 
9
9
  ## Usage
10
10
 
11
- $ gem install health_inspector
11
+ $ gem install knife-inspect
12
12
  $ cd [chef repo]
13
13
 
14
14
  ## Knife Commands
@@ -37,13 +37,36 @@ module HealthInspector
37
37
  self.methods.grep(/^validate_/).each { |meth| send(meth) }
38
38
  end
39
39
 
40
+
40
41
  def hash_diff(original, other)
42
+ recursive_diff(stringify_hash_keys(original), stringify_hash_keys(other))
43
+ end
44
+
45
+ def stringify_hash_keys(original)
46
+ original.keys.inject({}) do |original_strkey, key|
47
+ original_strkey[key.to_s] = stringify_item(original[key])
48
+ original_strkey
49
+ end
50
+ end
51
+
52
+ def stringify_item(item)
53
+ if item.kind_of?(Hash)
54
+ stringify_hash_keys(item)
55
+ elsif item.kind_of?(Array)
56
+ item.map {|array_item| stringify_item(array_item) }
57
+ else # must be a string
58
+ item
59
+ end
60
+ end
61
+
62
+ def recursive_diff(original, other)
41
63
  (original.keys + other.keys).uniq.inject({}) do |memo, key|
42
64
  unless original[key] == other[key]
43
65
  if original[key].kind_of?(Hash) && other[key].kind_of?(Hash)
44
- memo[key] = hash_diff(original[key], other[key])
66
+ diff = recursive_diff(original[key], other[key])
67
+ memo[key] = diff unless diff.empty?
45
68
  else
46
- memo[key] = {"server" => original[key],"local" => other[key]}
69
+ memo[key] = {"server" => original[key], "local" => other[key]}
47
70
  end
48
71
  end
49
72
  memo
@@ -1,3 +1,3 @@
1
1
  module HealthInspector
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.2"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -41,16 +41,64 @@ shared_examples "a chef model that can be respresented in json" do
41
41
  pairing.server = {"foo" => "bar"}
42
42
  pairing.local = {"foo" => "baz"}
43
43
  pairing.validate
44
-
44
+
45
45
  pairing.errors.should_not be_empty
46
46
  pairing.errors.first.should == {"foo"=>{"server"=>"bar", "local"=>"baz"}}
47
47
  end
48
-
48
+
49
49
  it "should detect if an item is the same" do
50
50
  pairing.server = {"foo" => "bar"}
51
51
  pairing.local = {"foo" => "bar"}
52
52
  pairing.validate
53
-
53
+
54
+ pairing.errors.should be_empty
55
+ end
56
+
57
+ it "should detect if an string and symbol keys convert to the same values" do
58
+ pairing.server = {"foo" => "bar"}
59
+ pairing.local = {:foo => "bar"}
60
+ pairing.validate
61
+
62
+ pairing.errors.should be_empty
63
+ end
64
+
65
+ it "should detect if matching hashes are the same" do
66
+ pairing.server = {"foo" => {"bar" => "fizz"}}
67
+ pairing.local = {"foo" => {"bar" => "fizz"}}
68
+ pairing.validate
69
+
70
+ pairing.errors.should be_empty
71
+ end
72
+
73
+ it "should detect if matching hashes with mismatched symbols and keys are the same" do
74
+ pairing.server = {"foo" => {"bar" => "fizz"}}
75
+ pairing.local = {:foo => {:bar => "fizz"}}
76
+ pairing.validate
77
+
78
+ pairing.errors.should be_empty
79
+ end
80
+
81
+ it "should detect if matching arrays are the same" do
82
+ pairing.server = {"foo" => ["bar", "fizz"]}
83
+ pairing.local = {"foo" => ["bar", "fizz"]}
84
+ pairing.validate
85
+
86
+ pairing.errors.should be_empty
87
+ end
88
+
89
+ it "should detect if matching arrays with hashes are the same" do
90
+ pairing.server = {"foo" => ["bar", {"fizz" => "buzz"}]}
91
+ pairing.local = {"foo" => ["bar", {"fizz" => "buzz"}]}
92
+ pairing.validate
93
+
94
+ pairing.errors.should be_empty
95
+ end
96
+
97
+ it "should detect if matching arrays with hashes containing symbols/strings are the same" do
98
+ pairing.server = {"foo" => ["bar", {"fizz" => "buzz"}]}
99
+ pairing.local = {"foo" => ["bar", {:fizz => "buzz"}]}
100
+ pairing.validate
101
+
54
102
  pairing.errors.should be_empty
55
103
  end
56
104
  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.6.0
4
+ version: 0.6.2
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-11-02 00:00:00.000000000 Z
12
+ date: 2013-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70274490577920 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70274490577920
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &70274490573900 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70274490573900
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: thor
38
- requirement: &70274490581800 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70274490581800
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: chef
49
- requirement: &70274490608360 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '10.14'
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *70274490608360
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '10.14'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: yajl-ruby
60
- requirement: &70274490625560 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,7 +85,12 @@ dependencies:
65
85
  version: '0'
66
86
  type: :runtime
67
87
  prerelease: false
68
- version_requirements: *70274490625560
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  description: Inspect your chef repo as is compares to what is on your chef server
70
95
  email:
71
96
  - bmarini@gmail.com
@@ -125,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
150
  version: '0'
126
151
  requirements: []
127
152
  rubyforge_project: knife-inspect
128
- rubygems_version: 1.8.11
153
+ rubygems_version: 1.8.23
129
154
  signing_key:
130
155
  specification_version: 3
131
156
  summary: Inspect your chef repo as is compares to what is on your chef server
@@ -138,3 +163,4 @@ test_files:
138
163
  - spec/environment_spec.rb
139
164
  - spec/role_spec.rb
140
165
  - spec/spec_helper.rb
166
+ has_rdoc: