Skip to content

Commit

Permalink
Update unit tests to handle new -q flag
Browse files Browse the repository at this point in the history
Updated the rabbitmq_user, rabbitmq_user_permissions, and
rabbitmq_vhost spec tests to correctly mock the rabbitmqctl command
with the -q flag. Also added one missed -q to a list users call.
  • Loading branch information
Colleen Murphy committed Nov 5, 2014
1 parent 7adb318 commit 87d39e8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def make_user_admin

private
def get_user_tags
match = rabbitmqctl('list_users').split(/\n/)[1..-2].collect do |line|
match = rabbitmqctl('-q', 'list_users').split(/\n/).collect do |line|
line.match(/^#{Regexp.escape(resource[:name])}\s+\[(.*?)\]/)
end.compact.first
Set.new(match[1].split(/, /)) if match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
@provider.admin.should == :false
end
it 'should fail if admin value is invalid' do
@provider.expects(:rabbitmqctl).with('q', 'list_users').returns <<-EOT
@provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT
foo fail
EOT
expect { @provider.admin }.to raise_error(Puppet::Error, /Could not match line/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,25 @@
@provider_class.instance_variable_set(:@users, nil)
end
it 'should match user permissions from list' do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
Listing users ...
@provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT
bar 1 2 3
...done.
EOT
@provider.exists?.should == {:configure=>"1", :write=>"2", :read=>"3"}
end
it 'should match user permissions with empty columns' do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
Listing users ...
@provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT
bar 3
...done.
EOT
@provider.exists?.should == {:configure=>"", :write=>"", :read=>"3"}
end
it 'should not match user permissions with more than 3 columns' do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
Listing users ...
@provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT
bar 1 2 3 4
...done.
EOT
expect { @provider.exists? }.to raise_error(Puppet::Error, /cannot parse line from list_user_permissions/)
end
it 'should not match an empty list' do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
Listing users ...
...done.
@provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT
EOT
@provider.exists?.should == nil
end
Expand All @@ -59,20 +51,16 @@
end
{:configure_permission => '1', :write_permission => '2', :read_permission => '3'}.each do |k,v|
it "should be able to retrieve #{k}" do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
Listing users ...
@provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT
bar 1 2 3
...done.
EOT
@provider.send(k).should == v
end
end
{:configure_permission => '1', :write_permission => '2', :read_permission => '3'}.each do |k,v|
it "should be able to retrieve #{k} after exists has been called" do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
Listing users ...
@provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT
bar 1 2 3
...done.
EOT
@provider.exists?
@provider.send(k).should == v
Expand All @@ -83,21 +71,17 @@
:write_permission => ['1', 'foo', '3']
}.each do |perm, columns|
it "should be able to sync #{perm}" do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
Listing users ...
@provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT
bar 1 2 3
...done.
EOT
@provider.resource[perm] = 'foo'
@provider.expects(:rabbitmqctl).with('set_permissions', '-p', 'bar', 'foo', *columns)
@provider.send("#{perm}=".to_sym, 'foo')
end
end
it 'should only call set_permissions once' do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
Listing users ...
@provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT
bar 1 2 3
...done.
EOT
@provider.resource[:configure_permission] = 'foo'
@provider.resource[:read_permission] = 'foo'
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
@provider = provider_class.new(@resource)
end
it 'should match vhost names' do
@provider.expects(:rabbitmqctl).with('list_vhosts').returns <<-EOT
@provider.expects(:rabbitmqctl).with('-q', 'list_vhosts').returns <<-EOT
Listing vhosts ...
foo
...done.
EOT
@provider.exists?.should == 'foo'
end
it 'should not match if no vhosts on system' do
@provider.expects(:rabbitmqctl).with('list_vhosts').returns <<-EOT
@provider.expects(:rabbitmqctl).with('-q', 'list_vhosts').returns <<-EOT
Listing vhosts ...
...done.
EOT
@provider.exists?.should be_nil
end
it 'should not match if no matching vhosts on system' do
@provider.expects(:rabbitmqctl).with('list_vhosts').returns <<-EOT
@provider.expects(:rabbitmqctl).with('-q', 'list_vhosts').returns <<-EOT
Listing vhosts ...
fooey
...done.
Expand Down

0 comments on commit 87d39e8

Please sign in to comment.