Refactoring chefspec tests

Change-Id: I35dfca684039512e2a238466ff7df5f3fd34d956
Addresses: blueprint refactor-spec-files
Closes-Bug: 1282996
This commit is contained in:
galstrom21 2014-02-20 18:28:28 +00:00
parent 4ad20f5e56
commit ffe0d05a0d
15 changed files with 574 additions and 539 deletions

@ -15,7 +15,7 @@ recipe 'openstack-common::sysctl', 'Configures sysctl settings'
supports os supports os
end end
depends 'apt' depends 'apt', '~> 2.3.8'
depends 'database' depends 'database'
depends 'yum', '~> 3.0' depends 'yum', '~> 3.0'
depends 'yum-epel' depends 'yum-epel'

@ -4,27 +4,29 @@ require_relative 'spec_helper'
describe 'openstack-common::ceph_client' do describe 'openstack-common::ceph_client' do
describe 'ubuntu' do describe 'ubuntu' do
before do let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
opts = ::UBUNTU_OPTS.merge(step_into: ['apt_repository']) let(:node) { runner.node }
@chef_run = ::ChefSpec::Runner.new(opts) do |n| let(:chef_run) do
n.set['openstack']['ceph']['global']['fsid'] = '9e5038a9-4329-4cad-8c24-0813a49d1125' node.set['openstack']['ceph']['global']['fsid'] = '9e5038a9-4329-4cad-8c24-0813a49d1125'
n.set['openstack']['ceph']['global']['mon_initial_members'] = %w{ 10.0.1.10 10.0.1.20 } node.set['openstack']['ceph']['global']['mon_initial_members'] = %w{ 10.0.1.10 10.0.1.20 }
n.set['openstack']['ceph']['global']['mon_hosts'] = %w{ mon01 mon02 } node.set['openstack']['ceph']['global']['mon_hosts'] = %w{ mon01 mon02 }
n.set['lsb']['codename'] = 'precise' node.set['lsb']['codename'] = 'precise'
end
@filename = '/etc/ceph/ceph.conf' runner.converge(described_recipe)
@chef_run.converge 'openstack-common::ceph_client'
end end
let(:file) { chef_run.template('/etc/ceph/ceph.conf') }
it 'configures ceph repository' do it 'configures ceph repository' do
file = '/etc/apt/sources.list.d/ceph.list' # Using cookbook(apt) LWRP custom matcher
expected = 'deb http://ceph.com/debian-emperor precise main' # https://github.com/sethvargo/chefspec#packaging-custom-matchers
expect(chef_run).to add_apt_repository('ceph').with(
expect(@chef_run).to render_file(file).with_content(expected) uri: 'http://ceph.com/debian-emperor',
components: ['main'],
distribution: 'precise')
end end
it 'creates the /etc/ceph/ceph.conf file' do it 'creates the /etc/ceph/ceph.conf file' do
expect(@chef_run).to create_template(@filename).with( expect(chef_run).to create_template(file.name).with(
owner: 'root', owner: 'root',
group: 'root', group: 'root',
mode: '644' mode: '644'
@ -36,9 +38,8 @@ describe 'openstack-common::ceph_client' do
/^fsid = 9e5038a9-4329-4cad-8c24-0813a49d1125$/, /^fsid = 9e5038a9-4329-4cad-8c24-0813a49d1125$/,
/^mon_initial_members = 10.0.1.10, 10.0.1.20$/, /^mon_initial_members = 10.0.1.10, 10.0.1.20$/,
/^mon_hosts = mon01, mon02$/].each do |content| /^mon_hosts = mon01, mon02$/].each do |content|
expect(@chef_run).to render_file(@filename).with_content(content) expect(chef_run).to render_file(file.name).with_content(content)
end end
end end
end end
end end

@ -1,29 +1,35 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'spec_helper' require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'database' require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'database'
describe ::Openstack do describe 'openstack-common::default' do
before do describe 'Openstack Database' do
@chef_run = ::ChefSpec::Runner.new ::CHEFSPEC_OPTS let(:runner) { ChefSpec::Runner.new(CHEFSPEC_OPTS) }
@chef_run.converge 'openstack-common::default' let(:node) { runner.node }
@subject = ::Object.new.extend ::Openstack let(:chef_run) { runner.converge(described_recipe) }
@subject.stub :include_recipe let(:subject) { Object.new.extend(Openstack) }
end
include_context 'library-stubs'
describe '#db_create_with_user' do describe '#db_create_with_user' do
before do
subject.stub(:include_recipe)
.with('database::mysql')
.and_return('')
end
it 'returns nil when no such service was found' do it 'returns nil when no such service was found' do
@subject.stub(:node).and_return @chef_run.node expect(
@subject.db_create_with_user('nonexisting', 'user', 'pass').should be_nil subject.db_create_with_user('nonexisting', 'user', 'pass')
).to be_nil
end end
it 'returns db info and creates database with user when service found' do it 'returns db info and creates database with user when service found' do
@subject.stub(:database).and_return {} subject.stub(:database).and_return({})
@subject.stub(:database_user).and_return {} subject.stub(:database_user).and_return({})
@subject.stub(:node).and_return @chef_run.node result = subject.db_create_with_user('compute', 'user', 'pass')
result = @subject.db_create_with_user 'compute', 'user', 'pass' expect(result['host']).to eq('127.0.0.1')
result['host'].should eq('127.0.0.1') expect(result['port']).to eq('3306')
result['port'].should eq('3306')
end end
it 'creates database' do it 'creates database' do
@ -39,3 +45,4 @@ describe ::Openstack do
end end
end end
end end
end

