spec/beaker/dsl/roles_spec.rb in beaker-2.2.0 vs spec/beaker/dsl/roles_spec.rb in beaker-2.3.0
- old
+ new
@@ -7,10 +7,11 @@
end
describe ClassMixedWithDSLRoles do
let( :hosts ) { @hosts || Hash.new }
+ let( :options ) { @options || Hash.new }
let( :agent1 ) { make_host( 'agent1', { :roles => [ 'agent' ] } ) }
let( :agent2 ) { make_host( 'agent2', { :roles => [ 'agent' ] } ) }
let( :a_and_dash ) { make_host( 'a_and_dash', { :roles => [ 'agent', 'dashboard' ] } ) }
let( :custom ) { make_host( 'custom', { :roles => [ 'custom_role' ] } ) }
let( :db ) { make_host( 'db', { :roles => [ 'database' ] } ) }
@@ -40,10 +41,16 @@
it 'raises an error if there is more than one master' do
@hosts = [ master, monolith ]
expect( subject ).to receive( :hosts ).exactly( 1 ).times.and_return( hosts )
expect { subject.master }.to raise_error Beaker::DSL::FailTest
end
+ it 'returns nil if no master and masterless is set' do
+ @options = { :masterless => true }
+ expect( subject ).to receive( :hosts ).and_return( hosts )
+ expect( subject ).to receive( :options ).and_return( options )
+ expect( subject.master ).to be_nil
+ end
end
describe '#dashboard' do
it 'returns the dashboard if there is one' do
@hosts = [ a_and_dash, agent1 ]
expect( subject ).to receive( :hosts ).and_return( hosts )
@@ -57,10 +64,16 @@
it 'and raises an error if there is no dashboard' do
@hosts = [ agent1, agent2, custom ]
expect( subject ).to receive( :hosts ).and_return( hosts )
expect { subject.dashboard }.to raise_error Beaker::DSL::FailTest
end
+ it 'returns nil if no dashboard and masterless is set' do
+ @options = { :masterless => true }
+ expect( subject ).to receive( :hosts ).and_return( hosts )
+ expect( subject ).to receive( :options ).and_return( options )
+ expect( subject.dashboard ).to be_nil
+ end
end
describe '#database' do
it 'returns the database if there is one' do
@hosts = [ db, agent1 ]
expect( subject ).to receive( :hosts ).and_return( hosts )
@@ -74,25 +87,37 @@
it 'and raises an error if there is no database' do
@hosts = [ agent1, agent2, custom ]
expect( subject ).to receive( :hosts ).and_return( hosts )
expect { subject.database }.to raise_error Beaker::DSL::FailTest
end
+ it 'returns nil if no database and masterless is set' do
+ @options = { :masterless => true }
+ expect( subject ).to receive( :hosts ).and_return( hosts )
+ expect( subject ).to receive( :options ).and_return( options )
+ expect( subject.database ).to be_nil
+ end
end
describe '#default' do
it 'returns the default host when one is specified' do
@hosts = [ db, agent1, agent2, default, master]
expect( subject ).to receive( :hosts ).exactly( 1 ).times.and_return( hosts )
expect( subject.default ).to be == default
end
it 'raises an error if there is more than one default' do
@hosts = [ db, monolith, default, default ]
expect( subject ).to receive( :hosts ).and_return( hosts )
- expect { subject.database }.to raise_error Beaker::DSL::FailTest
+ expect { subject.default }.to raise_error Beaker::DSL::FailTest
end
it 'and raises an error if there is no default' do
@hosts = [ agent1, agent2, custom ]
expect( subject ).to receive( :hosts ).and_return( hosts )
- expect { subject.database }.to raise_error Beaker::DSL::FailTest
+ expect { subject.default }.to raise_error Beaker::DSL::FailTest
+ end
+ it 'returns nil if no default and masterless is set' do
+ @options = { :masterless => true }
+ expect( subject ).to receive( :hosts ).and_return( hosts )
+ expect( subject ).to receive( :options ).and_return( options )
+ expect( subject.default ).to be_nil
end
end
describe '#add_role_def' do
it 'raises an error on unsupported role format "1role"' do
expect { subject.add_role_def( "1role" ) }.to raise_error