Update chef-sugar to fix a conflict in Chef 16+
This commit is contained in:
149
cookbooks/chef-sugar/spec/unit/chef/sugar/cloud_spec.rb
Normal file
149
cookbooks/chef-sugar/spec/unit/chef/sugar/cloud_spec.rb
Normal file
@@ -0,0 +1,149 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Sugar::Cloud do
|
||||
it_behaves_like 'a chef sugar'
|
||||
|
||||
describe '#cloud?' do
|
||||
it 'is true when the node is on cloud' do
|
||||
node = { 'cloud' => nil }
|
||||
expect(described_class.cloud?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when the node is not on cloud' do
|
||||
node = {}
|
||||
expect(described_class.cloud?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#ec2?' do
|
||||
it 'is true when the node is on ec2' do
|
||||
node = { 'ec2' => nil }
|
||||
expect(described_class.ec2?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when the node is not on ec2' do
|
||||
node = {}
|
||||
expect(described_class.ec2?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#gce?' do
|
||||
it 'is true when the node is on gce' do
|
||||
node = { 'gce' => nil }
|
||||
expect(described_class.gce?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when the node is not on gce' do
|
||||
node = {}
|
||||
expect(described_class.gce?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#rackspace?' do
|
||||
it 'is true when the node is on rackspace' do
|
||||
node = { 'rackspace' => nil }
|
||||
expect(described_class.rackspace?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when the node is not on rackspace' do
|
||||
node = {}
|
||||
expect(described_class.rackspace?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#eucalyptus?' do
|
||||
it 'is true when the node is on eucalyptus' do
|
||||
node = { 'eucalyptus' => nil }
|
||||
expect(described_class.eucalyptus?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when the node is not on eucalyptus' do
|
||||
node = {}
|
||||
expect(described_class.eucalyptus?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#euca?' do
|
||||
it 'is true when the node is on eucalyptus' do
|
||||
node = { 'eucalyptus' => nil }
|
||||
expect(described_class.euca?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when the node is not on eucalyptus' do
|
||||
node = {}
|
||||
expect(described_class.euca?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#linode?' do
|
||||
it 'is true when the node is on linode' do
|
||||
node = { 'linode' => nil }
|
||||
expect(described_class.linode?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when the node is not on linode' do
|
||||
node = {}
|
||||
expect(described_class.linode?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#openstack?' do
|
||||
it 'is true when the node is on openstack' do
|
||||
node = { 'openstack' => nil }
|
||||
expect(described_class.openstack?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when the node is not on openstack' do
|
||||
node = {}
|
||||
expect(described_class.openstack?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#cloudstack?' do
|
||||
it 'is true when the node is on cloudstack' do
|
||||
node = { 'cloudstack' => nil }
|
||||
expect(described_class.cloudstack?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when the node is not on cloudstack' do
|
||||
node = {}
|
||||
expect(described_class.cloudstack?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#azure?' do
|
||||
it 'is true when the node is on azure' do
|
||||
node = { 'azure' => nil }
|
||||
expect(described_class.azure?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when the node is not on azure' do
|
||||
node = {}
|
||||
expect(described_class.azure?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#digitalocean?' do
|
||||
it 'is true when the node is on digitalocean' do
|
||||
node = { 'digital_ocean' => nil }
|
||||
expect(described_class.digitalocean?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when the node is not on digitalocean' do
|
||||
node = {}
|
||||
expect(described_class.digitalocean?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#softlayer?' do
|
||||
it 'is true when the node is on softlayer' do
|
||||
node = { 'softlayer' => nil }
|
||||
expect(described_class.softlayer?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when the node is not on softlayer' do
|
||||
node = {}
|
||||
expect(described_class.softlayer?(node)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,45 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Sugar::Constraints do
|
||||
describe '#version' do
|
||||
let(:version) { described_class.version('1.2.3') }
|
||||
|
||||
it 'returns a new version object' do
|
||||
expect(version).to be_a(Chef::Sugar::Constraints::Version)
|
||||
end
|
||||
|
||||
it 'behaves like a String' do
|
||||
expect(version).to be_a(String)
|
||||
end
|
||||
|
||||
it 'returns true with the version is satisifed' do
|
||||
expect(version).to be_satisfies('~> 1.2.0')
|
||||
end
|
||||
|
||||
it 'returns false when the version is not satisfed' do
|
||||
expect(version).to_not be_satisfies('~> 2.0.0')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#constraint' do
|
||||
let(:constraint) { described_class.constraint('~> 1.2.0') }
|
||||
|
||||
it 'returns a new constraint object' do
|
||||
expect(constraint).to be_a(Chef::Sugar::Constraints::Constraint)
|
||||
end
|
||||
|
||||
it 'returns true when the constraint is satisfied' do
|
||||
expect(constraint).to be_satisfied_by('1.2.3')
|
||||
end
|
||||
|
||||
it 'returns false when the constraint is not satisfied' do
|
||||
expect(constraint).to_not be_satisfied_by('2.0.0')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#chef_version' do
|
||||
it 'is a DSL method' do
|
||||
expect(Chef::Sugar::DSL).to be_method_defined(:chef_version)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
require 'spec_helper'
|
||||
require 'chef/sugar/core_extensions'
|
||||
|
||||
describe Array do
|
||||
describe '#satisfied_by?' do
|
||||
it 'includes the method' do
|
||||
expect(described_class).to be_method_defined(:satisfied_by?)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,62 @@
|
||||
require 'spec_helper'
|
||||
require 'chef/sugar/core_extensions'
|
||||
|
||||
describe Object do
|
||||
describe '#blank?' do
|
||||
it 'includes the method' do
|
||||
expect(described_class).to be_method_defined(:blank?)
|
||||
end
|
||||
|
||||
it 'returns true for nil' do
|
||||
expect(nil).to be_blank
|
||||
end
|
||||
|
||||
it 'returns true for false' do
|
||||
expect(false).to be_blank
|
||||
end
|
||||
|
||||
it 'returns true for the empty string' do
|
||||
expect('').to be_blank
|
||||
end
|
||||
|
||||
it 'returns true for the empty array' do
|
||||
expect([]).to be_blank
|
||||
end
|
||||
|
||||
it 'returns true for the empty hash' do
|
||||
expect({}).to be_blank
|
||||
end
|
||||
|
||||
it 'returns false for a non-empty string' do
|
||||
expect(' ').to_not be_blank
|
||||
end
|
||||
|
||||
it 'returns false for a non-empty string with unicode' do
|
||||
expect("\u00a0").to_not be_blank
|
||||
end
|
||||
|
||||
it 'returns false for a non-empty string with special characters' do
|
||||
expect("\n\t").to_not be_blank
|
||||
end
|
||||
|
||||
it 'returns false for any object' do
|
||||
expect(Object.new).to_not be_blank
|
||||
end
|
||||
|
||||
it 'returns false for true' do
|
||||
expect(true).to_not be_blank
|
||||
end
|
||||
|
||||
it 'returns false for a fixnum' do
|
||||
expect(1).to_not be_blank
|
||||
end
|
||||
|
||||
it 'returns false for an array with items' do
|
||||
expect(['foo']).to_not be_blank
|
||||
end
|
||||
|
||||
it 'returns false for an array with items' do
|
||||
expect({'foo' => 'bar'}).to_not be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,48 @@
|
||||
require 'spec_helper'
|
||||
require 'chef/sugar/core_extensions'
|
||||
|
||||
describe String do
|
||||
describe '#satisfies?' do
|
||||
it 'includes the method' do
|
||||
expect(described_class).to be_method_defined(:satisfies?)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#satisfied_by?' do
|
||||
it 'includes the method' do
|
||||
expect(described_class).to be_method_defined(:satisfied_by?)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#flush' do
|
||||
context 'when given a single-line string' do
|
||||
it 'strips trailing whitespace' do
|
||||
string = <<-EOH
|
||||
This is a string
|
||||
EOH
|
||||
expect(string.flush).to eq('This is a string')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when given a multi-line string' do
|
||||
it 'removes the leading number of whitespaces' do
|
||||
string = <<-EOH
|
||||
def method
|
||||
"This is a string!"
|
||||
end
|
||||
EOH
|
||||
expect(string.flush).to eq(%Q(def method\n "This is a string!"\nend))
|
||||
end
|
||||
|
||||
it 'leaves a newline when given' do
|
||||
string = <<-EOH
|
||||
def method
|
||||
"This is a string!"
|
||||
end
|
||||
|
||||
EOH
|
||||
expect(string.flush).to eq(%Q(def method\n "This is a string!"\nend\n))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
118
cookbooks/chef-sugar/spec/unit/chef/sugar/data_bag_spec.rb
Normal file
118
cookbooks/chef-sugar/spec/unit/chef/sugar/data_bag_spec.rb
Normal file
@@ -0,0 +1,118 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Sugar::DataBag do
|
||||
describe '#encrypted_data_bag_item' do
|
||||
before { allow(Chef::EncryptedDataBagItem).to receive(:load) }
|
||||
|
||||
it 'loads the encrypted data bag item' do
|
||||
expect(Chef::EncryptedDataBagItem).to receive(:load)
|
||||
.with('accounts', 'github', 'secret_key')
|
||||
|
||||
described_class.encrypted_data_bag_item('accounts', 'github', 'secret_key')
|
||||
end
|
||||
|
||||
context 'when Chef::Config is set' do
|
||||
it 'loads the secret key from the Chef::Config' do
|
||||
allow(Chef::Config).to receive(:[]).with(:encrypted_data_bag_secret).and_return('/data/path')
|
||||
allow(File).to receive(:read).with('/data/path').and_return('B@c0n')
|
||||
|
||||
expect(Chef::EncryptedDataBagItem).to receive(:load)
|
||||
.with('accounts', 'github', 'B@c0n')
|
||||
|
||||
described_class.encrypted_data_bag_item('accounts', 'github')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Chef::Config is not set and no value is given' do
|
||||
it 'raises an exception' do
|
||||
expect {
|
||||
described_class.encrypted_data_bag_item('accounts', 'github')
|
||||
}.to raise_error(Chef::Sugar::DataBag::EncryptedDataBagSecretNotGiven)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#encrypted_data_bag_item_for_environment' do
|
||||
let(:node) { double(:node, chef_environment: 'production') }
|
||||
|
||||
context 'when the environment exists' do
|
||||
it 'loads the data from the environment' do
|
||||
allow(Chef::EncryptedDataBagItem).to receive(:load).and_return(
|
||||
'production' => {
|
||||
'username' => 'sethvargo',
|
||||
'password' => 'bacon',
|
||||
}
|
||||
)
|
||||
|
||||
expect(described_class.encrypted_data_bag_item_for_environment(node, 'accounts', 'github', 'secret_key')).to eq(
|
||||
'password' => 'bacon',
|
||||
'username' => 'sethvargo',
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the environment does not exist' do
|
||||
it 'loads the data from the default bucket' do
|
||||
allow(Chef::EncryptedDataBagItem).to receive(:load).and_return(
|
||||
'staging' => {
|
||||
'username' => 'sethvargo',
|
||||
'password' => 'bacon',
|
||||
},
|
||||
'default' => {
|
||||
'username' => 'schisamo',
|
||||
'password' => 'ham',
|
||||
}
|
||||
)
|
||||
|
||||
expect(described_class.encrypted_data_bag_item_for_environment(node, 'accounts', 'github', 'secret_key')).to eq(
|
||||
'password' => 'ham',
|
||||
'username' => 'schisamo',
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#data_bag_item_for_environment' do
|
||||
let(:node) { double(:node, chef_environment: 'production') }
|
||||
|
||||
context 'when the environment exists' do
|
||||
it 'loads the data from the environment' do
|
||||
allow(Chef::DataBagItem).to receive(:load).and_return(
|
||||
'production' => {
|
||||
'username' => 'sethvargo',
|
||||
'comment' => 'loves bacon',
|
||||
},
|
||||
'default' => {
|
||||
'username' => 'schisamo',
|
||||
'comment' => 'more of a ham guy',
|
||||
}
|
||||
)
|
||||
|
||||
expect(described_class.data_bag_item_for_environment(node, 'accounts', 'github')).to eq(
|
||||
'comment' => 'loves bacon',
|
||||
'username' => 'sethvargo',
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the environment does not exist' do
|
||||
it 'loads the data from the default bucket' do
|
||||
allow(Chef::DataBagItem).to receive(:load).and_return(
|
||||
'staging' => {
|
||||
'username' => 'sethvargo',
|
||||
'comment' => 'loves bacon',
|
||||
},
|
||||
'default' => {
|
||||
'username' => 'schisamo',
|
||||
'comment' => 'more of a ham guy',
|
||||
}
|
||||
)
|
||||
|
||||
expect(described_class.data_bag_item_for_environment(node, 'accounts', 'github')).to eq(
|
||||
'comment' => 'more of a ham guy',
|
||||
'username' => 'schisamo',
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
70
cookbooks/chef-sugar/spec/unit/chef/sugar/init_spec.rb
Normal file
70
cookbooks/chef-sugar/spec/unit/chef/sugar/init_spec.rb
Normal file
@@ -0,0 +1,70 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Sugar::Init do
|
||||
it_behaves_like 'a chef sugar'
|
||||
|
||||
before(:each) do
|
||||
allow(IO).to receive(:read)
|
||||
.with("/proc/1/comm")
|
||||
.and_return("init")
|
||||
allow(File).to receive(:executable?)
|
||||
.with("/sbin/initctl")
|
||||
.and_return(false)
|
||||
allow(File).to receive(:executable?)
|
||||
.with("/sbin/runit-init")
|
||||
.and_return(false)
|
||||
end
|
||||
|
||||
describe '#systemd?' do
|
||||
systemctl_path = '/bin/systemctl'
|
||||
it "is true when #{systemctl_path} exists" do
|
||||
allow(File).to receive(:exist?)
|
||||
.with(systemctl_path)
|
||||
.and_return(true)
|
||||
|
||||
node = {}
|
||||
expect(described_class.systemd?(node)).to be true
|
||||
end
|
||||
|
||||
it "is false when #{systemctl_path} does not exist" do
|
||||
allow(File).to receive(:exist?)
|
||||
.with(systemctl_path)
|
||||
.and_return(false)
|
||||
|
||||
node = {}
|
||||
expect(described_class.systemd?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#upstart?' do
|
||||
it 'is true when /sbin/initctl is executable' do
|
||||
allow(File).to receive(:executable?)
|
||||
.with("/sbin/initctl")
|
||||
.and_return(true)
|
||||
|
||||
node = {}
|
||||
expect(described_class.upstart?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when /sbin/initctl is not executable' do
|
||||
node = {}
|
||||
expect(described_class.upstart?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#runit?' do
|
||||
it 'is true when /sbin/runit-init is executable' do
|
||||
allow(File).to receive(:executable?)
|
||||
.with("/sbin/runit-init")
|
||||
.and_return(true)
|
||||
|
||||
node = {}
|
||||
expect(described_class.runit?(node)).to be true
|
||||
end
|
||||
|
||||
it 'is false when /sbin/runit-init is not executable' do
|
||||
node = {}
|
||||
expect(described_class.runit?(node)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
53
cookbooks/chef-sugar/spec/unit/chef/sugar/ip_spec.rb
Normal file
53
cookbooks/chef-sugar/spec/unit/chef/sugar/ip_spec.rb
Normal file
@@ -0,0 +1,53 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Sugar::IP do
|
||||
it_behaves_like 'a chef sugar'
|
||||
|
||||
let(:node) { { 'ipaddress' => '1.2.3.4' } }
|
||||
let(:other) { { 'ipaddress' => '5.6.7.8' } }
|
||||
|
||||
context 'when not on a cloud' do
|
||||
it 'returns the default IP address' do
|
||||
expect(described_class.best_ip_for(node, other)).to eq(other['ipaddress'])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the target is on the cloud' do
|
||||
before do
|
||||
other['cloud'] = {}
|
||||
other['cloud']['provider'] = 'ec2'
|
||||
other['cloud']['local_ipv4'] = '9.10.11.12'
|
||||
other['cloud']['public_ipv4'] = '13.14.15.16'
|
||||
|
||||
node['cloud'] = nil
|
||||
end
|
||||
|
||||
context 'when the current node is not on the cloud' do
|
||||
it 'uses the public ipv4' do
|
||||
expect(described_class.best_ip_for(node, other)).to eq('13.14.15.16')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the current node is on a different cloud' do
|
||||
before do
|
||||
node['cloud'] = {}
|
||||
node['cloud']['provider'] = 'rackspace'
|
||||
end
|
||||
|
||||
it 'uses the public ipv4' do
|
||||
expect(described_class.best_ip_for(node, other)).to eq('13.14.15.16')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the current node is on the same cloud' do
|
||||
before do
|
||||
node['cloud'] = {}
|
||||
node['cloud']['provider'] = 'ec2'
|
||||
end
|
||||
|
||||
it 'uses the local ipv4' do
|
||||
expect(described_class.best_ip_for(node, other)).to eq('9.10.11.12')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
16
cookbooks/chef-sugar/spec/unit/chef/sugar/kernel_spec.rb
Normal file
16
cookbooks/chef-sugar/spec/unit/chef/sugar/kernel_spec.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Sugar::Kernel do
|
||||
describe '.require_chef_gem' do
|
||||
it 'raises an exception when the gem is not installed' do
|
||||
expect {
|
||||
described_class.require_chef_gem('bacon')
|
||||
}.to raise_error(Chef::Sugar::Kernel::ChefGemLoadError)
|
||||
end
|
||||
|
||||
it 'loads the gem' do
|
||||
allow(Chef::Sugar::Kernel).to receive(:require).and_return(true)
|
||||
expect(described_class.require_chef_gem('bacon')).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
172
cookbooks/chef-sugar/spec/unit/chef/sugar/node_spec.rb
Normal file
172
cookbooks/chef-sugar/spec/unit/chef/sugar/node_spec.rb
Normal file
@@ -0,0 +1,172 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Node do
|
||||
describe '#in?' do
|
||||
it 'returns true when the node is in the environment' do
|
||||
allow(subject).to receive(:chef_environment).and_return('production')
|
||||
expect(subject.in?('production')).to be true
|
||||
expect(subject.in?(/production$/)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the node is not in the environment' do
|
||||
allow(subject).to receive(:chef_environment).and_return('staging')
|
||||
expect(subject.in?('production')).to be false
|
||||
expect(subject.in?(/production$/)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#deep_fetch' do
|
||||
let(:node) { described_class.new }
|
||||
before { node.default['apache2']['config']['root'] = '/var/www' }
|
||||
|
||||
it 'fetches a deeply nested attribute' do
|
||||
expect(node.deep_fetch('apache2', 'config', 'root')).to eq('/var/www')
|
||||
end
|
||||
|
||||
it 'ignores symbols, strings, etc' do
|
||||
expect(node.deep_fetch(:apache2, :config, :root)).to eq('/var/www')
|
||||
end
|
||||
|
||||
it 'safely returns nil if a key does not exist' do
|
||||
expect(node.deep_fetch(:apache2, :not_real, :nested, :yup)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '#deep_fetch!' do
|
||||
let(:node) { described_class.new }
|
||||
before { node.default['apache2']['config']['root'] = '/var/www' }
|
||||
|
||||
it 'fetches a deeply nested attribute' do
|
||||
expect(node.deep_fetch!('apache2', 'config', 'root')).to eq('/var/www')
|
||||
end
|
||||
|
||||
it 'ignores symbols, strings, etc' do
|
||||
expect(node.deep_fetch!(:apache2, :config, :root)).to eq('/var/www')
|
||||
end
|
||||
|
||||
it 'raises an error if a key does not exist' do
|
||||
expect {
|
||||
node.deep_fetch!(:apache2, :not_real)
|
||||
}.to raise_error(Chef::Node::AttributeDoesNotExistError) { |e|
|
||||
expect(e.message).to eq(<<-EOH.gsub(/^ {10}/, ''))
|
||||
No attribute `node['apache2']['not_real']' exists on
|
||||
the current node. Specifically the `not_real' attribute is not
|
||||
defined. Please make sure you have spelled everything correctly.
|
||||
EOH
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe '#namespace' do
|
||||
let(:node) { described_class.new }
|
||||
|
||||
it 'defines the attributes' do
|
||||
node.instance_eval do
|
||||
namespace 'apache2' do
|
||||
namespace 'config' do
|
||||
root '/var/www'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
expect(node.default).to eq({
|
||||
'apache2' => {
|
||||
'config' => { 'root' => '/var/www' }
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
it 'accepts multiple attributes' do
|
||||
node.instance_eval do
|
||||
namespace 'apache2', 'config' do
|
||||
root '/var/www'
|
||||
end
|
||||
end
|
||||
|
||||
expect(node.default).to eq({
|
||||
'apache2' => {
|
||||
'config' => { 'root' => '/var/www' }
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
it 'accepts attribute precedence levels' do
|
||||
node.instance_eval do
|
||||
namespace 'apache2', precedence: normal do
|
||||
namespace 'config', precedence: override do
|
||||
root '/var/www'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
expect(node.override).to eq({
|
||||
'apache2' => {
|
||||
'config' => { 'root' => '/var/www' }
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
it 'maintains precedence level into nested calls' do
|
||||
node.instance_eval do
|
||||
namespace 'apache2', precedence: override do
|
||||
namespace 'config' do
|
||||
root '/var/www'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
expect(node.override).to eq({
|
||||
'apache2' => {
|
||||
'config' => { 'root' => '/var/www' }
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
it 'resets precedence to default in subsequent non-nested calls' do
|
||||
node.instance_eval do
|
||||
namespace 'apache2', precedence: override do
|
||||
namespace 'config' do
|
||||
root '/var/www'
|
||||
end
|
||||
end
|
||||
|
||||
namespace 'php' do
|
||||
version '5.3'
|
||||
end
|
||||
end
|
||||
|
||||
expect(node.override).to eq({
|
||||
'apache2' => {
|
||||
'config' => { 'root' => '/var/www' }
|
||||
}
|
||||
})
|
||||
|
||||
expect(node.default).to eq({
|
||||
'php' => {
|
||||
'version' => '5.3'
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
it 'can access attributes within itself' do
|
||||
node.instance_eval do
|
||||
namespace 'apache2' do
|
||||
namespace 'config' do
|
||||
root '/var/www'
|
||||
ssl File.join(root, 'ssl')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
expect(node.default).to eq({
|
||||
'apache2' => {
|
||||
'config' => {
|
||||
'root' => '/var/www',
|
||||
'ssl' => '/var/www/ssl',
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
174
cookbooks/chef-sugar/spec/unit/chef/sugar/platform_spec.rb
Normal file
174
cookbooks/chef-sugar/spec/unit/chef/sugar/platform_spec.rb
Normal file
@@ -0,0 +1,174 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Sugar::Platform do
|
||||
it_behaves_like 'a chef sugar'
|
||||
|
||||
describe '#platform_version' do
|
||||
it 'returns the platform version' do
|
||||
node = { 'platform_version' => '1.2.3' }
|
||||
expect(described_class.platform_version(node)).to eq('1.2.3')
|
||||
end
|
||||
end
|
||||
|
||||
context 'dynamic matchers' do
|
||||
describe '#ubuntu_after_lucid?' do
|
||||
it 'returns true when the version is later than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.10' }
|
||||
expect(described_class.ubuntu_after_lucid?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the version is 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.04' }
|
||||
expect(described_class.ubuntu_after_lucid?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the version is a patch release higher than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.04.4' }
|
||||
expect(described_class.ubuntu_after_lucid?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the version is less than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '9.10' }
|
||||
expect(described_class.ubuntu_after_lucid?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#ubuntu_after_or_at_lucid?' do
|
||||
it 'returns true when the version is later than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.10' }
|
||||
expect(described_class.ubuntu_after_or_at_lucid?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns true when the version is 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.04' }
|
||||
expect(described_class.ubuntu_after_or_at_lucid?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns true when the version is a patch release higher than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.04.4' }
|
||||
expect(described_class.ubuntu_after_or_at_lucid?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the version is less than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '9.10' }
|
||||
expect(described_class.ubuntu_after_or_at_lucid?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#ubuntu_lucid?' do
|
||||
it 'returns false when the version is later than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.10' }
|
||||
expect(described_class.ubuntu_lucid?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns true when the version is 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.04' }
|
||||
expect(described_class.ubuntu_lucid?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns true when the version is a patch release higher than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.04.4' }
|
||||
expect(described_class.ubuntu_lucid?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the version is less than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '9.10' }
|
||||
expect(described_class.ubuntu_lucid?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#ubuntu_before_lucid?' do
|
||||
it 'returns false when the version is later than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.10' }
|
||||
expect(described_class.ubuntu_before_lucid?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the version is 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.04' }
|
||||
expect(described_class.ubuntu_before_lucid?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the version is a patch release higher than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.04.4' }
|
||||
expect(described_class.ubuntu_before_lucid?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns true when the version is less than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '9.10' }
|
||||
expect(described_class.ubuntu_before_lucid?(node)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#ubuntu_before_or_at_lucid?' do
|
||||
it 'returns false when the version is later than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.10' }
|
||||
expect(described_class.ubuntu_before_or_at_lucid?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns true when the version is 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.04' }
|
||||
expect(described_class.ubuntu_before_or_at_lucid?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns true when the version is a patch release higher than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '10.04.4' }
|
||||
expect(described_class.ubuntu_before_or_at_lucid?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns true when the version is less than 10.04' do
|
||||
node = { 'platform' => 'ubuntu', 'platform_version' => '9.10' }
|
||||
expect(described_class.ubuntu_before_or_at_lucid?(node)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#centos_final?' do
|
||||
it 'returns true when the version is a subset of the major' do
|
||||
node = { 'platform' => 'centos', 'platform_version' => '6.8' }
|
||||
expect(described_class.centos_final?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the version is not the major' do
|
||||
node = { 'platform' => 'centos', 'platform_version' => '7.4' }
|
||||
expect(described_class.centos_final?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#debian_wheezy?' do
|
||||
it 'returns true when the version is a subset of the major' do
|
||||
node = { 'platform' => 'debian', 'platform_version' => '7.1' }
|
||||
expect(described_class.debian_wheezy?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the version is not the major' do
|
||||
node = { 'platform' => 'debian', 'platform_version' => '6.1' }
|
||||
expect(described_class.debian_wheezy?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#debian_before_wheezy?' do
|
||||
it 'returns true when the version is a less than the major' do
|
||||
node = { 'platform' => 'debian', 'platform_version' => '6.5' }
|
||||
expect(described_class.debian_before_wheezy?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the version is not less than the major' do
|
||||
node = { 'platform' => 'debian', 'platform_version' => '8.0' }
|
||||
expect(described_class.debian_before_wheezy?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#solaris_10?' do
|
||||
it 'returns true when the version is 5.10' do
|
||||
node = { 'platform' => 'solaris2', 'platform_version' => '5.10' }
|
||||
expect(described_class.solaris_10?(node)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#solaris_11?' do
|
||||
it 'returns true when the version is 5.11' do
|
||||
node = { 'platform' => 'solaris2', 'platform_version' => '5.11' }
|
||||
expect(described_class.solaris_11?(node)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
39
cookbooks/chef-sugar/spec/unit/chef/sugar/ruby_spec.rb
Normal file
39
cookbooks/chef-sugar/spec/unit/chef/sugar/ruby_spec.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Sugar::Ruby do
|
||||
it_behaves_like 'a chef sugar'
|
||||
|
||||
describe '#ruby_20?' do
|
||||
it 'returns true when the ruby version is 2.0' do
|
||||
node = { 'languages' => { 'ruby' => { 'version' => '2.0.0' } } }
|
||||
expect(described_class.ruby_20?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns true when the ruby version is less than 2.0' do
|
||||
node = { 'languages' => { 'ruby' => { 'version' => '1.9.3' } } }
|
||||
expect(described_class.ruby_20?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the ruby version is higher than 2.0' do
|
||||
node = { 'languages' => { 'ruby' => { 'version' => '3.0.0' } } }
|
||||
expect(described_class.ruby_20?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#ruby_19?' do
|
||||
it 'returns true when the ruby version is 1.9' do
|
||||
node = { 'languages' => { 'ruby' => { 'version' => '1.9.1' } } }
|
||||
expect(described_class.ruby_19?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns true when the ruby version is less than 1.9' do
|
||||
node = { 'languages' => { 'ruby' => { 'version' => '1.8.7' } } }
|
||||
expect(described_class.ruby_19?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the ruby version is higher than 1.9' do
|
||||
node = { 'languages' => { 'ruby' => { 'version' => '2.0.0' } } }
|
||||
expect(described_class.ruby_19?(node)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,19 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Sugar::RunContext do
|
||||
it_behaves_like 'a chef sugar'
|
||||
|
||||
describe '#includes_recipe?' do
|
||||
let(:node) { double(Chef::Node) }
|
||||
|
||||
it 'returns true when the recipe exists' do
|
||||
allow(node).to receive(:recipe?).and_return(true)
|
||||
expect(described_class.includes_recipe?(node, 'foo')).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the recipe does not exist' do
|
||||
allow(node).to receive(:recipe?).and_return(false)
|
||||
expect(described_class.includes_recipe?(node, 'bar')).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
104
cookbooks/chef-sugar/spec/unit/chef/sugar/shell_spec.rb
Normal file
104
cookbooks/chef-sugar/spec/unit/chef/sugar/shell_spec.rb
Normal file
@@ -0,0 +1,104 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Sugar::Shell do
|
||||
describe '#which', :pre_chef16_only do
|
||||
it 'returns the first executable matching the command' do
|
||||
allow(File).to receive(:executable?).and_return(false)
|
||||
allow(File).to receive(:executable?).with('/usr/bin/mongo').and_return(true)
|
||||
expect(described_class.which('mongo')).to eq('/usr/bin/mongo')
|
||||
end
|
||||
|
||||
it 'returns nil when no command is found' do
|
||||
allow(File).to receive(:executable?).and_return(false)
|
||||
expect(described_class.which('node')).to be_nil
|
||||
end
|
||||
|
||||
context 'with an absolute path' do
|
||||
it 'returns the executable if it exists' do
|
||||
allow(File).to receive(:executable?).with('/usr/local/bin/bash').and_return(true)
|
||||
expect(described_class.which('/usr/local/bin/bash')).to eq('/usr/local/bin/bash')
|
||||
end
|
||||
|
||||
it 'returns nil when the file is not executable' do
|
||||
allow(File).to receive(:executable?).with('/usr/local/bin/bash').and_return(false)
|
||||
expect(described_class.which('/usr/local/bin/bash')).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dev_null' do
|
||||
it 'returns NUL on Windows' do
|
||||
node = { 'platform_family' => 'windows' }
|
||||
expect(described_class.dev_null(node)).to eq('NUL')
|
||||
end
|
||||
|
||||
it 'returns /dev/null on Linux' do
|
||||
node = { 'platform_family' => 'debian' }
|
||||
expect(described_class.dev_null(node)).to eq('/dev/null')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#installed?' do
|
||||
it 'returns true if the given binary exists' do
|
||||
allow(described_class).to receive(:which).and_return(nil)
|
||||
allow(described_class).to receive(:which).with('mongo').and_return(true)
|
||||
expect(described_class.installed?('mongo')).to be true
|
||||
end
|
||||
|
||||
it 'returns false if the given binary does not exist' do
|
||||
allow(described_class).to receive(:which).with('node').and_return(nil)
|
||||
expect(described_class.installed?('node')).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#installed_at_version?' do
|
||||
it 'returns true if the command is installed at the correct version' do
|
||||
allow(described_class).to receive(:which).and_return(true)
|
||||
allow(described_class).to receive(:version_for).and_return('1.2.3')
|
||||
expect(described_class.installed_at_version?('mongo', '1.2.3')).to be true
|
||||
end
|
||||
|
||||
it 'returns true if the command is installed at the correct version and has additional output' do
|
||||
allow(described_class).to receive(:which).and_return(true)
|
||||
allow(described_class).to receive(:version_for).and_return('Mongo DB version 1.2.3. Some other text.')
|
||||
expect(described_class.installed_at_version?('mongo', '1.2.3')).to be true
|
||||
end
|
||||
|
||||
it 'returns true if the command is installed at the correct version with a regex' do
|
||||
allow(described_class).to receive(:which).and_return(true)
|
||||
allow(described_class).to receive(:version_for).and_return('1.2.3')
|
||||
expect(described_class.installed_at_version?('mongo', /1\.2/)).to be true
|
||||
end
|
||||
|
||||
it 'returns false if the command is installed at the wrong version' do
|
||||
allow(described_class).to receive(:which).and_return(true)
|
||||
allow(described_class).to receive(:version_for).and_return('1.2.3')
|
||||
expect(described_class.installed_at_version?('mongo', '4.5.6')).to be false
|
||||
end
|
||||
|
||||
it 'returns false if #version_for is nil' do
|
||||
allow(described_class).to receive(:which).and_return(true)
|
||||
allow(described_class).to receive(:version_for).and_return(nil)
|
||||
expect(described_class.installed_at_version?('mongo', '4.5.6')).to be false
|
||||
end
|
||||
|
||||
it 'returns false if the command is not installed' do
|
||||
allow(described_class).to receive(:which).and_return(nil)
|
||||
expect(described_class.installed_at_version?('mongo', '1.0.0')).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#version_for' do
|
||||
let(:shell_out) { double('shell_out', run_command: nil, error!: nil, stdout: '1.2.3', stderr: 'Oh no!') }
|
||||
before { allow(Mixlib::ShellOut).to receive(:new).and_return(shell_out) }
|
||||
|
||||
it 'runs the thing in shellout' do
|
||||
expect(Mixlib::ShellOut).to receive(:new).with('mongo --version')
|
||||
described_class.version_for('mongo')
|
||||
end
|
||||
|
||||
it 'returns the combined stdout and stderr' do
|
||||
expect(described_class.version_for('mongo')).to eq("1.2.3\nOh no!")
|
||||
end
|
||||
end
|
||||
end
|
||||
37
cookbooks/chef-sugar/spec/unit/chef/sugar/vagrant_spec.rb
Normal file
37
cookbooks/chef-sugar/spec/unit/chef/sugar/vagrant_spec.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Sugar::Vagrant do
|
||||
it_behaves_like 'a chef sugar'
|
||||
|
||||
describe '#vagrant?' do
|
||||
it 'returns true when the machine is on vagrant' do
|
||||
node = { 'vagrant' => {} }
|
||||
expect(described_class.vagrant?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns true when the domain is vagrantup.com' do
|
||||
node = { 'domain' => 'bacon.vagrantup.com' }
|
||||
expect(described_class.vagrant?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the domain is nil' do
|
||||
node = { 'domain' => nil }
|
||||
expect(described_class.vagrant?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the domain is not vagrantup.com' do
|
||||
node = { 'domain' => 'sethvargo.com' }
|
||||
expect(described_class.vagrant?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns true when the vagrant user exists on the system' do
|
||||
node = { 'etc' => { 'passwd' => { 'vagrant' => {} } } }
|
||||
expect(described_class.vagrant?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the machine is not on vagrant' do
|
||||
node = {}
|
||||
expect(described_class.vagrant?(node)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
135
cookbooks/chef-sugar/spec/unit/chef/sugar/virtualization_spec.rb
Normal file
135
cookbooks/chef-sugar/spec/unit/chef/sugar/virtualization_spec.rb
Normal file
@@ -0,0 +1,135 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Chef::Sugar::Virtualization do
|
||||
it_behaves_like 'a chef sugar'
|
||||
|
||||
describe '#kvm?' do
|
||||
it 'returns true when the machine is under kvm' do
|
||||
node = { 'virtualization' => { 'system' => 'kvm' } }
|
||||
expect(described_class.kvm?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the virtual machine is not under kvm' do
|
||||
node = { 'virtualization' => { 'system' => 'vbox' } }
|
||||
expect(described_class.kvm?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the machine is not virtual' do
|
||||
node = {}
|
||||
expect(described_class.kvm?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#lxc?' do
|
||||
it 'returns true when the machine is a linux contianer' do
|
||||
node = { 'virtualization' => { 'system' => 'lxc' } }
|
||||
expect(described_class.lxc?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the virtual machine is not lxc' do
|
||||
node = { 'virtualization' => { 'system' => 'vbox' } }
|
||||
expect(described_class.lxc?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the machine is not virtual' do
|
||||
node = {}
|
||||
expect(described_class.lxc?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#parallels?' do
|
||||
it 'returns true when the machine is under parallels' do
|
||||
node = { 'virtualization' => { 'system' => 'parallels' } }
|
||||
expect(described_class.parallels?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the virtual machine is not under parallels' do
|
||||
node = { 'virtualization' => { 'system' => 'kvm' } }
|
||||
expect(described_class.parallels?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the machine is not virtual' do
|
||||
node = {}
|
||||
expect(described_class.parallels?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#virtualbox?' do
|
||||
it 'returns true when the machine is under virtualbox' do
|
||||
node = { 'virtualization' => { 'system' => 'vbox' } }
|
||||
expect(described_class.virtualbox?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the virtual machine is not under virtualbox' do
|
||||
node = { 'virtualization' => { 'system' => 'kvm' } }
|
||||
expect(described_class.virtualbox?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the machine is not virtual' do
|
||||
node = {}
|
||||
expect(described_class.virtualbox?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#vmware?' do
|
||||
it 'returns true when the machine is under vmware' do
|
||||
node = { 'virtualization' => { 'system' => 'vmware' } }
|
||||
expect(described_class.vmware?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the virtual machine is not under vmware' do
|
||||
node = { 'virtualization' => { 'system' => 'vbox' } }
|
||||
expect(described_class.vmware?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the machine is not virtual' do
|
||||
node = {}
|
||||
expect(described_class.vmware?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#openvz?' do
|
||||
it 'returns true when the machine is under openvz' do
|
||||
node = { 'virtualization' => { 'system' => 'openvz' } }
|
||||
expect(described_class.openvz?(node)).to be true
|
||||
end
|
||||
|
||||
it 'returns false when the virtual machine is not under openvz' do
|
||||
node = { 'virtualization' => { 'system' => 'kvm' } }
|
||||
expect(described_class.openvz?(node)).to be false
|
||||
end
|
||||
|
||||
it 'returns false when the machine is not virtual' do
|
||||
node = {}
|
||||
expect(described_class.openvz?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#virtual?' do
|
||||
it 'returns true when the machine is under a supported virtualization provider' do
|
||||
%w(openvz vmware vbox lxc kvm).each do |host|
|
||||
node = { 'virtualization' => { 'system' => host } }
|
||||
expect(described_class.virtual?(node)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns false when the machine is not virtual' do
|
||||
node = {}
|
||||
expect(described_class.virtual?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#physical?' do
|
||||
it 'returns false when the machine is under a supported virtualization provider' do
|
||||
%w(openvz vmware vbox lxc kvm).each do |host|
|
||||
node = { 'virtualization' => { 'system' => host } }
|
||||
expect(described_class.physical?(node)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns true when the machine is not virtual' do
|
||||
node = {}
|
||||
expect(described_class.physical?(node)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
9
cookbooks/chef-sugar/spec/unit/recipes/default_spec.rb
Normal file
9
cookbooks/chef-sugar/spec/unit/recipes/default_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'chef-sugar::default' do
|
||||
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe) }
|
||||
|
||||
it 'converges successfully' do
|
||||
expect { :chef_run }.to_not raise_error
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user