Update spec to be rubocop compliant
- Add rubocop.yml in spec/ - Add spec rubocop tests in Strainerfile - Update spec files to comply with rubocop Change-Id: Ia1aabed7ab1ed21913e4783eec711c09777c9754 Addresses: blueprint rubocop-for-ops-messaging
This commit is contained in:
parent
34a0660afd
commit
53bf5ec59d
@ -1,5 +1,6 @@
|
||||
# Strainerfile
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/Gemfile $SANDBOX/$COOKBOOK/metadata.rb --config $SANDBOX/$COOKBOOK/.rubocop.yml
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/spec/ --config $SANDBOX/$COOKBOOK/spec/.rubocop.yml
|
||||
# rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK
|
||||
knife test: bundle exec knife cookbook test $COOKBOOK
|
||||
foodcritic: bundle exec foodcritic -f any -t ~FC003 -t ~FC023 $SANDBOX/$COOKBOOK
|
||||
|
7
spec/.rubocop.yml
Normal file
7
spec/.rubocop.yml
Normal file
@ -0,0 +1,7 @@
|
||||
# embedded attributes make for long lines
|
||||
LineLength:
|
||||
Enabled: false
|
||||
|
||||
# Allow small arrays before forcing %w or %W
|
||||
WordArray:
|
||||
MinSize: 3
|
@ -1,22 +1,23 @@
|
||||
require_relative "spec_helper"
|
||||
# encoding: UTF-8
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe "openstack-ops-messaging::rabbitmq-server" do
|
||||
describe 'openstack-ops-messaging::rabbitmq-server' do
|
||||
before { ops_messaging_stubs }
|
||||
describe "ubuntu" do
|
||||
describe 'ubuntu' do
|
||||
before do
|
||||
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
||||
@chef_run.converge 'openstack-ops-messaging::rabbitmq-server'
|
||||
end
|
||||
|
||||
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"
|
||||
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'
|
||||
end
|
||||
|
||||
it "overrides rabbit and openstack image attributes" do
|
||||
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'
|
||||
@ -24,7 +25,7 @@ describe "openstack-ops-messaging::rabbitmq-server" do
|
||||
n.set['openstack']['mq']['vhost'] = '/bar'
|
||||
end
|
||||
|
||||
chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
||||
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'
|
||||
@ -35,113 +36,113 @@ describe "openstack-ops-messaging::rabbitmq-server" do
|
||||
expect(chef_run.node['openstack']['image']['rabbit']['vhost']).to eql '/bar'
|
||||
end
|
||||
|
||||
describe "cluster" do
|
||||
describe 'cluster' do
|
||||
before do
|
||||
@chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n|
|
||||
n.set["openstack"]["mq"] = {
|
||||
"cluster" => true
|
||||
n.set['openstack']['mq'] = {
|
||||
'cluster' => true
|
||||
}
|
||||
end
|
||||
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
||||
@chef_run.converge 'openstack-ops-messaging::rabbitmq-server'
|
||||
end
|
||||
|
||||
it "overrides cluster" do
|
||||
it 'overrides cluster' do
|
||||
expect(@chef_run.node['rabbitmq']['cluster']).to be_true
|
||||
end
|
||||
|
||||
it "overrides erlang_cookie" do
|
||||
it 'overrides erlang_cookie' do
|
||||
expect(@chef_run.node['rabbitmq']['erlang_cookie']).to eql(
|
||||
"erlang-cookie"
|
||||
'erlang-cookie'
|
||||
)
|
||||
end
|
||||
|
||||
it "overrides and sorts cluster_disk_nodes" do
|
||||
it 'overrides and sorts cluster_disk_nodes' do
|
||||
expect(@chef_run.node['rabbitmq']['cluster_disk_nodes']).to eql(
|
||||
["guest@host1", "guest@host2"]
|
||||
['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"
|
||||
it 'includes rabbit recipes' do
|
||||
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")
|
||||
describe 'lwrps' do
|
||||
it 'does not delete the guest user' do
|
||||
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'
|
||||
end.converge('openstack-ops-messaging::rabbitmq-server')
|
||||
|
||||
expect(chef_run).to delete_rabbitmq_user("remove rabbit guest user")
|
||||
expect(chef_run).to delete_rabbitmq_user('remove rabbit guest user')
|
||||
end
|
||||
|
||||
it "adds user" do
|
||||
it 'adds user' do
|
||||
resource = @chef_run.find_resource(
|
||||
"rabbitmq_user",
|
||||
"add openstack rabbit user"
|
||||
'rabbitmq_user',
|
||||
'add openstack rabbit user'
|
||||
).to_hash
|
||||
|
||||
expect(resource).to include(
|
||||
:user => "guest",
|
||||
:password => "rabbit-pass",
|
||||
:action => [:add]
|
||||
user: 'guest',
|
||||
password: 'rabbit-pass',
|
||||
action: [:add]
|
||||
)
|
||||
end
|
||||
|
||||
it "changes password" do
|
||||
it 'changes password' do
|
||||
resource = @chef_run.find_resource(
|
||||
"rabbitmq_user",
|
||||
"change openstack rabbit user password"
|
||||
'rabbitmq_user',
|
||||
'change openstack rabbit user password'
|
||||
).to_hash
|
||||
|
||||
expect(resource).to include(
|
||||
:user => "guest",
|
||||
:password => "rabbit-pass",
|
||||
:action => [:change_password]
|
||||
user: 'guest',
|
||||
password: 'rabbit-pass',
|
||||
action: [:change_password]
|
||||
)
|
||||
end
|
||||
|
||||
it "adds vhost" do
|
||||
it 'adds vhost' do
|
||||
resource = @chef_run.find_resource(
|
||||
"rabbitmq_vhost",
|
||||
"add openstack rabbit vhost"
|
||||
'rabbitmq_vhost',
|
||||
'add openstack rabbit vhost'
|
||||
).to_hash
|
||||
|
||||
expect(resource).to include(
|
||||
:vhost => "/",
|
||||
:action => [:add]
|
||||
vhost: '/',
|
||||
action: [:add]
|
||||
)
|
||||
end
|
||||
|
||||
it "sets user permissions" do
|
||||
it 'sets user permissions' do
|
||||
resource = @chef_run.find_resource(
|
||||
"rabbitmq_user",
|
||||
"set openstack user permissions"
|
||||
'rabbitmq_user',
|
||||
'set openstack user permissions'
|
||||
).to_hash
|
||||
|
||||
expect(resource).to include(
|
||||
:user => "guest",
|
||||
:vhost => "/",
|
||||
:permissions => '.* .* .*',
|
||||
:action => [:set_permissions]
|
||||
user: 'guest',
|
||||
vhost: '/',
|
||||
permissions: '.* .* .*',
|
||||
action: [:set_permissions]
|
||||
)
|
||||
end
|
||||
|
||||
it "sets administrator tag" do
|
||||
it 'sets administrator tag' do
|
||||
resource = @chef_run.find_resource(
|
||||
"rabbitmq_user",
|
||||
"set rabbit administrator tag"
|
||||
'rabbitmq_user',
|
||||
'set rabbit administrator tag'
|
||||
).to_hash
|
||||
|
||||
expect(resource).to include(
|
||||
:user => "guest",
|
||||
:tag => "administrator",
|
||||
:action => [:set_tags]
|
||||
user: 'guest',
|
||||
tag: 'administrator',
|
||||
action: [:set_tags]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -1,14 +1,15 @@
|
||||
# encoding: UTF-8
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe "openstack-ops-messaging::server" do
|
||||
describe 'openstack-ops-messaging::server' do
|
||||
before { ops_messaging_stubs }
|
||||
describe "ubuntu" do
|
||||
describe 'ubuntu' do
|
||||
|
||||
it "uses proper messaging server recipe" do
|
||||
it 'uses proper messaging server recipe' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||
chef_run.converge "openstack-ops-messaging::server"
|
||||
chef_run.converge 'openstack-ops-messaging::server'
|
||||
|
||||
expect(chef_run).to include_recipe "openstack-ops-messaging::rabbitmq-server"
|
||||
expect(chef_run).to include_recipe 'openstack-ops-messaging::rabbitmq-server'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,36 +1,37 @@
|
||||
require "chefspec"
|
||||
require "chefspec/berkshelf"
|
||||
require_relative "support/matcher"
|
||||
# encoding: UTF-8
|
||||
require 'chefspec'
|
||||
require 'chefspec/berkshelf'
|
||||
require_relative 'support/matcher'
|
||||
|
||||
::LOG_LEVEL = :fatal
|
||||
::REDHAT_OPTS = {
|
||||
:platform => "redhat",
|
||||
:version => "6.3",
|
||||
:log_level => ::LOG_LEVEL
|
||||
platform: 'redhat',
|
||||
version: '6.3',
|
||||
log_level: ::LOG_LEVEL
|
||||
}
|
||||
::UBUNTU_OPTS = {
|
||||
:platform => "ubuntu",
|
||||
:version => "12.04",
|
||||
:log_level => ::LOG_LEVEL
|
||||
platform: 'ubuntu',
|
||||
version: '12.04',
|
||||
log_level: ::LOG_LEVEL
|
||||
}
|
||||
|
||||
def ops_messaging_stubs
|
||||
::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 [
|
||||
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"
|
||||
::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
|
||||
|
@ -1,3 +1,4 @@
|
||||
# encoding: UTF-8
|
||||
# TODO(iartarisi) this should be submitted upstream and be a rabbitmq library
|
||||
def delete_rabbitmq_user(name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:rabbitmq_user, :delete, name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user