chef-sugar 1.2.6 → 1.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +49 -15
- data/Rakefile +0 -7
- data/chef-sugar.gemspec +0 -1
- data/lib/chef/sugar.rb +1 -0
- data/lib/chef/sugar/core_extensions.rb +1 -0
- data/lib/chef/sugar/core_extensions/array.rb +1 -1
- data/lib/chef/sugar/core_extensions/object.rb +27 -0
- data/lib/chef/sugar/core_extensions/string.rb +19 -2
- data/lib/chef/sugar/filters.rb +10 -4
- data/lib/chef/sugar/node.rb +0 -10
- data/lib/chef/sugar/platform.rb +11 -4
- data/lib/chef/sugar/run_context.rb +41 -0
- data/lib/chef/sugar/shell.rb +4 -3
- data/lib/chef/sugar/version.rb +1 -1
- data/metadata.rb +1 -1
- data/recipes/default.rb +1 -1
- data/spec/spec_helper.rb +5 -0
- data/spec/unit/chef/sugar/core_extensions/object_spec.rb +62 -0
- data/spec/unit/chef/sugar/core_extensions/string_spec.rb +32 -0
- data/spec/unit/chef/sugar/node_spec.rb +0 -13
- data/spec/unit/chef/sugar/platform_spec.rb +24 -0
- data/spec/unit/chef/sugar/run_context_spec.rb +19 -0
- data/spec/unit/chef/sugar/shell_spec.rb +5 -1
- metadata +9 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66a357a489b8f06b63b80a4f27388f34dcfabfb8
|
4
|
+
data.tar.gz: a918f43f869416832f5df31c528d31199177cb24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 632e3cf402e28a4e70daf2fa2cb1e1c9c55f5f5fae114c2cd4e3e436ee14f1ecaad627b0ec2c35caf316a89a46c2ce8ada33bc27709716db26c9ca4ff700d589
|
7
|
+
data.tar.gz: af93b654a34537965675d2e3ded37cdc4dc9339b69c259257f2aabecd878e58056ad5fbe9af6495b700183af4b7f5b0121e7c9564208ea0d13ed873e5dd31fd6
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@ Chef Sugar Changelog
|
|
2
2
|
=========================
|
3
3
|
This file is used to list changes made in each version of the chef-sugar cookbook and gem.
|
4
4
|
|
5
|
+
vx.y.z (not yet released)
|
6
|
+
-------------------------
|
7
|
+
- Check both `$stdout` and `$stderr` in `version_for`
|
8
|
+
- Add additional platform versions
|
9
|
+
- Make `includes_recipe?` a top-level API (instead of just Node)
|
10
|
+
- Match on the highest version number instead of direct equality checking on platform versions
|
11
|
+
- Define `Object#blank?` as a core extension
|
12
|
+
- Define `String#flush` as a core extension
|
13
|
+
- Remove Stove
|
14
|
+
|
5
15
|
v1.2.6 (2014-03-16)
|
6
16
|
-------------------
|
7
17
|
- Fix a bug in `vagrant?` returning false on newer Vagrant versions
|
data/README.md
CHANGED
@@ -1,16 +1,23 @@
|
|
1
1
|
Chef::Sugar
|
2
2
|
================
|
3
|
-
[][gem]
|
4
|
+
[][travis]
|
5
|
+
[][gemnasium]
|
6
|
+
[][codeclimate]
|
7
|
+
[][gittip]
|
7
8
|
|
8
|
-
|
9
|
+
[gem]: https://rubygems.org/gems/chef-sugar
|
10
|
+
[travis]: http://travis-ci.org/sethvargo/chef-suguar
|
11
|
+
[gemnasium]: https://gemnasium.com/sethvargo/chef-sugar
|
12
|
+
[codeclimate]: https://codeclimate.com/github/sethvargo/chef-sugar
|
13
|
+
[gittip]: https://www.gittip.com/sethvargo
|
14
|
+
|
15
|
+
Chef Sugar is a Gem & Chef Recipe that includes series of helpful sugar of the Chef core and other resources to make a cleaner, more lean recipe DSL, enforce DRY principles, and make writing Chef recipes an awesome experience!
|
9
16
|
|
10
17
|
|
11
18
|
Installation
|
12
19
|
------------
|
13
|
-
If you want to
|
20
|
+
If you want to develop/hack on chef-sugar, please see the Contributing.md.
|
14
21
|
|
15
22
|
If you are using Berkshelf, add `chef-sugar` to your `Berksfile`:
|
16
23
|
|
@@ -107,6 +114,31 @@ template '/tmp/config' do
|
|
107
114
|
end
|
108
115
|
```
|
109
116
|
|
117
|
+
### Core Extensions
|
118
|
+
**Note:** Core extensions are **not** included by default. You must require the `chef/sugar/core_extensions` module manually to gain access to these APIs:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
require 'chef/sugar/core_extensions'
|
122
|
+
```
|
123
|
+
|
124
|
+
- `String#satisfies?`
|
125
|
+
- `String#satisfied_by?`
|
126
|
+
- `Array#satisfied_by?`
|
127
|
+
- `Object#blank?`
|
128
|
+
|
129
|
+
#### Examples
|
130
|
+
```ruby
|
131
|
+
# Checking version constraints
|
132
|
+
'1.0.0'.satisfies?('~> 1.0') #=> true
|
133
|
+
'~> 1.0'.satisfied_by?('1.0') #=> true
|
134
|
+
```
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
# Check for an object's presence
|
138
|
+
''.blank? #=> true
|
139
|
+
['hello'].blank? #=> false
|
140
|
+
```
|
141
|
+
|
110
142
|
### Data Bag
|
111
143
|
- `encrypted_data_bag_item` - a handy DSL method for loading encrypted data bag items the same way you load a regular data bag item; this requires `Chef::Config[:encrypted_data_bag_secret]` is set!
|
112
144
|
- `encrypted_data_bag_item_for_environment` - find the data bag entry for the current node's Chef environment.
|
@@ -219,7 +251,6 @@ end
|
|
219
251
|
- `deep_fetch` - safely fetch a nested attribute.
|
220
252
|
- `deep_fetch!` - fetch a nested attribute, raising a more semantic error if the key does not exist.
|
221
253
|
- `in?` - determine if the node is in the given Chef environment.
|
222
|
-
- `includes_recipe?`
|
223
254
|
|
224
255
|
#### Examples
|
225
256
|
```ruby
|
@@ -230,14 +261,6 @@ credentials = if in?('production')
|
|
230
261
|
end
|
231
262
|
```
|
232
263
|
|
233
|
-
```ruby
|
234
|
-
if includes_recipe?('apache2::default')
|
235
|
-
apache_module 'my_module' do
|
236
|
-
# ...
|
237
|
-
end
|
238
|
-
end
|
239
|
-
```
|
240
|
-
|
241
264
|
```ruby
|
242
265
|
node.deep_fetch('apache2', 'config', 'root') => node['apache2']['config']['root']
|
243
266
|
```
|
@@ -307,6 +330,17 @@ node['attribute'] = if windows?
|
|
307
330
|
log 'This has been known to fail on Ruby 2.0' if ruby_20?
|
308
331
|
```
|
309
332
|
|
333
|
+
### Run Context
|
334
|
+
- `includes_recipe?` - determines if the current run context includes the recipe
|
335
|
+
|
336
|
+
```ruby
|
337
|
+
if includes_recipe?('apache2::default')
|
338
|
+
apache_module 'my_module' do
|
339
|
+
# ...
|
340
|
+
end
|
341
|
+
end
|
342
|
+
```
|
343
|
+
|
310
344
|
### Shell
|
311
345
|
- `which`
|
312
346
|
- `dev_null`
|
data/Rakefile
CHANGED
data/chef-sugar.gemspec
CHANGED
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
|
|
26
26
|
|
27
27
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
28
28
|
spec.add_development_dependency 'rake'
|
29
|
-
spec.add_development_dependency 'stove', '~> 2.0.0.beta'
|
30
29
|
|
31
30
|
spec.add_development_dependency 'chefspec', '~> 3.0'
|
32
31
|
spec.add_development_dependency 'test-kitchen', '~> 1.1'
|
data/lib/chef/sugar.rb
CHANGED
@@ -31,6 +31,7 @@ class Chef
|
|
31
31
|
require_relative 'sugar/platform'
|
32
32
|
require_relative 'sugar/platform_family'
|
33
33
|
require_relative 'sugar/ruby'
|
34
|
+
require_relative 'sugar/run_context'
|
34
35
|
require_relative 'sugar/shell'
|
35
36
|
require_relative 'sugar/vagrant'
|
36
37
|
require_relative 'sugar/version'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2013-2014, Seth Vargo <sethvargo@gmail.com>
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
class Object
|
18
|
+
# An object is blank if it's false, empty, or a whitespace string.
|
19
|
+
# This is implemented in rails.
|
20
|
+
#
|
21
|
+
# @example foo.nil? || foo.empty? can be replaced by foo.blank?
|
22
|
+
#
|
23
|
+
# @return [true, false]
|
24
|
+
def blank?
|
25
|
+
respond_to?(:empty?) ? empty? : !self
|
26
|
+
end unless method_defined?(:blank?)
|
27
|
+
end
|
@@ -30,7 +30,7 @@ class String
|
|
30
30
|
#
|
31
31
|
def satisfies?(*constraints)
|
32
32
|
Chef::Sugar::Constraints::Version.new(dup).satisfies?(*constraints)
|
33
|
-
end
|
33
|
+
end unless method_defined?(:satisfies?)
|
34
34
|
|
35
35
|
#
|
36
36
|
# Treat strings as version constraints.
|
@@ -45,5 +45,22 @@ class String
|
|
45
45
|
#
|
46
46
|
def satisfied_by?(version)
|
47
47
|
Chef::Sugar::Constraints::Constraint.new(dup).satisfied_by?(version)
|
48
|
-
end
|
48
|
+
end unless method_defined?(:satisfied_by?)
|
49
|
+
|
50
|
+
#
|
51
|
+
# Left-flush a string based off of the number of whitespace characters on the
|
52
|
+
# first line. This is especially useful for heredocs when whitespace matters.
|
53
|
+
#
|
54
|
+
# @example Remove leading whitespace and flush
|
55
|
+
# <<-EOH.flush
|
56
|
+
# def method
|
57
|
+
# 'This is a string!'
|
58
|
+
# end
|
59
|
+
# EOH #=>"def method\n 'This is a string!'\nend"
|
60
|
+
#
|
61
|
+
# @return [String]
|
62
|
+
#
|
63
|
+
def flush
|
64
|
+
gsub(/^#{self[/\A\s*/]}/, '').chomp
|
65
|
+
end unless method_defined?(:flush)
|
49
66
|
end
|
data/lib/chef/sugar/filters.rb
CHANGED
@@ -15,11 +15,17 @@ class Chef
|
|
15
15
|
|
16
16
|
def method_missing(m, *args, &block)
|
17
17
|
resource = @recipe.send(m, *args, &block)
|
18
|
-
|
19
|
-
resource.
|
20
|
-
|
21
|
-
resource.
|
18
|
+
|
19
|
+
if resource.is_a?(Chef::Resource)
|
20
|
+
actions = Array(resource.action)
|
21
|
+
resource.action(:nothing)
|
22
|
+
|
23
|
+
actions.each do |action|
|
24
|
+
resource.run_action(action)
|
25
|
+
end
|
22
26
|
end
|
27
|
+
|
28
|
+
resource
|
23
29
|
end
|
24
30
|
end
|
25
31
|
|
data/lib/chef/sugar/node.rb
CHANGED
@@ -38,16 +38,6 @@ EOH
|
|
38
38
|
environment === chef_environment
|
39
39
|
end
|
40
40
|
|
41
|
-
#
|
42
|
-
# Determine if the current node includes the given recipe name.
|
43
|
-
#
|
44
|
-
# @param [String] recipe_name
|
45
|
-
#
|
46
|
-
def includes_recipe?(recipe_name)
|
47
|
-
run_list.include?(recipe_name)
|
48
|
-
end
|
49
|
-
alias_method :include_recipe?, :includes_recipe?
|
50
|
-
|
51
41
|
#
|
52
42
|
# Safely fetch a deeply nested attribute by specifying a list of keys,
|
53
43
|
# bypassing Ruby's Hash notation. This method swallows +NoMethodError+
|
data/lib/chef/sugar/platform.rb
CHANGED
@@ -21,11 +21,12 @@ class Chef
|
|
21
21
|
|
22
22
|
PLATFORM_VERSIONS = {
|
23
23
|
'debian' => {
|
24
|
-
'squeeze' => '6
|
25
|
-
'wheezy' => '7
|
26
|
-
'jessie' => '8
|
24
|
+
'squeeze' => '6',
|
25
|
+
'wheezy' => '7',
|
26
|
+
'jessie' => '8',
|
27
27
|
},
|
28
28
|
'linuxmint' => {
|
29
|
+
'petra' => '16',
|
29
30
|
'olivia' => '15',
|
30
31
|
'nadia' => '14',
|
31
32
|
'maya' => '13',
|
@@ -45,6 +46,7 @@ class Chef
|
|
45
46
|
'quantal' => '12.10',
|
46
47
|
'raring' => '13.04',
|
47
48
|
'saucy' => '13.10',
|
49
|
+
'trusty' => '14.04',
|
48
50
|
},
|
49
51
|
}
|
50
52
|
|
@@ -64,9 +66,14 @@ class Chef
|
|
64
66
|
COMPARISON_OPERATORS.each do |operator, block|
|
65
67
|
method_name = "#{platform}_#{operator}_#{name}?".squeeze('_').to_sym
|
66
68
|
define_method(method_name) do |node|
|
69
|
+
# Find the highest precedence that we actually care about based
|
70
|
+
# off of what was given to us in the list.
|
71
|
+
length = version.split('.').size
|
72
|
+
check = node['platform_version'].split('.')[0...length].join('.')
|
73
|
+
|
67
74
|
# Calling #to_f will ensure we only check major versions since
|
68
75
|
# '10.04.4'.to_f #=> 10.04.
|
69
|
-
node['platform'] == platform && block.call(
|
76
|
+
node['platform'] == platform && block.call(check.to_f, version.to_f)
|
70
77
|
end
|
71
78
|
end
|
72
79
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2013-2014, Seth Vargo <sethvargo@gmail.com>
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
class Chef
|
18
|
+
module Sugar
|
19
|
+
module RunContext
|
20
|
+
extend self
|
21
|
+
|
22
|
+
#
|
23
|
+
# Determine if the current node includes the given recipe name.
|
24
|
+
#
|
25
|
+
# @param [String] recipe_name
|
26
|
+
#
|
27
|
+
def includes_recipe?(node, recipe_name)
|
28
|
+
node.recipe?(recipe_name)
|
29
|
+
end
|
30
|
+
alias_method :include_recipe?, :includes_recipe?
|
31
|
+
end
|
32
|
+
|
33
|
+
module DSL
|
34
|
+
# @see Chef::Sugar::IP#best_ip_for
|
35
|
+
def includes_recipe?(recipe_name)
|
36
|
+
Chef::Sugar::RunContext.includes_recipe?(node, recipe_name)
|
37
|
+
end
|
38
|
+
alias_method :include_recipe?, :includes_recipe?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/chef/sugar/shell.rb
CHANGED
@@ -93,7 +93,8 @@ class Chef
|
|
93
93
|
#
|
94
94
|
# Assumptions:
|
95
95
|
# 1. The command exists.
|
96
|
-
# 2. The command outputs version information to +$stdout+.
|
96
|
+
# 2. The command outputs version information to +$stdout+ or +$stderr+.
|
97
|
+
# Did you know that java outputs its version to $stderr?
|
97
98
|
#
|
98
99
|
#
|
99
100
|
# @param [String] cmd
|
@@ -102,13 +103,13 @@ class Chef
|
|
102
103
|
# the flag to use to get the version
|
103
104
|
#
|
104
105
|
# @return [String]
|
105
|
-
# the output of the version command
|
106
|
+
# the entire output of the version command (stderr and stdout)
|
106
107
|
#
|
107
108
|
def version_for(cmd, flag = '--version')
|
108
109
|
cmd = Mixlib::ShellOut.new("#{cmd} #{flag}")
|
109
110
|
cmd.run_command
|
110
111
|
cmd.error!
|
111
|
-
cmd.stdout.strip
|
112
|
+
[cmd.stdout.strip, cmd.stderr.strip].join("\n")
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
data/lib/chef/sugar/version.rb
CHANGED
data/metadata.rb
CHANGED
data/recipes/default.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -10,6 +10,11 @@ RSpec.configure do |config|
|
|
10
10
|
spec.syntax = :expect
|
11
11
|
end
|
12
12
|
|
13
|
+
# Focus groups
|
14
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
+
config.filter_run(focus: true)
|
16
|
+
config.run_all_when_everything_filtered = true
|
17
|
+
|
13
18
|
# Run specs in random order to surface order dependencies. If you find an
|
14
19
|
# order dependency and want to debug it, you can fix the order by providing
|
15
20
|
# the seed, which is printed after each run.
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'chef/sugar/core_extensions'
|
3
|
+
|
4
|
+
describe Object do
|
5
|
+
describe '#blank?' do
|
6
|
+
it 'includes the method' do
|
7
|
+
expect(described_class).to be_method_defined(:blank?)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns true for nil' do
|
11
|
+
expect(nil).to be_blank
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns true for false' do
|
15
|
+
expect(false).to be_blank
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns true for the empty string' do
|
19
|
+
expect('').to be_blank
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns true for the empty array' do
|
23
|
+
expect([]).to be_blank
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns true for the empty hash' do
|
27
|
+
expect({}).to be_blank
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns false for a non-empty string' do
|
31
|
+
expect(' ').to_not be_blank
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns false for a non-empty string with unicode' do
|
35
|
+
expect("\u00a0").to_not be_blank
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns false for a non-empty string with special characters' do
|
39
|
+
expect("\n\t").to_not be_blank
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns false for any object' do
|
43
|
+
expect(Object.new).to_not be_blank
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns false for true' do
|
47
|
+
expect(true).to_not be_blank
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns false for a fixnum' do
|
51
|
+
expect(1).to_not be_blank
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns false for an array with items' do
|
55
|
+
expect(['foo']).to_not be_blank
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'returns false for an array with items' do
|
59
|
+
expect({'foo' => 'bar'}).to_not be_blank
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -13,4 +13,36 @@ describe String do
|
|
13
13
|
expect(described_class).to be_method_defined(:satisfied_by?)
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
describe '#flush' do
|
18
|
+
context 'when given a single-line string' do
|
19
|
+
it 'strips trailing whitespace' do
|
20
|
+
string = <<-EOH
|
21
|
+
This is a string
|
22
|
+
EOH
|
23
|
+
expect(string.flush).to eq('This is a string')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when given a multi-line string' do
|
28
|
+
it 'removes the leading number of whitespaces' do
|
29
|
+
string = <<-EOH
|
30
|
+
def method
|
31
|
+
"This is a string!"
|
32
|
+
end
|
33
|
+
EOH
|
34
|
+
expect(string.flush).to eq(%Q(def method\n "This is a string!"\nend))
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'leaves a newline when given' do
|
38
|
+
string = <<-EOH
|
39
|
+
def method
|
40
|
+
"This is a string!"
|
41
|
+
end
|
42
|
+
|
43
|
+
EOH
|
44
|
+
expect(string.flush).to eq(%Q(def method\n "This is a string!"\nend\n))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
16
48
|
end
|
@@ -15,19 +15,6 @@ describe Chef::Node do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe '#includes_recipe?' do
|
19
|
-
it 'returns true when the recipe exists' do
|
20
|
-
subject.stub(:run_list).and_return(['recipe[magic::recipe]'])
|
21
|
-
expect(subject.includes_recipe?('recipe[magic::recipe]')).to be_true
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns false when the recipe does
|
25
|
-
not exist' do
|
26
|
-
subject.stub(:run_list).and_return([])
|
27
|
-
expect(subject.includes_recipe?('recipe[magic::recipe]')).to be_false
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
18
|
describe '#deep_fetch' do
|
32
19
|
let(:node) { described_class.new }
|
33
20
|
before { node.default['apache2']['config']['root'] = '/var/www' }
|
@@ -197,5 +197,29 @@ describe Chef::Sugar::Platform do
|
|
197
197
|
expect(described_class.ubuntu_before_or_at_lucid?(node)).to be_true
|
198
198
|
end
|
199
199
|
end
|
200
|
+
|
201
|
+
describe '#debian_wheezy?' do
|
202
|
+
it 'returns true when the version is a subset of the major' do
|
203
|
+
node = { 'platform' => 'debian', 'platform_version' => '7.1' }
|
204
|
+
expect(described_class.debian_wheezy?(node)).to be_true
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'returns false when the version is not the major' do
|
208
|
+
node = { 'platform' => 'debian', 'platform_version' => '6.1' }
|
209
|
+
expect(described_class.debian_wheezy?(node)).to be_false
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '#debian_before_wheezy?' do
|
214
|
+
it 'returns true when the version is a less than the major' do
|
215
|
+
node = { 'platform' => 'debian', 'platform_version' => '6.5' }
|
216
|
+
expect(described_class.debian_before_wheezy?(node)).to be_true
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'returns false when the version is not less than the major' do
|
220
|
+
node = { 'platform' => 'debian', 'platform_version' => '8.0' }
|
221
|
+
expect(described_class.debian_before_wheezy?(node)).to be_false
|
222
|
+
end
|
223
|
+
end
|
200
224
|
end
|
201
225
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chef::Sugar::RunContext do
|
4
|
+
it_behaves_like 'a chef sugar'
|
5
|
+
|
6
|
+
describe '#includes_recipe?' do
|
7
|
+
let(:node) { double(Chef::Node) }
|
8
|
+
|
9
|
+
it 'returns true when the recipe exists' do
|
10
|
+
node.stub(:recipe?).and_return(true)
|
11
|
+
expect(described_class.includes_recipe?(node, 'foo')).to be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns false when the recipe does not exist' do
|
15
|
+
node.stub(:recipe?).and_return(false)
|
16
|
+
expect(described_class.includes_recipe?(node, 'bar')).to be_false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -71,12 +71,16 @@ describe Chef::Sugar::Shell do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
describe '#version_for' do
|
74
|
-
let(:shell_out) { double('shell_out', run_command: nil, error!: nil, stdout: '1.2.3') }
|
74
|
+
let(:shell_out) { double('shell_out', run_command: nil, error!: nil, stdout: '1.2.3', stderr: 'Oh no!') }
|
75
75
|
before { Mixlib::ShellOut.stub(:new).and_return(shell_out) }
|
76
76
|
|
77
77
|
it 'runs the thing in shellout' do
|
78
78
|
expect(Mixlib::ShellOut).to receive(:new).with('mongo --version')
|
79
79
|
described_class.version_for('mongo')
|
80
80
|
end
|
81
|
+
|
82
|
+
it 'returns the combined stdout and stderr' do
|
83
|
+
expect(described_class.version_for('mongo')).to eq("1.2.3\nOh no!")
|
84
|
+
end
|
81
85
|
end
|
82
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-sugar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Vargo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: stove
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 2.0.0.beta
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 2.0.0.beta
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: chefspec
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,6 +105,7 @@ files:
|
|
119
105
|
- lib/chef/sugar/constraints.rb
|
120
106
|
- lib/chef/sugar/core_extensions.rb
|
121
107
|
- lib/chef/sugar/core_extensions/array.rb
|
108
|
+
- lib/chef/sugar/core_extensions/object.rb
|
122
109
|
- lib/chef/sugar/core_extensions/string.rb
|
123
110
|
- lib/chef/sugar/data_bag.rb
|
124
111
|
- lib/chef/sugar/filters.rb
|
@@ -128,6 +115,7 @@ files:
|
|
128
115
|
- lib/chef/sugar/platform.rb
|
129
116
|
- lib/chef/sugar/platform_family.rb
|
130
117
|
- lib/chef/sugar/ruby.rb
|
118
|
+
- lib/chef/sugar/run_context.rb
|
131
119
|
- lib/chef/sugar/shell.rb
|
132
120
|
- lib/chef/sugar/vagrant.rb
|
133
121
|
- lib/chef/sugar/version.rb
|
@@ -139,6 +127,7 @@ files:
|
|
139
127
|
- spec/unit/chef/sugar/cloud_spec.rb
|
140
128
|
- spec/unit/chef/sugar/constraints_spec.rb
|
141
129
|
- spec/unit/chef/sugar/core_extensions/array_spec.rb
|
130
|
+
- spec/unit/chef/sugar/core_extensions/object_spec.rb
|
142
131
|
- spec/unit/chef/sugar/core_extensions/string_spec.rb
|
143
132
|
- spec/unit/chef/sugar/data_bag_spec.rb
|
144
133
|
- spec/unit/chef/sugar/ip_spec.rb
|
@@ -147,6 +136,7 @@ files:
|
|
147
136
|
- spec/unit/chef/sugar/platform_family_spec.rb
|
148
137
|
- spec/unit/chef/sugar/platform_spec.rb
|
149
138
|
- spec/unit/chef/sugar/ruby_spec.rb
|
139
|
+
- spec/unit/chef/sugar/run_context_spec.rb
|
150
140
|
- spec/unit/chef/sugar/shell_spec.rb
|
151
141
|
- spec/unit/chef/sugar/vagrant_spec.rb
|
152
142
|
- spec/unit/recipes/default_spec.rb
|
@@ -182,6 +172,7 @@ test_files:
|
|
182
172
|
- spec/unit/chef/sugar/cloud_spec.rb
|
183
173
|
- spec/unit/chef/sugar/constraints_spec.rb
|
184
174
|
- spec/unit/chef/sugar/core_extensions/array_spec.rb
|
175
|
+
- spec/unit/chef/sugar/core_extensions/object_spec.rb
|
185
176
|
- spec/unit/chef/sugar/core_extensions/string_spec.rb
|
186
177
|
- spec/unit/chef/sugar/data_bag_spec.rb
|
187
178
|
- spec/unit/chef/sugar/ip_spec.rb
|
@@ -190,6 +181,8 @@ test_files:
|
|
190
181
|
- spec/unit/chef/sugar/platform_family_spec.rb
|
191
182
|
- spec/unit/chef/sugar/platform_spec.rb
|
192
183
|
- spec/unit/chef/sugar/ruby_spec.rb
|
184
|
+
- spec/unit/chef/sugar/run_context_spec.rb
|
193
185
|
- spec/unit/chef/sugar/shell_spec.rb
|
194
186
|
- spec/unit/chef/sugar/vagrant_spec.rb
|
195
187
|
- spec/unit/recipes/default_spec.rb
|
188
|
+
has_rdoc:
|