@ -1,40 +1,46 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'spec_helper'
describe 'openstack-common::default' do describe 'openstack-common::default' do
describe 'rhel-rdo' do describe 'rhel-rdo' do
before do let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
@chef_run = ::ChefSpec::Runner.new(::REDHAT_OPTS) do |n| let(:node) { runner.node }
n.set['openstack']['release'] = 'testrelease' let(:chef_run) do
end node.set['openstack']['release'] = 'testrelease'
@chef_run.converge 'openstack-common::default'
runner.converge(described_recipe)
end end
it 'configures RDO yum repository' do context 'enabling RDO' do
repo_name = 'RDO-testrelease' before do
expect(@chef_run).to add_yum_repository(repo_name) node.set['openstack']['yum']['rdo_enabled'] = true
end
it 'adds RDO yum repository' do
# Using cookbook(yum) LWRP custom matcher
# https://github.com/sethvargo/chefspec#packaging-custom-matchers
expect(chef_run).to add_yum_repository('RDO-testrelease')
end end
it 'includes yum-epel recipe' do it 'includes yum-epel recipe' do
expect(@chef_run).to include_recipe('yum-epel') expect(chef_run).to include_recipe('yum-epel')
end end
end end
describe 'rhel-no-rdo' do context 'disabling RDO' do
before do before do
@chef_run = ::ChefSpec::Runner.new(::REDHAT_OPTS) do |n| node.set['openstack']['yum']['rdo_enabled'] = false
n.set['openstack']['release'] = 'testrelease'
n.set['openstack']['yum']['rdo_enabled'] = false
end
@chef_run.converge 'openstack-common::default'
end end
it 'configures RDO yum repository' do it 'removes RDO yum repository' do
repo_name = 'RDO-testrelease' # Using cookbook(yum) LWRP custom matcher
expect(@chef_run).to remove_yum_repository(repo_name) # https://github.com/sethvargo/chefspec#packaging-custom-matchers
expect(chef_run).to remove_yum_repository('RDO-testrelease')
end end
it 'does not include yum-epel recipe' do it 'does not include yum-epel recipe' do
expect(@chef_run).to_not include_recipe('yum-epel') expect(chef_run).to_not include_recipe('yum-epel')
end
end end
end end
end end

@ -1,5 +1,4 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-common::default' do describe 'openstack-common::default' do

@ -1,26 +1,26 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-common::default' do describe 'openstack-common::default' do
describe 'ubuntu' do describe 'ubuntu' do
before do let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
opts = ::UBUNTU_OPTS.merge step_into: ['apt_repository'] let(:node) { runner.node }
@chef_run = ::ChefSpec::Runner.new(opts) do |n| let(:chef_run) do
n.set['lsb']['codename'] = 'precise' node.set['lsb']['codename'] = 'precise'
end
@chef_run.converge 'openstack-common::default' runner.converge(described_recipe)
end end
it 'installs ubuntu-cloud-keyring package' do it 'installs ubuntu-cloud-keyring package' do
expect(@chef_run).to install_package 'ubuntu-cloud-keyring' expect(chef_run).to install_package 'ubuntu-cloud-keyring'
end end
it 'configures openstack repository' do it 'configures openstack repository' do
file = '/etc/apt/sources.list.d/openstack-ppa.list' # Using cookbook(apt) LWRP custom matcher
expected = 'deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/havana main' # https://github.com/sethvargo/chefspec#packaging-custom-matchers
expect(chef_run).to add_apt_repository('openstack-ppa').with(
expect(@chef_run).to render_file(file).with_content(expected) uri: 'http://ubuntu-cloud.archive.canonical.com/ubuntu',
components: ['precise-updates/havana', 'main'])
end end
end end
end end

