spec/beaker/dsl/helpers_spec.rb in beaker-1.12.2 vs spec/beaker/dsl/helpers_spec.rb in beaker-1.13.0
- old
+ new
@@ -208,10 +208,78 @@
subject.create_remote_file( hosts, '/remote/path', 'blah', my_opts )
end
end
+ describe '#create_tmpdir_for_user' do
+ let(:host) { double.as_null_object }
+ let(:result) { double.as_null_object }
+
+ before :each do
+ allow(host).to receive(:result).and_return(result)
+ allow(result).to receive(:exit_code).and_return(0)
+ allow(result).to receive(:stdout).and_return('puppet')
+ end
+
+ context 'with no user argument' do
+
+ context 'with no path name argument' do
+ context 'without puppet installed on host' do
+ it 'raises an error' do
+ allow(host).to receive(:tmpdir).and_return("tmpdirname")
+ allow(result).to receive(:exit_code).and_return(1)
+ expect(subject).to receive(:on).with(host, /^puppet.*/).and_return(result)
+ expect{
+ subject.create_tmpdir_for_user host
+ }.to raise_error(RuntimeError, /`puppet master --configprint` failed,/)
+ end
+ end
+ context 'with puppet installed on host' do
+ it 'executes chown once' do
+ expect(subject).to receive(:on).with(host, /^puppet.*/).and_return(result)
+ expect(subject).to receive(:on).with(host, /^getent passwd puppet/).and_return(result)
+ expect(host).to receive(:tmpdir).with(/\/tmp\/beaker.*/)
+ expect(subject).to receive(:on).with(host, /chown puppet.puppet.*/)
+ subject.create_tmpdir_for_user(host)
+ end
+ end
+ end
+
+ context 'with path name argument' do
+ it 'executes chown once' do
+ expect(subject).to receive(:on).with(host, /^puppet.*/).and_return(result)
+ expect(subject).to receive(:on).with(host, /^getent passwd puppet/).and_return(result)
+ expect(host).to receive(:tmpdir).with(/\/tmp\/bogus.*/).and_return("/tmp/bogus")
+ expect(subject).to receive(:on).with(host, /chown puppet.puppet \/tmp\/bogus.*/)
+ subject.create_tmpdir_for_user(host, "/tmp/bogus")
+ end
+ end
+
+ end
+
+ context 'with an invalid user argument' do
+ it 'executes chown once' do
+ allow(result).to receive(:stdout).and_return('curiousgeorge')
+ expect(subject).to receive(:on).with(host, /^getent passwd curiousgeorge/).and_return(result)
+ expect(host).to receive(:tmpdir).with(/\/tmp\/bogus.*/).and_return("/tmp/bogus")
+ expect(subject).to receive(:on).with(host, /chown curiousgeorge.curiousgeorge \/tmp\/bogus.*/)
+ subject.create_tmpdir_for_user(host, "/tmp/bogus", "curiousgeorge")
+ end
+ end
+
+ context 'with a valid user argument' do
+ it 'executes chown once' do
+ allow(result).to receive(:exit_code).and_return(1)
+ expect(subject).to receive(:on).with(host, /^getent passwd curiousgeorge/).and_return(result)
+ expect{
+ subject.create_tmpdir_for_user(host, "/tmp/bogus", "curiousgeorge")
+ }.to raise_error(RuntimeError, /User curiousgeorge does not exist on/)
+ end
+ end
+
+ end
+
describe '#run_script_on' do
it 'scps the script to a tmpdir and executes it on host(s)' do
subject.should_receive( :scp_to )
subject.should_receive( :on )
subject.run_script_on( 'host', '~/.bin/make-enterprisy' )
@@ -318,11 +386,11 @@
describe '#apply_manifest_on' do
it 'calls puppet' do
subject.should_receive( :create_remote_file ).and_return( true )
subject.should_receive( :puppet ).
- with( 'apply', '--verbose', 'agent' ).
+ # with( 'apply', '--verbose', 'agent' ).
and_return( 'puppet_command' )
subject.should_receive( :on ).
with( agent, 'puppet_command',
:acceptable_exit_codes => [0] )
@@ -334,57 +402,50 @@
the_hosts = [master, agent]
subject.should_receive( :create_remote_file ).twice.and_return( true )
the_hosts.each do |host|
subject.should_receive( :puppet ).
- with( 'apply', '--verbose', host.to_s ).
and_return( 'puppet_command' )
subject.should_receive( :on ).
- with( host, 'puppet_command',
- :acceptable_exit_codes => [0, 1] ).ordered
+ with( host, 'puppet_command', :acceptable_exit_codes => [0] )
end
- result = subject.apply_manifest_on( the_hosts, 'include foobar', :acceptable_exit_codes => [0,1] )
+ result = subject.apply_manifest_on( the_hosts, 'include foobar' )
result.should(be_an(Array))
end
it 'adds acceptable exit codes with :catch_failures' do
subject.should_receive( :create_remote_file ).and_return( true )
subject.should_receive( :puppet ).
- with( 'apply', '--verbose', '--trace', '--detailed-exitcodes', 'agent' ).
and_return( 'puppet_command' )
subject.should_receive( :on ).
with( agent, 'puppet_command',
:acceptable_exit_codes => [0,2] )
subject.apply_manifest_on( agent,
'class { "boo": }',
- :trace => true,
:catch_failures => true )
end
it 'allows acceptable exit codes through :catch_failures' do
subject.should_receive( :create_remote_file ).and_return( true )
subject.should_receive( :puppet ).
- with( 'apply', '--verbose', '--trace', '--detailed-exitcodes', 'agent' ).
and_return( 'puppet_command' )
subject.should_receive( :on ).
with( agent, 'puppet_command',
:acceptable_exit_codes => [4,0,2] )
subject.apply_manifest_on( agent,
'class { "boo": }',
:acceptable_exit_codes => [4],
- :trace => true,
:catch_failures => true )
end
it 'enforces a 0 exit code through :catch_changes' do
subject.should_receive( :create_remote_file ).and_return( true )
subject.should_receive( :puppet ).
- with( 'apply', '--verbose', '--trace', '--detailed-exitcodes', 'agent' ).
and_return( 'puppet_command' )
subject.should_receive( :on ).with(
agent,
'puppet_command',
@@ -392,18 +453,16 @@
)
subject.apply_manifest_on(
agent,
'class { "boo": }',
- :trace => true,
:catch_changes => true
)
end
it 'enforces a 2 exit code through :expect_changes' do
subject.should_receive( :create_remote_file ).and_return( true )
subject.should_receive( :puppet ).
- with( 'apply', '--verbose', '--trace', '--detailed-exitcodes', 'agent' ).
and_return( 'puppet_command' )
subject.should_receive( :on ).with(
agent,
'puppet_command',
@@ -411,18 +470,16 @@
)
subject.apply_manifest_on(
agent,
'class { "boo": }',
- :trace => true,
:expect_changes => true
)
end
it 'enforces exit codes through :expect_failures' do
subject.should_receive( :create_remote_file ).and_return( true )
subject.should_receive( :puppet ).
- with( 'apply', '--verbose', '--trace', '--detailed-exitcodes', 'agent' ).
and_return( 'puppet_command' )
subject.should_receive( :on ).with(
agent,
'puppet_command',
@@ -430,29 +487,26 @@
)
subject.apply_manifest_on(
agent,
'class { "boo": }',
- :trace => true,
:expect_failures => true
)
end
it 'enforces exit codes through :expect_failures' do
expect {
subject.apply_manifest_on(
agent,
'class { "boo": }',
- :trace => true,
:expect_failures => true,
:catch_failures => true
)
}.to raise_error ArgumentError, /catch_failures.+expect_failures/
end
it 'enforces added exit codes through :expect_failures' do
subject.should_receive( :create_remote_file ).and_return( true )
subject.should_receive( :puppet ).
- with( 'apply', '--verbose', '--trace', '--detailed-exitcodes', 'agent' ).
and_return( 'puppet_command' )
subject.should_receive( :on ).with(
agent,
'puppet_command',
@@ -461,30 +515,49 @@
subject.apply_manifest_on(
agent,
'class { "boo": }',
:acceptable_exit_codes => (1..5),
- :trace => true,
:expect_failures => true
)
end
it 'can set the --parser future flag' do
subject.should_receive( :create_remote_file ).and_return( true )
- subject.should_receive( :puppet ).
- with( 'apply', '--verbose', '--parser future', '--detailed-exitcodes', 'agent' ).
- and_return( 'puppet_command' )
- subject.should_receive( :on ).with(
+
+ expect( subject ).to receive( :on ).with {|h, command, opts|
+ cmdline = command.cmd_line( h )
+ expect( h ).to be == agent
+ expect( cmdline ).to include('puppet apply')
+ expect( cmdline ).to include('--parser=future')
+ expect( cmdline ).to include('--detailed-exitcodes')
+ expect( cmdline ).to include('--verbose')
+ }
+
+ subject.apply_manifest_on(
agent,
- 'puppet_command',
- :acceptable_exit_codes => [1,2,3,4,5,6]
+ 'class { "boo": }',
+ :acceptable_exit_codes => (1..5),
+ :future_parser => true,
+ :expect_failures => true
)
+ end
+ it 'can set the --noops flag' do
+ subject.should_receive( :create_remote_file ).and_return( true )
+ expect( subject ).to receive( :on ).with {|h, command, opts|
+ cmdline = command.cmd_line( h )
+ expect( h ).to be == agent
+ expect( cmdline ).to include('puppet apply')
+ expect( cmdline ).to include('--detailed-exitcodes')
+ expect( cmdline ).to include('--verbose')
+ expect( cmdline ).to include('--noop')
+ }
subject.apply_manifest_on(
agent,
'class { "boo": }',
:acceptable_exit_codes => (1..5),
- :future_parser => true,
+ :noop => true,
:expect_failures => true
)
end
end