spec/support/shared_matcher_examples.rb in serverspec-0.3.0 vs spec/support/shared_matcher_examples.rb in serverspec-0.3.1
- old
+ new
@@ -251,9 +251,162 @@
end
end
end
+shared_examples_for 'support be_default_gateway matcher' do
+ describe 'be_default_gateway' do
+ before :all do
+ RSpec.configure do |c|
+ c.stdout = "default via 192.168.1.1 dev eth1 \r\n"
+ end
+ end
+
+ describe '192.168.1.1' do
+ it { should be_default_gateway }
+ it { should be_default_gateway.with_interface('eth1') }
+ it { should_not be_default_gateway.with_interface('eth0') }
+ end
+
+ describe '192.168.1.100' do
+ it { should_not be_default_gateway }
+ it { should_not be_default_gateway.with_interface('eth1') }
+ end
+ end
+end
+
+shared_examples_for 'support have_entry matcher' do
+ describe 'have_entry' do
+ before :all do
+ RSpec.configure do |c|
+ c.stdout = "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n"
+ end
+ end
+
+ describe 'routing table' do
+ it { should have_entry( :destination => '192.168.100.0/24' ) }
+ it { should_not have_entry( :destination => '192.168.100.100/24' ) }
+
+ it do
+ should have_entry(
+ :destination => '192.168.100.0/24',
+ :gateway => '192.168.100.1'
+ )
+ end
+
+ it do
+ should have_entry(
+ :destination => '192.168.100.0/24',
+ :gateway => '192.168.100.1',
+ :interface => 'eth1'
+ )
+ end
+
+ it do
+ should_not have_entry(
+ :gateway => '192.168.100.1',
+ :interface => 'eth1'
+ )
+ end
+
+ it do
+ should_not have_entry(
+ :destination => '192.168.100.0/32',
+ :gateway => '192.168.100.1',
+ :interface => 'eth1'
+ )
+ end
+ end
+ end
+
+ describe 'have_entry' do
+ before :all do
+ RSpec.configure do |c|
+ c.stdout = "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n"
+ end
+ end
+
+ describe 'routing table' do
+ it { should have_entry( :destination => '192.168.200.0/24' ) }
+ it { should_not have_entry( :destination => '192.168.200.200/24' ) }
+
+ it do
+ should have_entry(
+ :destination => '192.168.200.0/24',
+ :gateway => '192.168.200.1'
+ )
+ end
+
+ it do
+ should have_entry(
+ :destination => '192.168.200.0/24',
+ :gateway => '192.168.200.1',
+ :interface => 'eth0'
+ )
+ end
+
+ it do
+ should_not have_entry(
+ :gateway => '192.168.200.1',
+ :interface => 'eth0'
+ )
+ end
+
+ it do
+ should_not have_entry(
+ :destination => '192.168.200.0/32',
+ :gateway => '192.168.200.1',
+ :interface => 'eth0'
+ )
+ end
+ end
+ end
+
+ describe 'have_entry' do
+ before :all do
+ RSpec.configure do |c|
+ c.stdout = "default via 10.0.2.2 dev eth0 \r\n"
+ end
+ end
+
+ describe 'routing table' do
+ it { should have_entry( :destination => 'default' ) }
+ it { should_not have_entry( :destination => 'defaulth' ) }
+
+ it do
+ should have_entry(
+ :destination => 'default',
+ :gateway => '10.0.2.2'
+ )
+ end
+
+ it do
+ should have_entry(
+ :destination => 'default',
+ :gateway => '10.0.2.2',
+ :interface => 'eth0'
+ )
+ end
+
+ it do
+ should_not have_entry(
+ :gateway => '10.0.2.2',
+ :interface => 'eth0'
+ )
+ end
+
+ it do
+ should_not have_entry(
+ :destination => 'default',
+ :gateway => '10.0.2.1',
+ :interface => 'eth0'
+ )
+ end
+ end
+ end
+end
+
+
shared_examples_for 'support be_resolvable matcher' do |valid_name|
describe 'be_resolvable' do
describe valid_name do
it { should be_resolvable }
end