@ -1,24 +1,29 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'spec_helper' require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'endpoints' require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'endpoints'
describe ::Openstack do describe 'openstack-common::set_endpoints_by_interface' do
before do describe 'Openstack endpoints' do
@chef_run = ::ChefSpec::Runner.new ::CHEFSPEC_OPTS let(:runner) { ChefSpec::Runner.new(CHEFSPEC_OPTS) }
@chef_run.converge 'openstack-common::set_endpoints_by_interface' let(:node) { runner.node }
@subject = ::Object.new.extend ::Openstack let(:chef_run) { runner.converge(described_recipe) }
end let(:subject) { Object.new.extend(Openstack) }
describe '#endpoint' do describe '#endpoint' do
it 'returns nil when no openstack.endpoints not in node attrs' do it 'returns nil when no openstack.endpoints not in node attrs' do
@subject.stub(:node).and_return {} subject.stub(:node).and_return({})
@subject.endpoint('nonexisting').should be_nil expect(
subject.endpoint('nonexisting')
).to be_nil
end end
it 'returns nil when no such endpoint was found' do it 'returns nil when no such endpoint was found' do
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(node)
@subject.endpoint('nonexisting').should be_nil expect(
subject.endpoint('nonexisting')
).to be_nil
end end
it 'handles a URI needing escaped' do it 'handles a URI needing escaped' do
uri_hash = { uri_hash = {
'openstack' => { 'openstack' => {
@ -29,10 +34,12 @@ describe ::Openstack do
} }
} }
} }
@subject.stub(:node).and_return uri_hash subject.stub(:node).and_return(uri_hash)
result = @subject.endpoint 'compute-api' expect(
result.path.should == '/v2/%25(tenant_id)s' subject.endpoint('compute-api').path
).to eq('/v2/%25(tenant_id)s')
end end
it 'returns endpoint URI object when uri key in endpoint hash' do it 'returns endpoint URI object when uri key in endpoint hash' do
uri_hash = { uri_hash = {
'openstack' => { 'openstack' => {
@ -43,10 +50,12 @@ describe ::Openstack do
} }
} }
} }
@subject.stub(:node).and_return uri_hash subject.stub(:node).and_return(uri_hash)
result = @subject.endpoint 'compute-api' expect(
result.port.should == 8080 subject.endpoint('compute-api').port
).to eq(8080)
end end
it 'returns endpoint URI string when uri key in endpoint hash and host also in hash' do it 'returns endpoint URI string when uri key in endpoint hash and host also in hash' do
uri_hash = { uri_hash = {
'openstack' => { 'openstack' => {
@ -58,11 +67,13 @@ describe ::Openstack do
} }
} }
} }
@subject.stub(:node).and_return uri_hash subject.stub(:node).and_return(uri_hash)
@subject.endpoint('compute-api').to_s.should == 'http://localhost' expect(subject.endpoint('compute-api').to_s).to eq('http://localhost')
end end
it 'returns endpoint URI object when uri key not in endpoint hash but host is in hash' do it 'returns endpoint URI object when uri key not in endpoint hash but host is in hash' do
@subject.should_receive(:uri_from_hash).with('host' => 'localhost', 'port' => '8080') pending 'TODO: implement'
subject.should_receive(:uri_from_hash).with('host' => 'localhost', 'port' => '8080')
uri_hash = { uri_hash = {
'openstack' => { 'openstack' => {
'endpoints' => { 'endpoints' => {
@ -73,14 +84,13 @@ describe ::Openstack do
} }
} }
} }
@subject.stub(:node).and_return uri_hash subject.stub(:node).and_return(uri_hash)
@subject.endpoint 'compute-api' subject.endpoint 'compute-api'
end end
it 'endpoints recipe bind_interface sets host' do it 'endpoints recipe bind_interface sets host' do
@subject.stub('address_for').and_return '10.0.0.100' node.set['openstack']['endpoints']['identity-api']['bind_interface'] = 'eth0'
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS node.set['network'] = {
chef_run.node.set['openstack']['endpoints']['identity-api']['bind_interface'] = 'eth0'
chef_run.node.set['network'] = {
'interfaces' => { 'interfaces' => {
'lo' => { 'lo' => {
'addresses' => { 'addresses' => {
@ -102,63 +112,76 @@ describe ::Openstack do
} }
} }
} }
chef_run.converge 'openstack-common::set_endpoints_by_interface' subject.stub('address_for').and_return('10.0.0.100')
expect(chef_run.node['openstack']['endpoints']['identity-api']['host']).to eql('10.0.0.100') expect(
chef_run.node['openstack']['endpoints']['identity-api']['host']
).to eq('10.0.0.100')
end end
end end
describe '#endpoints' do describe '#endpoints' do
it 'does nothing when no endpoints' do it 'does nothing when no endpoints' do
@subject.stub(:node).and_return {} subject.stub(:node).and_return({})
@subject.endpoints.should be_nil expect(subject.endpoints).to be_nil
end end
it 'does nothing when empty endpoints' do it 'does nothing when empty endpoints' do
@subject.stub(:node).and_return('openstack' => { 'endpoints' => {} }) subject.stub(:node).and_return('openstack' => { 'endpoints' => {} })
@count = 0 count = 0
@subject.endpoints do | ep | subject.endpoints do | ep |
@count += 1 count += 1
end end
@count.should == 0 expect(count).to eq(0)
end end
it 'executes block count when have endpoints' do it 'executes block count when have endpoints' do
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(chef_run.node)
@count = 0 count = 0
@subject.endpoints do |ep| subject.endpoints do |ep|
@count += 1 count += 1
end end
@count.should >= 1 expect(count).to be >= 1
end end
end end
describe '#db' do describe '#db' do
it 'returns nil when no openstack.db not in node attrs' do it 'returns nil when no openstack.db not in node attrs' do
@subject.stub(:node).and_return {} subject.stub(:node).and_return({})
@subject.db('nonexisting').should be_nil expect(subject.db('nonexisting')).to be_nil
end end
it 'returns nil when no such service was found' do it 'returns nil when no such service was found' do
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(chef_run.node)
@subject.db('nonexisting').should be_nil expect(subject.db('nonexisting')).to be_nil
end end
it 'returns db info hash when service found' do it 'returns db info hash when service found' do
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(chef_run.node)
@subject.db('compute')['host'].should eq('127.0.0.1') expect(subject.db('compute')['host']).to eq('127.0.0.1')
@subject.db('compute').key?('uri').should be_false expect(subject.db('compute').key?('uri')).to be_false
end end
end end
describe '#db_uri' do describe '#db_uri' do
it 'returns nil when no openstack.db not in node attrs' do it 'returns nil when no openstack.db not in node attrs' do
@subject.stub(:node).and_return {} subject.stub(:node).and_return({})
@subject.db_uri('nonexisting', 'user', 'pass').should be_nil expect(subject.db_uri('nonexisting', 'user', 'pass')).to be_nil
end end
it 'returns nil when no such service was found' do it 'returns nil when no such service was found' do
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(chef_run.node)
@subject.db_uri('nonexisting', 'user', 'pass').should be_nil expect(
subject.db_uri('nonexisting', 'user', 'pass')
).to be_nil
end end
it 'returns db info hash when service found' do it 'returns db info hash when service found' do
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(chef_run.node)
expect = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8' expected = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
@subject.db_uri('compute', 'user', 'pass').should == expect expect(
subject.db_uri('compute', 'user', 'pass')
).to eq(expected)
end
end end
end end
end end

@ -1,48 +1,38 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-common::logging' do describe 'openstack-common::logging' do
describe 'ubuntu' do describe 'ubuntu' do
before do let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS let(:node) { runner.node }
@chef_run.converge 'openstack-common::logging' let(:chef_run) { runner.converge(described_recipe) }
end
describe '/etc/openstack' do describe '/etc/openstack' do
before do let(:dir) { chef_run.directory('/etc/openstack') }
@dir = @chef_run.directory '/etc/openstack'
end
it 'has proper owner' do it 'has proper owner' do
expect(@dir.owner).to eq('root') expect(dir.owner).to eq('root')
expect(@dir.group).to eq('root') expect(dir.group).to eq('root')
end end
it 'has proper modes' do it 'has proper modes' do
expect(sprintf('%o', @dir.mode)).to eq '755' expect(sprintf('%o', dir.mode)).to eq '755'
end end
end end
describe 'logging.conf' do describe 'logging.conf' do
before do let(:file) { chef_run.template('/etc/openstack/logging.conf') }
@file = '/etc/openstack/logging.conf'
end
it 'has proper owner' do it 'has proper owner' do
expect(@chef_run.template(@file).owner).to eq('root') expect(file.owner).to eq('root')
expect(@chef_run.template(@file).group).to eq('root') expect(file.group).to eq('root')
end end
it 'has proper modes' do it 'has proper modes' do
m = @chef_run.template(@file).mode expect(sprintf('%o', file.mode)).to eq '644'
expect(sprintf('%o', m)).to eq '644'
end end
it 'templates openstack.logging.ignore block' do it 'templates openstack.logging.ignore block' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
chef_run.converge 'openstack-common::logging'
node = chef_run.node
node.set['openstack']['logging']['ignore'] = { node.set['openstack']['logging']['ignore'] = {
'test.nova.api.openstack.wsgi' => 'WARNING' 'test.nova.api.openstack.wsgi' => 'WARNING'
} }
@ -53,7 +43,7 @@ describe 'openstack-common::logging' do
'handlers = prod,debug', 'handlers = prod,debug',
'qualname = test.nova.api.openstack.wsgi' 'qualname = test.nova.api.openstack.wsgi'
] ]
expect(chef_run).to render_file(@file).with_content(tmp.join(' expect(chef_run).to render_file(file.name).with_content(tmp.join('
')) '))
end end
end end

