Refactoring chefspec tests
Change-Id: Ifb11af44da87fec7a8d0018a7db36bbd8b1989de Addresses: blueprint refactor-spec-files
This commit is contained in:
parent
bc66b00cd9
commit
40f8140e17
|
@ -3,16 +3,14 @@ require_relative 'spec_helper'
|
|||
|
||||
describe 'openstack-ops-messaging::rabbitmq-server' do
|
||||
describe 'redhat' do
|
||||
before { ops_messaging_stubs }
|
||||
|
||||
let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
let(:chef_run) { runner.converge(described_recipe) }
|
||||
|
||||
include_context 'ops_messaging_stubs'
|
||||
|
||||
it 'does not set use_distro_version to true' do
|
||||
expect(chef_run.node['rabbitmq']['use_distro_version']).to eql false
|
||||
expect(chef_run.node['rabbitmq']['use_distro_version']).to be_false
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,88 +2,78 @@
|
|||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-ops-messaging::rabbitmq-server' do
|
||||
before { ops_messaging_stubs }
|
||||
describe 'ubuntu' do
|
||||
before do
|
||||
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||
@chef_run.converge 'openstack-ops-messaging::rabbitmq-server'
|
||||
end
|
||||
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) { runner.converge(described_recipe) }
|
||||
|
||||
include_context 'ops_messaging_stubs'
|
||||
|
||||
it 'overrides default rabbit attributes' do
|
||||
expect(@chef_run.node['openstack']['mq']['port']).to eql '5672'
|
||||
expect(@chef_run.node['openstack']['mq']['listen']).to eql '127.0.0.1'
|
||||
expect(@chef_run.node['rabbitmq']['address']).to eql '127.0.0.1'
|
||||
expect(@chef_run.node['rabbitmq']['default_user']).to eql 'guest'
|
||||
expect(@chef_run.node['rabbitmq']['default_pass']).to eql 'rabbit-pass'
|
||||
expect(@chef_run.node['rabbitmq']['use_distro_version']).to eql true
|
||||
expect(chef_run.node['openstack']['mq']['port']).to eq('5672')
|
||||
expect(chef_run.node['openstack']['mq']['listen']).to eq('127.0.0.1')
|
||||
expect(chef_run.node['rabbitmq']['address']).to eq('127.0.0.1')
|
||||
expect(chef_run.node['rabbitmq']['default_user']).to eq('guest')
|
||||
expect(chef_run.node['rabbitmq']['default_pass']).to eq('rabbit-pass')
|
||||
expect(chef_run.node['rabbitmq']['use_distro_version']).to be_true
|
||||
end
|
||||
|
||||
it 'overrides rabbit and openstack image attributes' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
|
||||
n.set['openstack']['mq']['bind_interface'] = 'eth0'
|
||||
n.set['openstack']['mq']['port'] = '4242'
|
||||
n.set['openstack']['mq']['user'] = 'foo'
|
||||
n.set['openstack']['mq']['vhost'] = '/bar'
|
||||
end
|
||||
node.set['openstack']['mq']['bind_interface'] = 'eth0'
|
||||
node.set['openstack']['mq']['port'] = '4242'
|
||||
node.set['openstack']['mq']['user'] = 'foo'
|
||||
node.set['openstack']['mq']['vhost'] = '/bar'
|
||||
|
||||
chef_run.converge 'openstack-ops-messaging::rabbitmq-server'
|
||||
|
||||
expect(chef_run.node['openstack']['mq']['listen']).to eql '33.44.55.66'
|
||||
expect(chef_run.node['openstack']['mq']['port']).to eql '4242'
|
||||
expect(chef_run.node['openstack']['mq']['user']).to eql 'foo'
|
||||
expect(chef_run.node['openstack']['mq']['vhost']).to eql '/bar'
|
||||
expect(chef_run.node['openstack']['mq']['image']['rabbit']['port']).to eql '4242'
|
||||
expect(chef_run.node['openstack']['mq']['image']['rabbit']['userid']).to eql 'foo'
|
||||
expect(chef_run.node['openstack']['mq']['image']['rabbit']['vhost']).to eql '/bar'
|
||||
expect(chef_run.node['openstack']['mq']['listen']).to eq('33.44.55.66')
|
||||
expect(chef_run.node['openstack']['mq']['port']).to eq('4242')
|
||||
expect(chef_run.node['openstack']['mq']['user']).to eq('foo')
|
||||
expect(chef_run.node['openstack']['mq']['vhost']).to eq('/bar')
|
||||
expect(chef_run.node['openstack']['mq']['image']['rabbit']['port']).to eq('4242')
|
||||
expect(chef_run.node['openstack']['mq']['image']['rabbit']['userid']).to eq('foo')
|
||||
expect(chef_run.node['openstack']['mq']['image']['rabbit']['vhost']).to eq('/bar')
|
||||
end
|
||||
|
||||
describe 'cluster' do
|
||||
before do
|
||||
@chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n|
|
||||
n.set['openstack']['mq'] = {
|
||||
'cluster' => true
|
||||
}
|
||||
end
|
||||
@chef_run.converge 'openstack-ops-messaging::rabbitmq-server'
|
||||
node.set['openstack']['mq'] = {
|
||||
'cluster' => true
|
||||
}
|
||||
end
|
||||
|
||||
it 'overrides cluster' do
|
||||
expect(@chef_run.node['rabbitmq']['cluster']).to be_true
|
||||
expect(chef_run.node['rabbitmq']['cluster']).to be_true
|
||||
end
|
||||
|
||||
it 'overrides erlang_cookie' do
|
||||
expect(@chef_run.node['rabbitmq']['erlang_cookie']).to eql(
|
||||
expect(chef_run.node['rabbitmq']['erlang_cookie']).to eq(
|
||||
'erlang-cookie'
|
||||
)
|
||||
end
|
||||
|
||||
it 'overrides and sorts cluster_disk_nodes' do
|
||||
expect(@chef_run.node['rabbitmq']['cluster_disk_nodes']).to eql(
|
||||
expect(chef_run.node['rabbitmq']['cluster_disk_nodes']).to eq(
|
||||
['guest@host1', 'guest@host2']
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
it 'includes rabbit recipes' do
|
||||
expect(@chef_run).to include_recipe 'rabbitmq'
|
||||
expect(@chef_run).to include_recipe 'rabbitmq::mgmt_console'
|
||||
expect(chef_run).to include_recipe 'rabbitmq'
|
||||
expect(chef_run).to include_recipe 'rabbitmq::mgmt_console'
|
||||
end
|
||||
|
||||
describe 'lwrps' do
|
||||
it 'does not delete the guest user' do
|
||||
expect(@chef_run).not_to delete_rabbitmq_user('remove rabbit guest user')
|
||||
expect(chef_run).not_to delete_rabbitmq_user('remove rabbit guest user')
|
||||
end
|
||||
|
||||
it "deletes a user not called 'guest'" do
|
||||
chef_run = ChefSpec::Runner.new(::UBUNTU_OPTS) do |node|
|
||||
node.node.set['openstack']['mq']['user'] = 'not-a-guest'
|
||||
end.converge('openstack-ops-messaging::rabbitmq-server')
|
||||
|
||||
node.node.set['openstack']['mq']['user'] = 'not-a-guest'
|
||||
expect(chef_run).to delete_rabbitmq_user('remove rabbit guest user')
|
||||
end
|
||||
|
||||
it 'adds user' do
|
||||
resource = @chef_run.find_resource(
|
||||
resource = chef_run.find_resource(
|
||||
'rabbitmq_user',
|
||||
'add openstack rabbit user'
|
||||
).to_hash
|
||||
|
@ -96,7 +86,7 @@ describe 'openstack-ops-messaging::rabbitmq-server' do
|
|||
end
|
||||
|
||||
it 'changes password' do
|
||||
resource = @chef_run.find_resource(
|
||||
resource = chef_run.find_resource(
|
||||
'rabbitmq_user',
|
||||
'change openstack rabbit user password'
|
||||
).to_hash
|
||||
|
@ -109,7 +99,7 @@ describe 'openstack-ops-messaging::rabbitmq-server' do
|
|||
end
|
||||
|
||||
it 'adds vhost' do
|
||||
resource = @chef_run.find_resource(
|
||||
resource = chef_run.find_resource(
|
||||
'rabbitmq_vhost',
|
||||
'add openstack rabbit vhost'
|
||||
).to_hash
|
||||
|
@ -121,7 +111,7 @@ describe 'openstack-ops-messaging::rabbitmq-server' do
|
|||
end
|
||||
|
||||
it 'sets user permissions' do
|
||||
resource = @chef_run.find_resource(
|
||||
resource = chef_run.find_resource(
|
||||
'rabbitmq_user',
|
||||
'set openstack user permissions'
|
||||
).to_hash
|
||||
|
@ -135,7 +125,7 @@ describe 'openstack-ops-messaging::rabbitmq-server' do
|
|||
end
|
||||
|
||||
it 'sets administrator tag' do
|
||||
resource = @chef_run.find_resource(
|
||||
resource = chef_run.find_resource(
|
||||
'rabbitmq_user',
|
||||
'set rabbit administrator tag'
|
||||
).to_hash
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-ops-messaging::server' do
|
||||
before { ops_messaging_stubs }
|
||||
describe 'ubuntu' do
|
||||
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) { runner.converge(described_recipe) }
|
||||
|
||||
include_context 'ops_messaging_stubs'
|
||||
|
||||
it 'uses proper messaging server recipe' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||
chef_run.converge 'openstack-ops-messaging::server'
|
||||
|
||||
expect(chef_run).to include_recipe 'openstack-ops-messaging::rabbitmq-server'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,37 +3,39 @@ require 'chefspec'
|
|||
require 'chefspec/berkshelf'
|
||||
require_relative 'support/matcher'
|
||||
|
||||
::LOG_LEVEL = :fatal
|
||||
::REDHAT_OPTS = {
|
||||
LOG_LEVEL = :fatal
|
||||
REDHAT_OPTS = {
|
||||
platform: 'redhat',
|
||||
version: '6.5',
|
||||
log_level: ::LOG_LEVEL
|
||||
}
|
||||
::UBUNTU_OPTS = {
|
||||
UBUNTU_OPTS = {
|
||||
platform: 'ubuntu',
|
||||
version: '12.04',
|
||||
log_level: ::LOG_LEVEL
|
||||
}
|
||||
|
||||
def ops_messaging_stubs # rubocop:disable MethodLength
|
||||
::Chef::Recipe.any_instance.stub(:address_for)
|
||||
.with('lo')
|
||||
.and_return '127.0.0.1'
|
||||
::Chef::Recipe.any_instance.stub(:address_for)
|
||||
.with('eth0')
|
||||
.and_return '33.44.55.66'
|
||||
::Chef::Recipe.any_instance.stub(:search)
|
||||
.with(:node, 'roles:os-ops-messaging AND chef_environment:_default')
|
||||
.and_return [
|
||||
{ 'hostname' => 'host2' },
|
||||
{ 'hostname' => 'host1' }
|
||||
]
|
||||
::Chef::Recipe.any_instance.stub(:get_password)
|
||||
.with('user', anything)
|
||||
.and_return 'rabbit-pass'
|
||||
::Chef::Recipe.any_instance.stub(:get_password)
|
||||
.with('service', 'rabbit_cookie')
|
||||
.and_return 'erlang-cookie'
|
||||
shared_context 'ops_messaging_stubs' do
|
||||
before do
|
||||
::Chef::Recipe.any_instance.stub(:address_for)
|
||||
.with('lo')
|
||||
.and_return '127.0.0.1'
|
||||
::Chef::Recipe.any_instance.stub(:address_for)
|
||||
.with('eth0')
|
||||
.and_return '33.44.55.66'
|
||||
::Chef::Recipe.any_instance.stub(:search)
|
||||
.with(:node, 'roles:os-ops-messaging AND chef_environment:_default')
|
||||
.and_return [
|
||||
{ 'hostname' => 'host2' },
|
||||
{ 'hostname' => 'host1' }
|
||||
]
|
||||
::Chef::Recipe.any_instance.stub(:get_password)
|
||||
.with('user', anything)
|
||||
.and_return 'rabbit-pass'
|
||||
::Chef::Recipe.any_instance.stub(:get_password)
|
||||
.with('service', 'rabbit_cookie')
|
||||
.and_return 'erlang-cookie'
|
||||
end
|
||||
end
|
||||
|
||||
# README(galstrom21): This will remove any coverage warnings from
|
||||
|
|
Loading…
Reference in New Issue