Refactoring chefspec tests
Change-Id: I35dfca684039512e2a238466ff7df5f3fd34d956 Addresses: blueprint refactor-spec-files Closes-Bug: 1282996
This commit is contained in:
parent
4ad20f5e56
commit
ffe0d05a0d
@ -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,41 +1,48 @@
|
|||||||
# 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
|
|
||||||
|
|
||||||
describe '#db_create_with_user' do
|
include_context 'library-stubs'
|
||||||
it 'returns nil when no such service was found' do
|
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
|
||||||
@subject.db_create_with_user('nonexisting', 'user', 'pass').should be_nil
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns db info and creates database with user when service found' do
|
describe '#db_create_with_user' do
|
||||||
@subject.stub(:database).and_return {}
|
before do
|
||||||
@subject.stub(:database_user).and_return {}
|
subject.stub(:include_recipe)
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
.with('database::mysql')
|
||||||
result = @subject.db_create_with_user 'compute', 'user', 'pass'
|
.and_return('')
|
||||||
result['host'].should eq('127.0.0.1')
|
end
|
||||||
result['port'].should eq('3306')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'creates database' do
|
it 'returns nil when no such service was found' do
|
||||||
pending 'TODO: test this LWRP'
|
expect(
|
||||||
end
|
subject.db_create_with_user('nonexisting', 'user', 'pass')
|
||||||
|
).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
it 'creates database user' do
|
it 'returns db info and creates database with user when service found' do
|
||||||
pending 'TODO: test this LWRP'
|
subject.stub(:database).and_return({})
|
||||||
end
|
subject.stub(:database_user).and_return({})
|
||||||
|
result = subject.db_create_with_user('compute', 'user', 'pass')
|
||||||
|
expect(result['host']).to eq('127.0.0.1')
|
||||||
|
expect(result['port']).to eq('3306')
|
||||||
|
end
|
||||||
|
|
||||||
it 'grants privs to database user' do
|
it 'creates database' do
|
||||||
pending 'TODO: test this LWRP'
|
pending 'TODO: test this LWRP'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates database user' do
|
||||||
|
pending 'TODO: test this LWRP'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'grants privs to database user' do
|
||||||
|
pending 'TODO: test this LWRP'
|
||||||
|
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
|
||||||
|
node.set['openstack']['release'] = 'testrelease'
|
||||||
|
|
||||||
|
runner.converge(described_recipe)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'enabling RDO' do
|
||||||
|
before do
|
||||||
|
node.set['openstack']['yum']['rdo_enabled'] = true
|
||||||
end
|
end
|
||||||
@chef_run.converge 'openstack-common::default'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'configures RDO yum repository' do
|
it 'adds RDO yum repository' do
|
||||||
repo_name = 'RDO-testrelease'
|
# Using cookbook(yum) LWRP custom matcher
|
||||||
expect(@chef_run).to add_yum_repository(repo_name)
|
# https://github.com/sethvargo/chefspec#packaging-custom-matchers
|
||||||
end
|
expect(chef_run).to add_yum_repository('RDO-testrelease')
|
||||||
|
end
|
||||||
it 'includes yum-epel recipe' do
|
|
||||||
expect(@chef_run).to include_recipe('yum-epel')
|
it 'includes yum-epel recipe' do
|
||||||
end
|
expect(chef_run).to include_recipe('yum-epel')
|
||||||
end
|
|
||||||
|
|
||||||
describe 'rhel-no-rdo' do
|
|
||||||
before do
|
|
||||||
@chef_run = ::ChefSpec::Runner.new(::REDHAT_OPTS) do |n|
|
|
||||||
n.set['openstack']['release'] = 'testrelease'
|
|
||||||
n.set['openstack']['yum']['rdo_enabled'] = false
|
|
||||||
end
|
end
|
||||||
@chef_run.converge 'openstack-common::default'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'configures RDO yum repository' do
|
context 'disabling RDO' do
|
||||||
repo_name = 'RDO-testrelease'
|
before do
|
||||||
expect(@chef_run).to remove_yum_repository(repo_name)
|
node.set['openstack']['yum']['rdo_enabled'] = false
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not include yum-epel recipe' do
|
it 'removes RDO yum repository' do
|
||||||
expect(@chef_run).to_not include_recipe('yum-epel')
|
# Using cookbook(yum) LWRP custom matcher
|
||||||
|
# https://github.com/sethvargo/chefspec#packaging-custom-matchers
|
||||||
|
expect(chef_run).to remove_yum_repository('RDO-testrelease')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not include yum-epel recipe' do
|
||||||
|
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,164 +1,187 @@
|
|||||||
# 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(
|
||||||
end
|
subject.endpoint('nonexisting')
|
||||||
it 'returns nil when no such endpoint was found' do
|
).to be_nil
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
end
|
||||||
@subject.endpoint('nonexisting').should be_nil
|
|
||||||
end
|
it 'returns nil when no such endpoint was found' do
|
||||||
it 'handles a URI needing escaped' do
|
subject.stub(:node).and_return(node)
|
||||||
uri_hash = {
|
expect(
|
||||||
'openstack' => {
|
subject.endpoint('nonexisting')
|
||||||
'endpoints' => {
|
).to be_nil
|
||||||
'compute-api' => {
|
end
|
||||||
'uri' => 'http://localhost:8080/v2/%(tenant_id)s'
|
|
||||||
}
|
it 'handles a URI needing escaped' do
|
||||||
}
|
uri_hash = {
|
||||||
}
|
'openstack' => {
|
||||||
}
|
'endpoints' => {
|
||||||
@subject.stub(:node).and_return uri_hash
|
'compute-api' => {
|
||||||
result = @subject.endpoint 'compute-api'
|
'uri' => 'http://localhost:8080/v2/%(tenant_id)s'
|
||||||
result.path.should == '/v2/%25(tenant_id)s'
|
|
||||||
end
|
|
||||||
it 'returns endpoint URI object when uri key in endpoint hash' do
|
|
||||||
uri_hash = {
|
|
||||||
'openstack' => {
|
|
||||||
'endpoints' => {
|
|
||||||
'compute-api' => {
|
|
||||||
'uri' => 'http://localhost:8080/path'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@subject.stub(:node).and_return uri_hash
|
|
||||||
result = @subject.endpoint 'compute-api'
|
|
||||||
result.port.should == 8080
|
|
||||||
end
|
|
||||||
it 'returns endpoint URI string when uri key in endpoint hash and host also in hash' do
|
|
||||||
uri_hash = {
|
|
||||||
'openstack' => {
|
|
||||||
'endpoints' => {
|
|
||||||
'compute-api' => {
|
|
||||||
'uri' => 'http://localhost',
|
|
||||||
'host' => 'ignored'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@subject.stub(:node).and_return uri_hash
|
|
||||||
@subject.endpoint('compute-api').to_s.should == 'http://localhost'
|
|
||||||
end
|
|
||||||
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')
|
|
||||||
uri_hash = {
|
|
||||||
'openstack' => {
|
|
||||||
'endpoints' => {
|
|
||||||
'compute-api' => {
|
|
||||||
'host' => 'localhost',
|
|
||||||
'port' => '8080'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@subject.stub(:node).and_return uri_hash
|
|
||||||
@subject.endpoint 'compute-api'
|
|
||||||
end
|
|
||||||
it 'endpoints recipe bind_interface sets host' do
|
|
||||||
@subject.stub('address_for').and_return '10.0.0.100'
|
|
||||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
|
||||||
chef_run.node.set['openstack']['endpoints']['identity-api']['bind_interface'] = 'eth0'
|
|
||||||
chef_run.node.set['network'] = {
|
|
||||||
'interfaces' => {
|
|
||||||
'lo' => {
|
|
||||||
'addresses' => {
|
|
||||||
'127.0.0.1' => {
|
|
||||||
'family' => 'inet',
|
|
||||||
'netmask' => '255.0.0.0',
|
|
||||||
'scope' => 'Node'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'eth0' => {
|
|
||||||
'addresses' => {
|
|
||||||
'10.0.0.100' => {
|
|
||||||
'family' => 'inet',
|
|
||||||
'netmask' => '255.255.255.0',
|
|
||||||
'scope' => 'Global'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
subject.stub(:node).and_return(uri_hash)
|
||||||
chef_run.converge 'openstack-common::set_endpoints_by_interface'
|
expect(
|
||||||
expect(chef_run.node['openstack']['endpoints']['identity-api']['host']).to eql('10.0.0.100')
|
subject.endpoint('compute-api').path
|
||||||
end
|
).to eq('/v2/%25(tenant_id)s')
|
||||||
end
|
|
||||||
|
|
||||||
describe '#endpoints' do
|
|
||||||
it 'does nothing when no endpoints' do
|
|
||||||
@subject.stub(:node).and_return {}
|
|
||||||
@subject.endpoints.should be_nil
|
|
||||||
end
|
|
||||||
it 'does nothing when empty endpoints' do
|
|
||||||
@subject.stub(:node).and_return('openstack' => { 'endpoints' => {} })
|
|
||||||
@count = 0
|
|
||||||
@subject.endpoints do | ep |
|
|
||||||
@count += 1
|
|
||||||
end
|
end
|
||||||
@count.should == 0
|
|
||||||
end
|
it 'returns endpoint URI object when uri key in endpoint hash' do
|
||||||
it 'executes block count when have endpoints' do
|
uri_hash = {
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
'openstack' => {
|
||||||
@count = 0
|
'endpoints' => {
|
||||||
@subject.endpoints do |ep|
|
'compute-api' => {
|
||||||
@count += 1
|
'uri' => 'http://localhost:8080/path'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subject.stub(:node).and_return(uri_hash)
|
||||||
|
expect(
|
||||||
|
subject.endpoint('compute-api').port
|
||||||
|
).to eq(8080)
|
||||||
end
|
end
|
||||||
@count.should >= 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#db' do
|
it 'returns endpoint URI string when uri key in endpoint hash and host also in hash' do
|
||||||
it 'returns nil when no openstack.db not in node attrs' do
|
uri_hash = {
|
||||||
@subject.stub(:node).and_return {}
|
'openstack' => {
|
||||||
@subject.db('nonexisting').should be_nil
|
'endpoints' => {
|
||||||
end
|
'compute-api' => {
|
||||||
it 'returns nil when no such service was found' do
|
'uri' => 'http://localhost',
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
'host' => 'ignored'
|
||||||
@subject.db('nonexisting').should be_nil
|
}
|
||||||
end
|
}
|
||||||
it 'returns db info hash when service found' do
|
}
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
}
|
||||||
@subject.db('compute')['host'].should eq('127.0.0.1')
|
subject.stub(:node).and_return(uri_hash)
|
||||||
@subject.db('compute').key?('uri').should be_false
|
expect(subject.endpoint('compute-api').to_s).to eq('http://localhost')
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
describe '#db_uri' do
|
it 'returns endpoint URI object when uri key not in endpoint hash but host is in hash' do
|
||||||
it 'returns nil when no openstack.db not in node attrs' do
|
pending 'TODO: implement'
|
||||||
@subject.stub(:node).and_return {}
|
subject.should_receive(:uri_from_hash).with('host' => 'localhost', 'port' => '8080')
|
||||||
@subject.db_uri('nonexisting', 'user', 'pass').should be_nil
|
uri_hash = {
|
||||||
|
'openstack' => {
|
||||||
|
'endpoints' => {
|
||||||
|
'compute-api' => {
|
||||||
|
'host' => 'localhost',
|
||||||
|
'port' => '8080'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subject.stub(:node).and_return(uri_hash)
|
||||||
|
subject.endpoint 'compute-api'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'endpoints recipe bind_interface sets host' do
|
||||||
|
node.set['openstack']['endpoints']['identity-api']['bind_interface'] = 'eth0'
|
||||||
|
node.set['network'] = {
|
||||||
|
'interfaces' => {
|
||||||
|
'lo' => {
|
||||||
|
'addresses' => {
|
||||||
|
'127.0.0.1' => {
|
||||||
|
'family' => 'inet',
|
||||||
|
'netmask' => '255.0.0.0',
|
||||||
|
'scope' => 'Node'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'eth0' => {
|
||||||
|
'addresses' => {
|
||||||
|
'10.0.0.100' => {
|
||||||
|
'family' => 'inet',
|
||||||
|
'netmask' => '255.255.255.0',
|
||||||
|
'scope' => 'Global'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subject.stub('address_for').and_return('10.0.0.100')
|
||||||
|
expect(
|
||||||
|
chef_run.node['openstack']['endpoints']['identity-api']['host']
|
||||||
|
).to eq('10.0.0.100')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
it 'returns nil when no such service was found' do
|
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
describe '#endpoints' do
|
||||||
@subject.db_uri('nonexisting', 'user', 'pass').should be_nil
|
it 'does nothing when no endpoints' do
|
||||||
|
subject.stub(:node).and_return({})
|
||||||
|
expect(subject.endpoints).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does nothing when empty endpoints' do
|
||||||
|
subject.stub(:node).and_return('openstack' => { 'endpoints' => {} })
|
||||||
|
count = 0
|
||||||
|
subject.endpoints do | ep |
|
||||||
|
count += 1
|
||||||
|
end
|
||||||
|
expect(count).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'executes block count when have endpoints' do
|
||||||
|
subject.stub(:node).and_return(chef_run.node)
|
||||||
|
count = 0
|
||||||
|
subject.endpoints do |ep|
|
||||||
|
count += 1
|
||||||
|
end
|
||||||
|
expect(count).to be >= 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
it 'returns db info hash when service found' do
|
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
describe '#db' do
|
||||||
expect = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
|
it 'returns nil when no openstack.db not in node attrs' do
|
||||||
@subject.db_uri('compute', 'user', 'pass').should == expect
|
subject.stub(:node).and_return({})
|
||||||
|
expect(subject.db('nonexisting')).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil when no such service was found' do
|
||||||
|
subject.stub(:node).and_return(chef_run.node)
|
||||||
|
expect(subject.db('nonexisting')).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns db info hash when service found' do
|
||||||
|
subject.stub(:node).and_return(chef_run.node)
|
||||||
|
expect(subject.db('compute')['host']).to eq('127.0.0.1')
|
||||||
|
expect(subject.db('compute').key?('uri')).to be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#db_uri' do
|
||||||
|
it 'returns nil when no openstack.db not in node attrs' do
|
||||||
|
subject.stub(:node).and_return({})
|
||||||
|
expect(subject.db_uri('nonexisting', 'user', 'pass')).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil when no such service was found' do
|
||||||
|
subject.stub(:node).and_return(chef_run.node)
|
||||||
|
expect(
|
||||||
|
subject.db_uri('nonexisting', 'user', 'pass')
|
||||||
|
).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns db info hash when service found' do
|
||||||
|
subject.stub(:node).and_return(chef_run.node)
|
||||||
|
expected = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
|
||||||
|
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
|
|
||||||
|
|
||||||
describe '#address_for' do
|
include_context 'library-stubs'
|
||||||
it 'returns ipv4 address' do
|
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
|
||||||
resp = @subject.address_for 'lo'
|
|
||||||
|
|
||||||
expect(resp).to eq '127.0.0.1'
|
describe '#address_for' do
|
||||||
end
|
it 'returns ipv4 address' do
|
||||||
|
expect(
|
||||||
|
subject.address_for('lo')
|
||||||
|
).to eq('127.0.0.1')
|
||||||
|
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) }
|
||||||
|
|
||||||
describe '#secret' do
|
include_context 'library-stubs'
|
||||||
it 'returns index param when developer_mode is true' do
|
|
||||||
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
|
|
||||||
n.set['openstack']['developer_mode'] = true
|
|
||||||
end
|
|
||||||
@chef_run.converge 'openstack-common::default'
|
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
|
||||||
result = @subject.secret('passwords', 'nova')
|
|
||||||
result.should == 'nova'
|
|
||||||
end
|
|
||||||
it 'returns databag when developer_mode is false' do
|
|
||||||
value = { 'nova' => 'this' }
|
|
||||||
::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
|
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
|
||||||
result = @subject.secret('passwords', 'nova')
|
|
||||||
result.should == 'this'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#get_password_service_password' 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
|
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
|
|
||||||
it 'returns databag when developer_mode is false' do
|
|
||||||
value = { 'nova' => 'this' }
|
|
||||||
::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
|
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
|
||||||
result = @subject.get_password('service', 'nova')
|
|
||||||
result.should == 'this'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#get_password_db_password' do
|
it 'returns databag when developer_mode is false' do
|
||||||
it 'returns index param when developer_mode is true' do
|
value = { 'nova' => 'this' }
|
||||||
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
|
::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return('secret')
|
||||||
n.set['openstack']['developer_mode'] = true
|
::Chef::EncryptedDataBagItem.stub(:load).with('passwords', 'nova', 'secret').and_return(value)
|
||||||
|
expect(subject.secret('passwords', 'nova')).to eq('this')
|
||||||
end
|
end
|
||||||
@chef_run.converge 'openstack-common::default'
|
|
||||||
@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
|
|
||||||
value = { 'nova' => 'this' }
|
|
||||||
::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
|
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
|
||||||
result = @subject.get_password('db', 'nova')
|
|
||||||
result.should == 'this'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#get_password_user_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
|
||||||
|
|
||||||
|
it 'returns databag when developer_mode is false' do
|
||||||
|
value = { 'nova' => 'this' }
|
||||||
|
::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)
|
||||||
|
expect(
|
||||||
|
subject.get_password('service', 'nova')
|
||||||
|
).to eq('this')
|
||||||
end
|
end
|
||||||
@chef_run.converge 'openstack-common::default'
|
|
||||||
@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
|
|
||||||
value = { 'nova' => 'this' }
|
describe '#get_password_db_password' do
|
||||||
::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return 'secret'
|
it 'returns index param when developer_mode is true' do
|
||||||
::Chef::EncryptedDataBagItem.stub(:load).with('user_passwords', 'nova', 'secret').and_return value
|
node.set['openstack']['developer_mode'] = true
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
expect(
|
||||||
result = @subject.get_password('user', 'nova')
|
subject.get_password('db', 'nova')
|
||||||
result.should == 'this'
|
).to eq('nova')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns databag when developer_mode is false' do
|
||||||
|
value = { 'nova' => 'this' }
|
||||||
|
::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)
|
||||||
|
expect(
|
||||||
|
subject.get_password('db', 'nova')
|
||||||
|
).to eq('this')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#get_password_user_password' do
|
||||||
|
it 'returns index param when developer_mode is true' do
|
||||||
|
node.set['openstack']['developer_mode'] = true
|
||||||
|
expect(
|
||||||
|
subject.get_password('user', 'nova')
|
||||||
|
).to eq('nova')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns databag when developer_mode is false' do
|
||||||
|
value = { 'nova' => 'this' }
|
||||||
|
::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)
|
||||||
|
expect(
|
||||||
|
subject.get_password('user', 'nova')
|
||||||
|
).to eq('this')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,142 +1,139 @@
|
|||||||
# 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
|
||||||
|
|
||||||
|
runner.converge(described_recipe)
|
||||||
end
|
end
|
||||||
@chef_run.converge 'openstack-common::default'
|
let(:subject) { Object.new.extend(Openstack) }
|
||||||
@subject = ::Object.new.extend ::Openstack
|
|
||||||
end
|
|
||||||
|
|
||||||
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')
|
||||||
|
end
|
||||||
|
|
||||||
expect(resp[0]['fqdn']).to eq 'chefspec.local'
|
it 'returns empty results' do
|
||||||
|
subject.stub(:node).and_return(chef_run.node)
|
||||||
|
subject.stub(:search)
|
||||||
|
.with(:node, '(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)')
|
||||||
|
.and_return([])
|
||||||
|
expect(
|
||||||
|
subject.search_for('empty-role')
|
||||||
|
).to eq([])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'always returns empty results' do
|
||||||
|
subject.stub(:node).and_return(chef_run.node)
|
||||||
|
subject.stub(:search)
|
||||||
|
.with(:node, '(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)')
|
||||||
|
.and_return(nil)
|
||||||
|
expect(
|
||||||
|
subject.search_for('empty-role')
|
||||||
|
).to eq([])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns empty results' do
|
describe '#memcached_servers' do
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
it 'returns memcached list' do
|
||||||
@subject.stub(:search)
|
nodes = [
|
||||||
.with(:node, '(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)')
|
{ 'memcached' => { 'listen' => '1.1.1.1', 'port' => '11211' } },
|
||||||
.and_return []
|
{ 'memcached' => { 'listen' => '2.2.2.2', 'port' => '11211' } }
|
||||||
resp = @subject.search_for('empty-role')
|
]
|
||||||
|
subject.stub(:node).and_return(chef_run.node)
|
||||||
|
subject.stub(:search_for)
|
||||||
|
.with('role')
|
||||||
|
.and_return(nodes)
|
||||||
|
expect(
|
||||||
|
subject.memcached_servers('role')
|
||||||
|
).to eq(['1.1.1.1:11211', '2.2.2.2:11211'])
|
||||||
|
end
|
||||||
|
|
||||||
expect(resp).to eq []
|
it 'returns sorted memcached list' do
|
||||||
end
|
nodes = [
|
||||||
|
{ 'memcached' => { 'listen' => '3.3.3.3', 'port' => '11211' } },
|
||||||
|
{ 'memcached' => { 'listen' => '1.1.1.1', 'port' => '11211' } },
|
||||||
|
{ 'memcached' => { 'listen' => '2.2.2.2', 'port' => '11211' } }
|
||||||
|
]
|
||||||
|
subject.stub(:node).and_return(chef_run.node)
|
||||||
|
subject.stub(:search_for)
|
||||||
|
.with('role')
|
||||||
|
.and_return(nodes)
|
||||||
|
expect(
|
||||||
|
subject.memcached_servers('role')
|
||||||
|
).to eq(['1.1.1.1:11211', '2.2.2.2:11211', '3.3.3.3:11211'])
|
||||||
|
end
|
||||||
|
|
||||||
it 'always returns empty results' do
|
it 'returns memcached servers as defined by attributes' do
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
nodes = {
|
||||||
@subject.stub(:search)
|
'openstack' => {
|
||||||
.with(:node, '(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)')
|
'memcached_servers' => ['1.1.1.1:11211', '2.2.2.2:11211']
|
||||||
.and_return nil
|
}
|
||||||
resp = @subject.search_for('empty-role')
|
|
||||||
|
|
||||||
expect(resp).to eq []
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#memcached_servers' do
|
|
||||||
it 'returns memcached list' do
|
|
||||||
nodes = [
|
|
||||||
{ 'memcached' => { 'listen' => '1.1.1.1', 'port' => '11211' } },
|
|
||||||
{ 'memcached' => { 'listen' => '2.2.2.2', 'port' => '11211' } }
|
|
||||||
]
|
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
|
||||||
@subject.stub(:search_for)
|
|
||||||
.with('role')
|
|
||||||
.and_return nodes
|
|
||||||
resp = @subject.memcached_servers('role')
|
|
||||||
|
|
||||||
expect(resp).to eq ['1.1.1.1:11211', '2.2.2.2:11211']
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns sorted memcached list' do
|
|
||||||
nodes = [
|
|
||||||
{ 'memcached' => { 'listen' => '3.3.3.3', 'port' => '11211' } },
|
|
||||||
{ 'memcached' => { 'listen' => '1.1.1.1', 'port' => '11211' } },
|
|
||||||
{ 'memcached' => { 'listen' => '2.2.2.2', 'port' => '11211' } }
|
|
||||||
]
|
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
|
||||||
@subject.stub(:search_for)
|
|
||||||
.with('role')
|
|
||||||
.and_return nodes
|
|
||||||
resp = @subject.memcached_servers('role')
|
|
||||||
|
|
||||||
expect(resp).to eq ['1.1.1.1:11211', '2.2.2.2:11211', '3.3.3.3:11211']
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns memcached servers as defined by attributes' do
|
|
||||||
nodes = {
|
|
||||||
'openstack' => {
|
|
||||||
'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
|
expect(
|
||||||
resp = @subject.memcached_servers('role')
|
subject.memcached_servers('role')
|
||||||
|
).to eq(['1.1.1.1:11211', '2.2.2.2:11211'])
|
||||||
|
end
|
||||||
|
|
||||||
expect(resp).to eq ['1.1.1.1:11211', '2.2.2.2:11211']
|
it 'returns empty memcached servers as defined by attributes' do
|
||||||
end
|
nodes = {
|
||||||
|
'openstack' => {
|
||||||
it 'returns empty memcached servers as defined by attributes' do
|
'memcached_servers' => []
|
||||||
nodes = {
|
}
|
||||||
'openstack' => {
|
|
||||||
'memcached_servers' => []
|
|
||||||
}
|
}
|
||||||
}
|
subject.stub(:node).and_return(chef_run.node.merge(nodes))
|
||||||
@subject.stub(:node).and_return @chef_run.node.merge nodes
|
expect(
|
||||||
resp = @subject.memcached_servers('empty-role')
|
subject.memcached_servers('empty-role')
|
||||||
|
).to eq([])
|
||||||
expect(resp).to eq []
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#rabbit_servers' do
|
|
||||||
it 'returns rabbit servers' do
|
|
||||||
nodes = [
|
|
||||||
{ 'openstack' => { 'mq' => { 'listen' => '1.1.1.1', 'port' => '5672' } } },
|
|
||||||
{ 'openstack' => { 'mq' => { 'listen' => '2.2.2.2', 'port' => '5672' } } }
|
|
||||||
]
|
|
||||||
@subject.stub(:node).and_return @chef_run.node
|
|
||||||
@subject.stub(:search_for)
|
|
||||||
.and_return nodes
|
|
||||||
resp = @subject.rabbit_servers
|
|
||||||
|
|
||||||
expect(resp).to eq '1.1.1.1:5672,2.2.2.2:5672'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns sorted rabbit servers' do
|
describe '#rabbit_servers' do
|
||||||
nodes = [
|
it 'returns rabbit servers' do
|
||||||
{ 'openstack' => { 'mq' => { 'listen' => '3.3.3.3', 'port' => '5672' } } },
|
nodes = [
|
||||||
{ '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')
|
||||||
|
end
|
||||||
|
|
||||||
expect(resp).to eq '1.1.1.1:5672,2.2.2.2:5672,3.3.3.3:5672'
|
it 'returns sorted rabbit servers' do
|
||||||
end
|
nodes = [
|
||||||
|
{ 'openstack' => { 'mq' => { 'listen' => '3.3.3.3', 'port' => '5672' } } },
|
||||||
|
{ 'openstack' => { 'mq' => { 'listen' => '1.1.1.1', 'port' => '5672' } } },
|
||||||
|
{ 'openstack' => { 'mq' => { 'listen' => '2.2.2.2', 'port' => '5672' } } }
|
||||||
|
]
|
||||||
|
subject.stub(:node).and_return(chef_run.node)
|
||||||
|
subject.stub(:search_for)
|
||||||
|
.and_return(nodes)
|
||||||
|
expect(
|
||||||
|
subject.rabbit_servers
|
||||||
|
).to eq('1.1.1.1:5672,2.2.2.2:5672,3.3.3.3:5672')
|
||||||
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user