@ -1,12 +1,13 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'spec_helper' require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'network' require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'network'
describe ::Openstack do describe 'openstack-common::default' do
before do describe 'Openstack address_for' do
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n| let(:runner) { ChefSpec::Runner.new(CHEFSPEC_OPTS) }
n.set['network'] = { let(:node) { runner.node }
let(:chef_run) do
node.set['network'] = {
'interfaces' => { 'interfaces' => {
'lo' => { 'lo' => {
'addresses' => { 'addresses' => {
@ -25,24 +26,25 @@ describe ::Openstack do
} }
} }
} }
runner.converge(described_recipe)
end end
@chef_run.converge 'openstack-common::default' let(:subject) { Object.new.extend(Openstack) }
@subject = ::Object.new.extend ::Openstack
end include_context 'library-stubs'
describe '#address_for' do describe '#address_for' do
it 'returns ipv4 address' do it 'returns ipv4 address' do
@subject.stub(:node).and_return @chef_run.node expect(
resp = @subject.address_for 'lo' subject.address_for('lo')
).to eq('127.0.0.1')
expect(resp).to eq '127.0.0.1'
end end
it 'returns ipv4 address' do it 'returns ipv4 address' do
@subject.stub(:node).and_return @chef_run.node expect(
resp = @subject.address_for 'lo', 'inet6' subject.address_for('lo', 'inet6')
).to eq('::1')
expect(resp).to eq '::1' end
end end
end end
end end

@ -1,20 +1,21 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'spec_helper' require_relative 'spec_helper'
require 'uri' require 'uri'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'parse' require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'parse'
describe ::Openstack do describe 'Openstack parse' do
before do let(:subject) { Object.new.extend(Openstack) }
@subject = ::Object.new.extend(::Openstack)
end
describe '#prettytable_to_array' do describe '#prettytable_to_array' do
it 'returns [] when no table provided' do it 'returns [] when no table provided' do
@subject.prettytable_to_array(nil).should == [] expect(
subject.prettytable_to_array(nil)
).to eq([])
end end
it 'returns [] when table provided is empty' do it 'returns [] when table provided is empty' do
@subject.prettytable_to_array('').should == [] expect(
subject.prettytable_to_array('')
).to eq([])
end end
it 'returns proper array of hashes when proper table provided' do it 'returns proper array of hashes when proper table provided' do
table = table =
@ -23,10 +24,12 @@ describe ::Openstack do
+---------+----------------------------------+----------------------------------+ +---------+----------------------------------+----------------------------------+
| service | 91af731b3be244beb8f30fc59b7bc96d | ce811442cfb549c39390a203778a4bf5 | | service | 91af731b3be244beb8f30fc59b7bc96d | ce811442cfb549c39390a203778a4bf5 |
+---------+----------------------------------+----------------------------------+' +---------+----------------------------------+----------------------------------+'
@subject.prettytable_to_array(table).should == expect(
subject.prettytable_to_array(table)
).to eq(
[{ 'tenant' => 'service', [{ 'tenant' => 'service',
'access' => '91af731b3be244beb8f30fc59b7bc96d', 'access' => '91af731b3be244beb8f30fc59b7bc96d',
'secret' => 'ce811442cfb549c39390a203778a4bf5' }] 'secret' => 'ce811442cfb549c39390a203778a4bf5' }])
end end
it 'returns proper array of hashes when proper table provided including whitespace' do it 'returns proper array of hashes when proper table provided including whitespace' do
table = table =
@ -38,10 +41,12 @@ describe ::Openstack do
' '
@subject.prettytable_to_array(table).should == expect(
subject.prettytable_to_array(table)
).to eq(
[{ 'tenant' => 'service', [{ 'tenant' => 'service',
'access' => '91af731b3be244beb8f30fc59b7bc96d', 'access' => '91af731b3be244beb8f30fc59b7bc96d',
'secret' => 'ce811442cfb549c39390a203778a4bf5' }] 'secret' => 'ce811442cfb549c39390a203778a4bf5' }])
end end
it 'returns a flatten hash when provided a Property/Value table' do it 'returns a flatten hash when provided a Property/Value table' do
table = table =
@ -53,11 +58,13 @@ describe ::Openstack do
| tenant_id | 429271dd1cf54b7ca921a0017524d8ea | | tenant_id | 429271dd1cf54b7ca921a0017524d8ea |
| user_id | 1c4fc229560f40689c490c5d0838fd84 | | user_id | 1c4fc229560f40689c490c5d0838fd84 |
+-----------+----------------------------------+' +-----------+----------------------------------+'
@subject.prettytable_to_array(table).should == expect(
subject.prettytable_to_array(table)
).to eq(
[{ 'tenant_id' => '429271dd1cf54b7ca921a0017524d8ea', [{ 'tenant_id' => '429271dd1cf54b7ca921a0017524d8ea',
'access' => '91af731b3be244beb8f30fc59b7bc96d', 'access' => '91af731b3be244beb8f30fc59b7bc96d',
'secret' => 'ce811442cfb549c39390a203778a4bf5', 'secret' => 'ce811442cfb549c39390a203778a4bf5',
'user_id' => '1c4fc229560f40689c490c5d0838fd84' }] 'user_id' => '1c4fc229560f40689c490c5d0838fd84' }])
end end
it 'returns a flatten hash when provided a Property/Value table including whitespace' do it 'returns a flatten hash when provided a Property/Value table including whitespace' do
table = table =
@ -71,11 +78,13 @@ describe ::Openstack do
| tenant_id | 429271dd1cf54b7ca921a0017524d8ea | | tenant_id | 429271dd1cf54b7ca921a0017524d8ea |
| user_id | 1c4fc229560f40689c490c5d0838fd84 | | user_id | 1c4fc229560f40689c490c5d0838fd84 |
+-----------+----------------------------------+' +-----------+----------------------------------+'
@subject.prettytable_to_array(table).should == expect(
subject.prettytable_to_array(table)
).to eq(
[{ 'tenant_id' => '429271dd1cf54b7ca921a0017524d8ea', [{ 'tenant_id' => '429271dd1cf54b7ca921a0017524d8ea',
'access' => '91af731b3be244beb8f30fc59b7bc96d', 'access' => '91af731b3be244beb8f30fc59b7bc96d',
'secret' => 'ce811442cfb549c39390a203778a4bf5', 'secret' => 'ce811442cfb549c39390a203778a4bf5',
'user_id' => '1c4fc229560f40689c490c5d0838fd84' }] 'user_id' => '1c4fc229560f40689c490c5d0838fd84' }])
end end
end end
end end

@ -1,92 +1,80 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'spec_helper' require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'passwords' require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'passwords'
describe ::Openstack do describe 'openstack-common::default' do
before do describe 'Passwords' do
@chef_run = ::ChefSpec::Runner.new ::CHEFSPEC_OPTS let(:runner) { ChefSpec::Runner.new(CHEFSPEC_OPTS) }
@chef_run.converge 'openstack-common::default' let(:node) { runner.node }
@subject = ::Object.new.extend(::Openstack) let(:chef_run) { runner.converge(described_recipe) }
end let(:subject) { Object.new.extend(Openstack) }
include_context 'library-stubs'
describe '#secret' do describe '#secret' do
it 'returns index param when developer_mode is true' do it 'returns index param when developer_mode is true' do
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n| node.set['openstack']['developer_mode'] = true
n.set['openstack']['developer_mode'] = true expect(subject.secret('passwords', 'nova')).to eq('nova')
end
@chef_run.converge 'openstack-common::default'
@subject.stub(:node).and_return @chef_run.node
result = @subject.secret('passwords', 'nova')
result.should == 'nova'
end end
it 'returns databag when developer_mode is false' do it 'returns databag when developer_mode is false' do
value = { 'nova' => 'this' } value = { 'nova' => 'this' }
::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return 'secret' ::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return('secret')
::Chef::EncryptedDataBagItem.stub(:load).with('passwords', 'nova', 'secret').and_return value ::Chef::EncryptedDataBagItem.stub(:load).with('passwords', 'nova', 'secret').and_return(value)
@subject.stub(:node).and_return @chef_run.node expect(subject.secret('passwords', 'nova')).to eq('this')
result = @subject.secret('passwords', 'nova')
result.should == 'this'
end end
end end
describe '#get_password_service_password' do describe '#get_password_service_password' do
it 'returns index param when developer_mode is true' do it 'returns index param when developer_mode is true' do
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n| node.set['openstack']['developer_mode'] = true
n.set['openstack']['developer_mode'] = true expect(subject.get_password('service', 'nova')).to eq('nova')
end
@chef_run.converge 'openstack-common::default'
@subject.stub(:node).and_return @chef_run.node
result = @subject.get_password('service', 'nova')
result.should == 'nova'
end end
it 'returns databag when developer_mode is false' do it 'returns databag when developer_mode is false' do
value = { 'nova' => 'this' } value = { 'nova' => 'this' }
::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return 'secret' ::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return('secret')
::Chef::EncryptedDataBagItem.stub(:load).with('service_passwords', 'nova', 'secret').and_return value ::Chef::EncryptedDataBagItem.stub(:load).with('service_passwords', 'nova', 'secret').and_return(value)
@subject.stub(:node).and_return @chef_run.node expect(
result = @subject.get_password('service', 'nova') subject.get_password('service', 'nova')
result.should == 'this' ).to eq('this')
end end
end end
describe '#get_password_db_password' do describe '#get_password_db_password' do
it 'returns index param when developer_mode is true' do it 'returns index param when developer_mode is true' do
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n| node.set['openstack']['developer_mode'] = true
n.set['openstack']['developer_mode'] = true expect(
end subject.get_password('db', 'nova')
@chef_run.converge 'openstack-common::default' ).to eq('nova')
@subject.stub(:node).and_return @chef_run.node
result = @subject.get_password('db', 'nova')
result.should == 'nova'
end end
it 'returns databag when developer_mode is false' do it 'returns databag when developer_mode is false' do
value = { 'nova' => 'this' } value = { 'nova' => 'this' }
::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return 'secret' ::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return('secret')
::Chef::EncryptedDataBagItem.stub(:load).with('db_passwords', 'nova', 'secret').and_return value ::Chef::EncryptedDataBagItem.stub(:load).with('db_passwords', 'nova', 'secret').and_return(value)
@subject.stub(:node).and_return @chef_run.node expect(
result = @subject.get_password('db', 'nova') subject.get_password('db', 'nova')
result.should == 'this' ).to eq('this')
end end
end end
describe '#get_password_user_password' do describe '#get_password_user_password' do
it 'returns index param when developer_mode is true' do it 'returns index param when developer_mode is true' do
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n| node.set['openstack']['developer_mode'] = true
n.set['openstack']['developer_mode'] = true expect(
end subject.get_password('user', 'nova')
@chef_run.converge 'openstack-common::default' ).to eq('nova')
@subject.stub(:node).and_return @chef_run.node
result = @subject.get_password('user', 'nova')
result.should == 'nova'
end end
it 'returns databag when developer_mode is false' do it 'returns databag when developer_mode is false' do
value = { 'nova' => 'this' } value = { 'nova' => 'this' }
::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return 'secret' ::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return('secret')
::Chef::EncryptedDataBagItem.stub(:load).with('user_passwords', 'nova', 'secret').and_return value ::Chef::EncryptedDataBagItem.stub(:load).with('user_passwords', 'nova', 'secret').and_return(value)
@subject.stub(:node).and_return @chef_run.node expect(
result = @subject.get_password('user', 'nova') subject.get_password('user', 'nova')
result.should == 'this' ).to eq('this')
end
end end
end end
end end

@ -1,49 +1,47 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'spec_helper' require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'search' require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'search'
describe ::Openstack do describe 'openstack-common::default' do
before do describe 'Openstack Search' do
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n| let(:runner) { ChefSpec::Runner.new(CHEFSPEC_OPTS) }
n.set['openstack']['mq'] = { let(:node) { runner.node }
'server_role' => 'openstack-ops-mq', let(:chef_run) do
'port' => 5672 node.set['openstack']['mq']['server_role'] = 'openstack-ops-mq'
} node.set['openstack']['mq']['port'] = 5672
end
@chef_run.converge 'openstack-common::default' runner.converge(described_recipe)
@subject = ::Object.new.extend ::Openstack
end end
let(:subject) { Object.new.extend(Openstack) }
describe '#search_for' do describe '#search_for' do
it 'returns results' do it 'returns results' do
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(chef_run.node)
@subject.stub(:search) subject.stub(:search)
.with(:node, '(chef_environment:_default AND roles:role) OR (chef_environment:_default AND recipes:role)') .with(:node, '(chef_environment:_default AND roles:role) OR (chef_environment:_default AND recipes:role)')
.and_return [@chef_run.node] .and_return([chef_run.node])
resp = @subject.search_for('role') resp = subject.search_for('role')
expect(resp[0]['fqdn']).to eq('chefspec.local')
expect(resp[0]['fqdn']).to eq 'chefspec.local'
end end
it 'returns empty results' do it 'returns empty results' do
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(chef_run.node)
@subject.stub(:search) subject.stub(:search)
.with(:node, '(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)') .with(:node, '(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)')
.and_return [] .and_return([])
resp = @subject.search_for('empty-role') expect(
subject.search_for('empty-role')
expect(resp).to eq [] ).to eq([])
end end
it 'always returns empty results' do it 'always returns empty results' do
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(chef_run.node)
@subject.stub(:search) subject.stub(:search)
.with(:node, '(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)') .with(:node, '(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)')
.and_return nil .and_return(nil)
resp = @subject.search_for('empty-role') expect(
subject.search_for('empty-role')
expect(resp).to eq [] ).to eq([])
end end
end end
@ -53,13 +51,13 @@ describe ::Openstack do
{ 'memcached' => { 'listen' => '1.1.1.1', 'port' => '11211' } }, { 'memcached' => { 'listen' => '1.1.1.1', 'port' => '11211' } },
{ 'memcached' => { 'listen' => '2.2.2.2', 'port' => '11211' } } { 'memcached' => { 'listen' => '2.2.2.2', 'port' => '11211' } }
] ]
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(chef_run.node)
@subject.stub(:search_for) subject.stub(:search_for)
.with('role') .with('role')
.and_return nodes .and_return(nodes)
resp = @subject.memcached_servers('role') expect(
subject.memcached_servers('role')
expect(resp).to eq ['1.1.1.1:11211', '2.2.2.2:11211'] ).to eq(['1.1.1.1:11211', '2.2.2.2:11211'])
end end
it 'returns sorted memcached list' do it 'returns sorted memcached list' do
@ -68,13 +66,13 @@ describe ::Openstack do
{ 'memcached' => { 'listen' => '1.1.1.1', 'port' => '11211' } }, { 'memcached' => { 'listen' => '1.1.1.1', 'port' => '11211' } },
{ 'memcached' => { 'listen' => '2.2.2.2', 'port' => '11211' } } { 'memcached' => { 'listen' => '2.2.2.2', 'port' => '11211' } }
] ]
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(chef_run.node)
@subject.stub(:search_for) subject.stub(:search_for)
.with('role') .with('role')
.and_return nodes .and_return(nodes)
resp = @subject.memcached_servers('role') expect(
subject.memcached_servers('role')
expect(resp).to eq ['1.1.1.1:11211', '2.2.2.2:11211', '3.3.3.3:11211'] ).to eq(['1.1.1.1:11211', '2.2.2.2:11211', '3.3.3.3:11211'])
end end
it 'returns memcached servers as defined by attributes' do it 'returns memcached servers as defined by attributes' do
@ -83,10 +81,10 @@ describe ::Openstack do
'memcached_servers' => ['1.1.1.1:11211', '2.2.2.2:11211'] 'memcached_servers' => ['1.1.1.1:11211', '2.2.2.2:11211']
} }
} }
@subject.stub(:node).and_return @chef_run.node.merge nodes subject.stub(:node).and_return(chef_run.node.merge(nodes))
resp = @subject.memcached_servers('role') expect(
subject.memcached_servers('role')
expect(resp).to eq ['1.1.1.1:11211', '2.2.2.2:11211'] ).to eq(['1.1.1.1:11211', '2.2.2.2:11211'])
end end
it 'returns empty memcached servers as defined by attributes' do it 'returns empty memcached servers as defined by attributes' do
@ -95,10 +93,10 @@ describe ::Openstack do
'memcached_servers' => [] 'memcached_servers' => []
} }
} }
@subject.stub(:node).and_return @chef_run.node.merge nodes subject.stub(:node).and_return(chef_run.node.merge(nodes))
resp = @subject.memcached_servers('empty-role') expect(
subject.memcached_servers('empty-role')
expect(resp).to eq [] ).to eq([])
end end
end end
@ -108,12 +106,11 @@ describe ::Openstack do
{ 'openstack' => { 'mq' => { 'listen' => '1.1.1.1', 'port' => '5672' } } }, { 'openstack' => { 'mq' => { 'listen' => '1.1.1.1', 'port' => '5672' } } },
{ 'openstack' => { 'mq' => { 'listen' => '2.2.2.2', 'port' => '5672' } } } { 'openstack' => { 'mq' => { 'listen' => '2.2.2.2', 'port' => '5672' } } }
] ]
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(chef_run.node)
@subject.stub(:search_for) subject.stub(:search_for)
.and_return nodes .and_return(nodes)
resp = @subject.rabbit_servers expect(
subject.rabbit_servers).to eq('1.1.1.1:5672,2.2.2.2:5672')
expect(resp).to eq '1.1.1.1:5672,2.2.2.2:5672'
end end
it 'returns sorted rabbit servers' do it 'returns sorted rabbit servers' do
@ -122,21 +119,21 @@ describe ::Openstack do
{ 'openstack' => { 'mq' => { 'listen' => '1.1.1.1', 'port' => '5672' } } }, { 'openstack' => { 'mq' => { 'listen' => '1.1.1.1', 'port' => '5672' } } },
{ 'openstack' => { 'mq' => { 'listen' => '2.2.2.2', 'port' => '5672' } } } { 'openstack' => { 'mq' => { 'listen' => '2.2.2.2', 'port' => '5672' } } }
] ]
@subject.stub(:node).and_return @chef_run.node subject.stub(:node).and_return(chef_run.node)
@subject.stub(:search_for) subject.stub(:search_for)
.and_return nodes .and_return(nodes)
resp = @subject.rabbit_servers expect(
subject.rabbit_servers
expect(resp).to eq '1.1.1.1:5672,2.2.2.2:5672,3.3.3.3:5672' ).to eq('1.1.1.1:5672,2.2.2.2:5672,3.3.3.3:5672')
end end
it 'returns rabbit servers when not searching' do it 'returns rabbit servers when not searching' do
node = @chef_run.node chef_run.node.set['openstack']['mq']['servers'] = ['1.1.1.1', '2.2.2.2']
node.set['openstack']['mq']['servers'] = ['1.1.1.1', '2.2.2.2'] subject.stub(:node).and_return(chef_run.node)
@subject.stub(:node).and_return @chef_run.node expect(
resp = @subject.rabbit_servers subject.rabbit_servers
).to eq('1.1.1.1:5672,2.2.2.2:5672')
expect(resp).to eq '1.1.1.1:5672,2.2.2.2:5672' end
end end
end end
end end

