Skip to content

Commit

Permalink
Merge pull request #243 from mvidner/rspec
Browse files Browse the repository at this point in the history
Rspec speed up, enable library lookup in working copies.
  • Loading branch information
mvidner committed Sep 3, 2014
2 parents 28e7be8 + a04dae5 commit 3c9788c
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 49 deletions.
6 changes: 6 additions & 0 deletions package/yast2-network.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Sep 3 09:01:40 UTC 2014 - mvidner@suse.com

- Test speed-up.
- 3.1.92

-------------------------------------------------------------------
Wed Sep 3 08:37:43 UTC 2014 - mfilka@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-network.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-network
Version: 3.1.91
Version: 3.1.92
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
2 changes: 0 additions & 2 deletions test/bridge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

require "yast"

include Yast

Yast.import "LanItems"

module Yast
Expand Down
20 changes: 11 additions & 9 deletions test/install_inf_convertor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
require "network/install_inf_convertor"
include Yast # for path shortcut and avoid namespace

Yast.import "Proxy"

describe "InstallInfConvertor" do

context "in case of no network config in /etc/install.inf" do
Expand All @@ -20,7 +22,7 @@

describe "#write_dhcp_timeout" do
it "returns false" do
expect(@install_inf_convertor.send(:write_dhcp_timeout)).to be_false
expect(@install_inf_convertor.send(:write_dhcp_timeout)).to be false
end
end

Expand All @@ -32,31 +34,31 @@

describe "#write_hostname" do
it "returns false" do
expect(@install_inf_convertor.send(:write_hostname)).to be_false
expect(@install_inf_convertor.send(:write_hostname)).to be false
end
end

describe "#write_dns" do
it "returns false" do
expect(@install_inf_convertor.send(:write_dns)).to be_false
expect(@install_inf_convertor.send(:write_dns)).to be false
end
end

describe "#write_proxy" do
it "returns false" do
expect(@install_inf_convertor.send(:write_proxy)).to be_false
expect(@install_inf_convertor.send(:write_proxy)).to be false
end
end

describe "#write_nis_domain" do
it "returns false" do
expect(@install_inf_convertor.send(:write_nis_domain)).to be_false
expect(@install_inf_convertor.send(:write_nis_domain)).to be false
end
end

describe "#write_connect_wait" do
it "returns false" do
expect(@install_inf_convertor.send(:write_connect_wait)).to be_false
expect(@install_inf_convertor.send(:write_connect_wait)).to be false
end
end

Expand Down Expand Up @@ -224,7 +226,7 @@
end
expect(Yast::Proxy).to receive(:Write).and_return(true)

expect(Yast::InstallInfConvertor.instance.send(:write_proxy)).to be_true
expect(Yast::InstallInfConvertor.instance.send(:write_proxy)).to be true
end

it "writes proxy credentials separately" do
Expand All @@ -249,7 +251,7 @@
end
expect(Yast::Proxy).to receive(:Write).and_return(true)

expect(Yast::InstallInfConvertor.instance.send(:write_proxy)).to be_true
expect(Yast::InstallInfConvertor.instance.send(:write_proxy)).to be true
end

it "does not write proxy configuration if not defined in install.inf" do
Expand All @@ -259,7 +261,7 @@
expect(Yast::Proxy).to receive(:Read).never
expect(Yast::Proxy).to receive(:Write).never

expect(Yast::InstallInfConvertor.instance.send(:write_proxy)).to be_false
expect(Yast::InstallInfConvertor.instance.send(:write_proxy)).to be false
end
end

Expand Down
10 changes: 5 additions & 5 deletions test/lan_items_helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@
it "succeeds when item has configuration" do
Yast::LanItems.stub(:GetLanItem) { { "ifcfg" => "enp0s3" } }

expect(Yast::LanItems.IsItemConfigured(0)).to be_true
expect(Yast::LanItems.IsItemConfigured(0)).to be true
end

it "fails when item doesn't exist" do
Yast::LanItems.stub(:GetLanItem) { {} }

expect(Yast::LanItems.IsItemConfigured(0)).to be_false
expect(Yast::LanItems.IsItemConfigured(0)).to be false
end

it "fails when item's configuration doesn't exist" do
Yast::LanItems.stub(:GetLanItem) { { "ifcfg" => nil } }

expect(Yast::LanItems.IsItemConfigured(0)).to be_false
expect(Yast::LanItems.IsItemConfigured(0)).to be false
end
end

describe "LanItemsClass#delete_dev" do

