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
|
# Strainerfile
|
||||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/Gemfile $SANDBOX/$COOKBOOK/metadata.rb --config $SANDBOX/$COOKBOOK/.rubocop.yml
|
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
|
# rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK
|
||||||
knife test: bundle exec knife cookbook test $COOKBOOK
|
knife test: bundle exec knife cookbook test $COOKBOOK
|
||||||
foodcritic: bundle exec foodcritic -f any -t ~FC003 -t ~FC023 $SANDBOX/$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 }
|
before { ops_messaging_stubs }
|
||||||
describe "ubuntu" do
|
describe 'ubuntu' do
|
||||||
before do
|
before do
|
||||||
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||||
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
@chef_run.converge 'openstack-ops-messaging::rabbitmq-server'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "overrides default rabbit attributes" do
|
it 'overrides default rabbit attributes' do
|
||||||
expect(@chef_run.node["openstack"]["mq"]["port"]).to eql "5672"
|
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['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']['address']).to eql '127.0.0.1'
|
||||||
expect(@chef_run.node["rabbitmq"]["default_user"]).to eql "guest"
|
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']['default_pass']).to eql 'rabbit-pass'
|
||||||
end
|
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|
|
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
|
||||||
n.set['openstack']['mq']['bind_interface'] = 'eth0'
|
n.set['openstack']['mq']['bind_interface'] = 'eth0'
|
||||||
n.set['openstack']['mq']['port'] = '4242'
|
n.set['openstack']['mq']['port'] = '4242'
|
||||||
@ -24,7 +25,7 @@ describe "openstack-ops-messaging::rabbitmq-server" do
|
|||||||
n.set['openstack']['mq']['vhost'] = '/bar'
|
n.set['openstack']['mq']['vhost'] = '/bar'
|
||||||
end
|
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']['listen']).to eql '33.44.55.66'
|
||||||
expect(chef_run.node['openstack']['mq']['port']).to eql '4242'
|
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'
|
expect(chef_run.node['openstack']['image']['rabbit']['vhost']).to eql '/bar'
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "cluster" do
|
describe 'cluster' do
|
||||||
before do
|
before do
|
||||||
@chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n|
|
@chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) do |n|
|
||||||
n.set["openstack"]["mq"] = {
|
n.set['openstack']['mq'] = {
|
||||||
"cluster" => true
|
'cluster' => true
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
@chef_run.converge 'openstack-ops-messaging::rabbitmq-server'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "overrides cluster" do
|
it 'overrides cluster' do
|
||||||
expect(@chef_run.node['rabbitmq']['cluster']).to be_true
|
expect(@chef_run.node['rabbitmq']['cluster']).to be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "overrides erlang_cookie" do
|
it 'overrides erlang_cookie' do
|
||||||
expect(@chef_run.node['rabbitmq']['erlang_cookie']).to eql(
|
expect(@chef_run.node['rabbitmq']['erlang_cookie']).to eql(
|
||||||
"erlang-cookie"
|
'erlang-cookie'
|
||||||
)
|
)
|
||||||
end
|
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(
|
expect(@chef_run.node['rabbitmq']['cluster_disk_nodes']).to eql(
|
||||||
["guest@host1", "guest@host2"]
|
['guest@host1', 'guest@host2']
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes rabbit recipes" do
|
it 'includes rabbit recipes' do
|
||||||
expect(@chef_run).to include_recipe "rabbitmq"
|
expect(@chef_run).to include_recipe 'rabbitmq'
|
||||||
expect(@chef_run).to include_recipe "rabbitmq::mgmt_console"
|
expect(@chef_run).to include_recipe 'rabbitmq::mgmt_console'
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "lwrps" do
|
describe 'lwrps' do
|
||||||
it "does not delete the guest user" 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
|
end
|
||||||
|
|
||||||
it "deletes a user not called 'guest'" do
|
it "deletes a user not called 'guest'" do
|
||||||
chef_run = ChefSpec::Runner.new(::UBUNTU_OPTS) do |node|
|
chef_run = ChefSpec::Runner.new(::UBUNTU_OPTS) do |node|
|
||||||
node.node.set["openstack"]["mq"]["user"] = "not-a-guest"
|
node.node.set['openstack']['mq']['user'] = 'not-a-guest'
|
||||||
end.converge("openstack-ops-messaging::rabbitmq-server")
|
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
|
end
|
||||||
|
|
||||||
it "adds user" do
|
it 'adds user' do
|
||||||
resource = @chef_run.find_resource(
|
resource = @chef_run.find_resource(
|
||||||
"rabbitmq_user",
|
'rabbitmq_user',
|
||||||
"add openstack rabbit user"
|
'add openstack rabbit user'
|
||||||
).to_hash
|
).to_hash
|
||||||
|
|
||||||
expect(resource).to include(
|
expect(resource).to include(
|
||||||
:user => "guest",
|
user: 'guest',
|
||||||
:password => "rabbit-pass",
|
password: 'rabbit-pass',
|
||||||
:action => [:add]
|
action: [:add]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "changes password" do
|
it 'changes password' do
|
||||||
resource = @chef_run.find_resource(
|
resource = @chef_run.find_resource(
|
||||||
"rabbitmq_user",
|
'rabbitmq_user',
|
||||||
"change openstack rabbit user password"
|
'change openstack rabbit user password'
|
||||||
).to_hash
|
).to_hash
|
||||||
|
|
||||||
expect(resource).to include(
|
expect(resource).to include(
|
||||||
:user => "guest",
|
user: 'guest',
|
||||||
:password => "rabbit-pass",
|
password: 'rabbit-pass',
|
||||||
:action => [:change_password]
|
action: [:change_password]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "adds vhost" do
|
it 'adds vhost' do
|
||||||
resource = @chef_run.find_resource(
|
resource = @chef_run.find_resource(
|
||||||
"rabbitmq_vhost",
|
'rabbitmq_vhost',
|
||||||
"add openstack rabbit vhost"
|
'add openstack rabbit vhost'
|
||||||
).to_hash
|
).to_hash
|
||||||
|
|
||||||
expect(resource).to include(
|
expect(resource).to include(
|
||||||
:vhost => "/",
|
vhost: '/',
|
||||||
:action => [:add]
|
action: [:add]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets user permissions" do
|
it 'sets user permissions' do
|
||||||
resource = @chef_run.find_resource(
|
resource = @chef_run.find_resource(
|
||||||
"rabbitmq_user",
|
'rabbitmq_user',
|
||||||
"set openstack user permissions"
|
'set openstack user permissions'
|
||||||
).to_hash
|
).to_hash
|
||||||
|
|
||||||
expect(resource).to include(
|
expect(resource).to include(
|
||||||
:user => "guest",
|
user: 'guest',
|
||||||
:vhost => "/",
|
vhost: '/',
|
||||||
:permissions => '.* .* .*',
|
permissions: '.* .* .*',
|
||||||
:action => [:set_permissions]
|
action: [:set_permissions]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets administrator tag" do
|
it 'sets administrator tag' do
|
||||||
resource = @chef_run.find_resource(
|
resource = @chef_run.find_resource(
|
||||||
"rabbitmq_user",
|
'rabbitmq_user',
|
||||||
"set rabbit administrator tag"
|
'set rabbit administrator tag'
|
||||||
).to_hash
|
).to_hash
|
||||||
|
|
||||||
expect(resource).to include(
|
expect(resource).to include(
|
||||||
:user => "guest",
|
user: 'guest',
|
||||||
:tag => "administrator",
|
tag: 'administrator',
|
||||||
:action => [:set_tags]
|
action: [:set_tags]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
|
# encoding: UTF-8
|
||||||
require_relative 'spec_helper'
|
require_relative 'spec_helper'
|
||||||
|
|
||||||
describe "openstack-ops-messaging::server" do
|
describe 'openstack-ops-messaging::server' do
|
||||||
before { ops_messaging_stubs }
|
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 = ::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
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,36 +1,37 @@
|
|||||||
require "chefspec"
|
# encoding: UTF-8
|
||||||
require "chefspec/berkshelf"
|
require 'chefspec'
|
||||||
require_relative "support/matcher"
|
require 'chefspec/berkshelf'
|
||||||
|
require_relative 'support/matcher'
|
||||||
|
|
||||||
::LOG_LEVEL = :fatal
|
::LOG_LEVEL = :fatal
|
||||||
::REDHAT_OPTS = {
|
::REDHAT_OPTS = {
|
||||||
:platform => "redhat",
|
platform: 'redhat',
|
||||||
:version => "6.3",
|
version: '6.3',
|
||||||
:log_level => ::LOG_LEVEL
|
log_level: ::LOG_LEVEL
|
||||||
}
|
}
|
||||||
::UBUNTU_OPTS = {
|
::UBUNTU_OPTS = {
|
||||||
:platform => "ubuntu",
|
platform: 'ubuntu',
|
||||||
:version => "12.04",
|
version: '12.04',
|
||||||
:log_level => ::LOG_LEVEL
|
log_level: ::LOG_LEVEL
|
||||||
}
|
}
|
||||||
|
|
||||||
def ops_messaging_stubs
|
def ops_messaging_stubs # rubocop:disable MethodLength
|
||||||
::Chef::Recipe.any_instance.stub(:address_for).
|
::Chef::Recipe.any_instance.stub(:address_for)
|
||||||
with("lo").
|
.with('lo')
|
||||||
and_return "127.0.0.1"
|
.and_return '127.0.0.1'
|
||||||
::Chef::Recipe.any_instance.stub(:address_for).
|
::Chef::Recipe.any_instance.stub(:address_for)
|
||||||
with("eth0").
|
.with('eth0')
|
||||||
and_return "33.44.55.66"
|
.and_return '33.44.55.66'
|
||||||
::Chef::Recipe.any_instance.stub(:search).
|
::Chef::Recipe.any_instance.stub(:search)
|
||||||
with(:node, "roles:os-ops-messaging AND chef_environment:_default").
|
.with(:node, 'roles:os-ops-messaging AND chef_environment:_default')
|
||||||
and_return [
|
.and_return [
|
||||||
{ 'hostname' => 'host2' },
|
{ 'hostname' => 'host2' },
|
||||||
{ 'hostname' => 'host1' }
|
{ 'hostname' => 'host1' }
|
||||||
]
|
]
|
||||||
::Chef::Recipe.any_instance.stub(:get_password).
|
::Chef::Recipe.any_instance.stub(:get_password)
|
||||||
with("user", anything()).
|
.with('user', anything)
|
||||||
and_return "rabbit-pass"
|
.and_return 'rabbit-pass'
|
||||||
::Chef::Recipe.any_instance.stub(:get_password).
|
::Chef::Recipe.any_instance.stub(:get_password)
|
||||||
with("service", "rabbit_cookie").
|
.with('service', 'rabbit_cookie')
|
||||||
and_return "erlang-cookie"
|
.and_return 'erlang-cookie'
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# encoding: UTF-8
|
||||||
# TODO(iartarisi) this should be submitted upstream and be a rabbitmq library
|
# TODO(iartarisi) this should be submitted upstream and be a rabbitmq library
|
||||||
def delete_rabbitmq_user(name)
|
def delete_rabbitmq_user(name)
|
||||||
ChefSpec::Matchers::ResourceMatcher.new(:rabbitmq_user, :delete, name)
|
ChefSpec::Matchers::ResourceMatcher.new(:rabbitmq_user, :delete, name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user