@ -3,26 +3,32 @@
require 'chefspec' require 'chefspec'
require 'chefspec/berkshelf' require 'chefspec/berkshelf'
::LOG_LEVEL = :fatal LOG_LEVEL = :fatal
::UBUNTU_OPTS = { UBUNTU_OPTS = {
platform: 'ubuntu', platform: 'ubuntu',
version: '12.04', version: '12.04',
log_level: ::LOG_LEVEL log_level: LOG_LEVEL
} }
::REDHAT_OPTS = { REDHAT_OPTS = {
platform: 'redhat', platform: 'redhat',
version: '6.3', version: '6.5',
log_level: ::LOG_LEVEL log_level: LOG_LEVEL
} }
::SUSE_OPTS = { SUSE_OPTS = {
platform: 'suse', platform: 'suse',
version: '11.03', version: '11.03',
log_lovel: ::LOG_LEVEL log_lovel: LOG_LEVEL
} }
::CHEFSPEC_OPTS = { CHEFSPEC_OPTS = {
log_level: ::LOG_LEVEL log_level: LOG_LEVEL
} }
shared_context 'library-stubs' do
before do
subject.stub(:node).and_return(chef_run.node)
end
end
# README(galstrom21): This will remove any coverage warnings from # README(galstrom21): This will remove any coverage warnings from
# dependent cookbooks # dependent cookbooks
ChefSpec::Coverage.filters << '*/openstack-common' ChefSpec::Coverage.filters << '*/openstack-common'

