spec/methods_spec.rb in sloe-0.8.5 vs spec/methods_spec.rb in sloe-0.8.6

- old
+ new

@@ -1,107 +1,74 @@ require 'sloe/junos' describe Sloe do + let(:jnx_mibs) { Dir.glob("./mibs/JUNIPER-*.yaml").map { |f| File.basename(f, '.yaml') } } + let(:login) { { + target: 'crtj-0dc1-0001', + username: 'netadmin', + password: 'pass123', + mib_dir: './mibs', + mib_modules: ["SNMPv2-SMI", "SNMPv2-MIB", "IF-MIB", "IP-MIB", "TCP-MIB", "UDP-MIB"].concat(jnx_mibs) } + } + subject(:dut) { Sloe::Junos.new(login) } - before(:all) do - @jnx_mibs = Dir.glob("./mibs/JUNIPER-*.yaml").map { |f| File.basename(f, '.yaml') } - @args = { - :target => 'capella', - :username => 'netconf', - :password => 'netconf', - :mib_dir => './mibs', - :mib_modules => ["SNMPv2-SMI", "SNMPv2-MIB", "IF-MIB", "IP-MIB", "TCP-MIB", "UDP-MIB"].concat(@jnx_mibs) - } - - @dut = Sloe::Junos.new(@args) - end - context "SNMP API" do it "snmp.get_value() returns valid value" do - @dut.snmp.get_value('sysDescr.0').should =~ /^Juniper Networks,/ + expect( dut.snmp.get_value('sysDescr.0') ).to =~ /^Juniper Networks,/ end it "snmp.get() returns one PDU" do - @pdu = @dut.snmp.get('sysDescr.0') - @pdu.varbind_list.should have(1).item + expect( dut.snmp.get('sysDescr.0').varbind_list.size ).to eq(1) end it "snmp.get_bulk() returns a list of PDUs" do - @pdu = @dut.snmp.get_bulk(0, 5, 'system') - @pdu.varbind_list.should have(5).items + expect( dut.snmp.get_bulk(0, 5, 'system').varbind_list.size ).to eq(5) end it "snmp.get_next() returns one PDU" do - @pdu = @dut.snmp.get_next('system') - @pdu.varbind_list.should have(1).item + expect( dut.snmp.get_next('system').varbind_list.size ).to eq(1) end it "snmp.walk() returns a list of PDUs none of which are nil" do - @dut.snmp.walk('system') { |vb| vb.should_not be_nil } + expect { dut.snmp.walk('system') }.not_to eq(nil) end end context "JNX Enterprise MIBs" do it "jnxBoxDescr.0 has a valid value" do - @dut.snmp.get_value('jnxBoxDescr.0').should =~ /^Juniper/ + expect( dut.snmp.get_value('jnxBoxDescr.0') ).to =~ /^Juniper/ end end context "NETCONF API" do it "rpc.get_interface_information() functions without error" do - lambda { @dut.rpc.get_interface_information() }.should_not raise_error + expect { dut.rpc.get_interface_information() }.not_to raise_error end it "rpc.get_ospf_neighbor_information() functions without error" do - lambda { @dut.rpc.get_ospf_neighbor_information() }.should_not raise_error + expect { dut.rpc.get_ospf_neighbor_information() }.not_to raise_error end end context "SCP API" do it "scp.download() functions without error" do - lambda { @dut.scp.download!('/config/juniper.conf.gz', '/var/tmp/juniper.conf.gz') }.should_not raise_error + expect { dut.scp.download!('/config/juniper.conf.gz', '/var/tmp/juniper.conf.gz') }.not_to raise_error File.delete('/var/tmp/juniper.conf.gz') end it "scp.upload() functions without error" do File.new('/var/tmp/test', 'w+') - lambda { @dut.scp.upload!('/var/tmp/test', 'test') }.should_not raise_error - @dut.rpc.file_delete(:path => 'test') + expect { dut.scp.upload!('/var/tmp/test', 'test') }.not_to raise_error + dut.rpc.file_delete(:path => 'test') File.delete('/var/tmp/test') end end context "CLI API" do it "cli('show version') functions without error" do - lambda { @dut.cli("show version") }.should_not raise_error + expect { dut.cli("show version") }.not_to raise_error end it "cli('show version') contains OS information" do - @dut.cli("show version").should be_a(String) - @dut.cli("show version").should =~ /JUNOS Base OS/ + expect( dut.cli("show version") ).to =~ /JUNOS Base OS/ end it "cli('show version', :foo => 'bar') still contains OS information" do - @dut.cli("show version", :foo => 'bar').should be_a(String) - @dut.cli("show version", :foo => 'bar').should =~ /JUNOS Base OS/ + expect( dut.cli("show version", :foo => 'bar') ).to =~ /JUNOS Base OS/ end it "cli('clear interface statistics') empty reply does not cause an error" do - lambda { @dut.cli('clear interface statistics fxp0') }.should_not raise_error - end - end - - context "Helper methods" do - before( :all ) do - Dir.mkdir( 'configs' ) - @apply = File.open( "configs/capella-apply.set", "w" ) - @apply.write( 'set system location building "In a galaxy far, far, away"' ) - @apply.close - - @delete = File.open( "configs/capella-delete.set", "w" ) - @delete.write( 'delete system location') - @delete.close - end - - it "setup() with default args updates the router config" do - lambda { @dut.setup() }.should_not raise_error - end - it "clearup() with default args updates the router config" do - lambda { @dut.clearup() }.should_not raise_error - end - - after(:all) do - FileUtils.rm_rf( 'configs' ) + expect { dut.cli('clear interface statistics fxp0') }.not_to raise_error end end end \ No newline at end of file