MOCKED_ITEMS = {
MOCKED_ITEMS_DEL = {
0 => {
"ifcfg" => "enp0s3"
}
}

before(:each) do
Yast::LanItems.Items = MOCKED_ITEMS
Yast::LanItems.Items = MOCKED_ITEMS_DEL
end

it "removes device config when found" do
Expand Down
17 changes: 13 additions & 4 deletions test/link_handlers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@

require "yast"

describe "phy_connected?" do
before(:each) do
# need a class to stub the sleep call; hard to stub it on Kernel
class LinkHandlersClass
def initialize
Yast.include self, "network/routines.rb"
end
end

describe "phy_connected?" do
include Yast
subject { LinkHandlersClass.new }

before(:each) do
Yast::SCR.stub(:Execute).with(path(".target.bash"), //) { 0 }
allow(subject).to receive(:sleep)
end

it "returns true if PHY layer is available" do
Yast::SCR.stub(:Read).with(path(".target.string"), /\/sys\/class\/net/) { 1 }
expect(phy_connected?("enp0s3")).to eql true
expect(subject.phy_connected?("enp0s3")).to eql true
end

it "returns false if PHY layer is available" do
Yast::SCR.stub(:Read).with(path(".target.string"), /\/sys\/class\/net/) { 0 }
expect(phy_connected?("enp0s3")).to eql false
expect(subject.phy_connected?("enp0s3")).to eql false
end
end
10 changes: 5 additions & 5 deletions test/netcard_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,19 @@

@lan_items.DeleteItem

expect(@lan_items.FindAndSelect(item_name)).to be_false
expect(@lan_items.FindAndSelect(item_name)).to be false
end
end

it "removes only the configuration if the item has hwinfo" do
before_size = @lan_items.Items.size
item_name = "enp0s3"

expect(@lan_items.FindAndSelect(item_name)).to be_true
expect(@lan_items.FindAndSelect(item_name)).to be true

@lan_items.DeleteItem

expect(@lan_items.FindAndSelect(item_name)).to be_false
expect(@lan_items.FindAndSelect(item_name)).to be false
expect(@lan_items.Items.size).to eql before_size
end
end
Expand Down Expand Up @@ -244,10 +244,10 @@
end

it "finds configured device" do
expect(@lan_items.FindAndSelect("enp0s3")).to be_true
expect(@lan_items.FindAndSelect("enp0s3")).to be true
end

it "fails to find unconfigured device" do
expect(@lan_items.FindAndSelect("nonexistent")).to be_false
expect(@lan_items.FindAndSelect("nonexistent")).to be false
end
end
4 changes: 2 additions & 2 deletions test/network_autoconfiguration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ def set(section, key, value)
expect(Yast::SCR).
to receive(:Read).
with(Yast::Path.new(".udev_persistent.net")).
and_return {}
and_return({})
expect(Yast::SCR).
to receive(:Read).
with(Yast::Path.new(".udev_persistent.drivers")).
and_return {}
and_return({})
end

it "configures just one NIC to have a default route" do
Expand Down
14 changes: 7 additions & 7 deletions test/new_device_startmode_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
"STARTMODE" => "invalid"
}

AVAILABLE_PRODUCT_STARTMODES = [
"hotplug",
"manual",
"off",
"nfsroot"
]

["hotplug", ""].each do |hwinfo_hotplug|

expected_startmode = hwinfo_hotplug == "hotplug" ? "hotplug" : "auto"
Expand Down Expand Up @@ -79,13 +86,6 @@

context "When product_startmode is not auto neither ifplugd" do

AVAILABLE_PRODUCT_STARTMODES = [
"hotplug",
"manual",
"off",
"nfsroot"
]

AVAILABLE_PRODUCT_STARTMODES.each do |product_startmode|

it "for #{product_startmode} it results to #{expected_startmode} if device " + hotplug_desc do
Expand Down
6 changes: 3 additions & 3 deletions test/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ def fw_independent_write_expects
describe "#Import" do

it "Returns true for non nil settings" do
expect(Routing.Import({})).to be_true
expect(Routing.Import({})).to be true
end

it "Returns true for nil settings" do
expect(Routing.Import(nil)).to be_true
expect(Routing.Import(nil)).to be true
end
end

Expand Down Expand Up @@ -298,7 +298,7 @@ def fw_independent_write_expects
it "loads configuration from system" do
NetworkInterfaces.as_null_object

expect(Routing.Read).to be_true
expect(Routing.Read).to be true
end
end
end
Expand Down
20 changes: 10 additions & 10 deletions test/suse_firewall_4_network_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ module Yast
describe "#SetSshdEnabled" do
it "sets whether sshd service should be started and caches the information in ServicesProposal" do
SuSEFirewall4Network.SetSshdEnabled(true)
expect(SuSEFirewall4Network.EnabledSshd).to be_true
expect(ServicesProposal.enabled_services.include?('sshd')).to be_true
expect(ServicesProposal.disabled_services.include?('sshd')).to be_false
expect(SuSEFirewall4Network.EnabledSshd).to be true
expect(ServicesProposal.enabled_services.include?('sshd')).to be true
expect(ServicesProposal.disabled_services.include?('sshd')).to be false

SuSEFirewall4Network.SetSshdEnabled(false)
expect(SuSEFirewall4Network.EnabledSshd).to be_false
expect(ServicesProposal.enabled_services.include?('sshd')).to be_false
expect(ServicesProposal.disabled_services.include?('sshd')).to be_true
expect(SuSEFirewall4Network.EnabledSshd).to be false
expect(ServicesProposal.enabled_services.include?('sshd')).to be false
expect(ServicesProposal.disabled_services.include?('sshd')).to be true
end
end

Expand All @@ -46,8 +46,8 @@ module Yast

it "proposes firewall and ssh port according to control file" do
SuSEFirewall4Network.prepare_proposal
expect(SuSEFirewall4Network.Enabled1stStage).to be_true
expect(SuSEFirewall4Network.EnabledSsh1stStage).to be_false
expect(SuSEFirewall4Network.Enabled1stStage).to be true
expect(SuSEFirewall4Network.EnabledSsh1stStage).to be false
end
end

Expand All @@ -58,8 +58,8 @@ module Yast

it "proposes disabled firewall and proposes ssh port according to control file" do
SuSEFirewall4Network.prepare_proposal
expect(SuSEFirewall4Network.Enabled1stStage).to be_false
expect(SuSEFirewall4Network.EnabledSsh1stStage).to be_false
expect(SuSEFirewall4Network.Enabled1stStage).to be false
expect(SuSEFirewall4Network.EnabledSsh1stStage).to be false
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ENV["Y2DIR"] = File.expand_path("../../src", __FILE__)
srcdir = File.expand_path("../../src", __FILE__)
y2dirs = ENV.fetch("Y2DIR", "").split(":")
ENV["Y2DIR"] = y2dirs.unshift(srcdir).join(":")

0 comments on commit 3c9788c

Please sign in to comment.