@ -1,36 +1,29 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'openstack-common::sysctl' do describe 'openstack-common::sysctl' do
describe 'ubuntu' do describe 'ubuntu' do
before do let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS let(:node) { runner.node }
@chef_run.converge 'openstack-common::sysctl' let(:chef_run) { runner.converge(described_recipe) }
end
describe '60-openstack.conf' do describe '60-openstack.conf' do
before do let(:file) { chef_run.template('/etc/sysctl.d/60-openstack.conf') }
@file = @chef_run.template '/etc/sysctl.d/60-openstack.conf'
end
it 'has proper owner' do it 'has proper owner' do
expect(@file.owner).to eq('root') expect(file.owner).to eq('root')
expect(@file.group).to eq('root') expect(file.group).to eq('root')
end end
it 'has proper modes' do it 'has proper modes' do
expect(sprintf('%o', @file.mode)).to eq '644' expect(sprintf('%o', file.mode)).to eq '644'
end end
it 'sets the all.rp_filter' do { 'net.ipv4.conf.all.rp_filter' => 0,
match = 'net.ipv4.conf.all.rp_filter = 0' 'net.ipv4.conf.default.rp_filter' => 0 }.each do |k, v|
expect(@chef_run).to render_file(@file.name).with_content(match) it "sets the #{k}" do
end expect(chef_run).to render_file(file.name).with_content("#{k} = #{v}")
end
it 'sets the default.rp_filter' do
match = 'net.ipv4.conf.default.rp_filter = 0'
expect(@chef_run).to render_file(@file.name).with_content(match)
end end
end end
end end

@ -1,13 +1,10 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'spec_helper' require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'uri' require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'uri'
require 'uri' require 'uri'
describe ::Openstack do describe 'Openstack uri' do
before do let(:subject) { Object.new.extend(Openstack) }
@subject = ::Object.new.extend(::Openstack)
end
describe '#uri_from_hash' do describe '#uri_from_hash' do
it 'returns nil when no host or uri key found' do it 'returns nil when no host or uri key found' do
@ -15,8 +12,11 @@ describe ::Openstack do
'port' => 8888, 'port' => 8888,
'path' => '/path' 'path' => '/path'
} }
@subject.uri_from_hash(hash).should be_nil expect(
subject.uri_from_hash(hash)
).to be_nil
end end
it 'returns uri when uri key found, ignoring other parts' do it 'returns uri when uri key found, ignoring other parts' do
uri = 'http://localhost/' uri = 'http://localhost/'
hash = { hash = {
@ -24,10 +24,11 @@ describe ::Openstack do
'path' => '/path', 'path' => '/path',
'uri' => uri 'uri' => uri
} }
result = @subject.uri_from_hash(hash) result = subject.uri_from_hash(hash)
result.should be_a URI expect(result).to be_a URI
result.to_s.should == uri expect(result.to_s).to eq(uri)
end end
it 'constructs from host' do it 'constructs from host' do
uri = 'https://localhost:8888/path' uri = 'https://localhost:8888/path'
hash = { hash = {
@ -36,52 +37,65 @@ describe ::Openstack do
'path' => '/path', 'path' => '/path',
'host' => 'localhost' 'host' => 'localhost'
} }
result = @subject.uri_from_hash(hash) expect(
result.to_s.should == uri subject.uri_from_hash(hash).to_s
).to eq(uri)
end end
it 'constructs with defaults' do it 'constructs with defaults' do
uri = 'https://localhost' uri = 'https://localhost'
hash = { hash = {
'scheme' => 'https', 'scheme' => 'https',
'host' => 'localhost' 'host' => 'localhost'
} }
result = @subject.uri_from_hash(hash) expect(
result.to_s.should == uri subject.uri_from_hash(hash).to_s
).to eq(uri)
end end
it 'constructs with extraneous keys' do it 'constructs with extraneous keys' do
uri = 'http://localhost' uri = 'http://localhost'
hash = { hash = {
'host' => 'localhost', 'host' => 'localhost',
'network' => 'public' # To emulate the osops-utils::ip_location way... 'network' => 'public' # To emulate the osops-utils::ip_location way...
} }
result = @subject.uri_from_hash(hash) expect(
result.to_s.should == uri subject.uri_from_hash(hash).to_s
).to eq(uri)
end end
end end
describe '#uri_join_paths' do describe '#uri_join_paths' do
it 'returns nil when no paths are passed in' do it 'returns nil when no paths are passed in' do
@subject.uri_join_paths.should be_nil expect(subject.uri_join_paths).to be_nil
end end
it 'preserves absolute path when only absolute path passed in' do it 'preserves absolute path when only absolute path passed in' do
path = '/abspath' path = '/abspath'
result = @subject.uri_join_paths(path) expect(
result.should == path subject.uri_join_paths(path)
).to eq(path)
end end
it 'preserves relative path when only relative path passed in' do it 'preserves relative path when only relative path passed in' do
path = 'abspath/' path = 'abspath/'
result = @subject.uri_join_paths(path) expect(
result.should == path subject.uri_join_paths(path)
).to eq(path)
end end
it 'preserves leadng and trailing slashes' do it 'preserves leadng and trailing slashes' do
expected = '/path/to/resource/' expected = '/path/to/resource/'
result = @subject.uri_join_paths('/path', 'to', 'resource/') expect(
result.should == expected subject.uri_join_paths('/path', 'to', 'resource/')
).to eq(expected)
end end
it 'removes extraneous intermediate slashes' do it 'removes extraneous intermediate slashes' do
expected = '/path/to/resource' expected = '/path/to/resource'
result = @subject.uri_join_paths('/path', '//to/', '/resource') expect(
result.should == expected subject.uri_join_paths('/path', '//to/', '/resource')
).to eq(expected)
end end
end end
end end