Skip to content

Commit

Permalink
Some changes based on code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Jan 29, 2016
1 parent 34ae252 commit 9769f80
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions test/yapi_network_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
include YaPINetworkStub

describe ".Write" do
let(:routing) { Yast::Routing }

context "with routes" do
# Mock the system to do not break anything
before do
allow(Yast::Routing).to receive(:Read)
allow(Yast::Routing).to receive(:Routes)
allow(Yast::Routing).to receive(:Write)
allow(routing).to receive(:Read)
allow(routing).to receive(:Routes)
allow(routing).to receive(:Write)
end

subject { Yast::YaPI::NETWORK.Write("route" => route) }
Expand All @@ -37,7 +38,7 @@
end

it "empties the routes" do
expect(Yast::Routing).to receive(:Routes=).with []
expect(routing).to receive(:Routes=).with []
subject
end
end
Expand All @@ -50,7 +51,7 @@
end

it "empties the routes" do
expect(Yast::Routing).to receive(:Routes=).with []
expect(routing).to receive(:Routes=).with []
subject
end
end
Expand All @@ -69,7 +70,7 @@
end

it "correctly modifies the routes" do
expect(Yast::Routing).to receive(:Routes=).with(
expect(routing).to receive(:Routes=).with(
[
{
"destination" => "default",
Expand All @@ -89,18 +90,19 @@
it "returns failure" do
res = subject
expect(res["exit"]).to eq "-1"
expect(res["error"]).to_not be_empty
expect(res["error"]).not_to be_empty
end

it "doesnt't modify the routes" do
expect(Yast::Routing).to_not receive(:Routes=)
expect(routing).not_to receive(:Routes=)
subject
end
end
end
end

context "with interfaces" do
let(:network_interfaces) { Yast::NetworkInterfaces }

subject { Yast::YaPI::NETWORK.Write("interface" => interface) }

Expand All @@ -114,7 +116,7 @@
let(:interface) { { "eth0" => { "bootproto" => "dhcp6", "startmode" => "onboot" } } }

it "sets both parameters correctly" do
expect(Yast::NetworkInterfaces).to receive(:Current=).with(
expect(network_interfaces).to receive(:Current=).with(
"BOOTPROTO" => "dhcp6",
"STARTMODE" => "onboot"
)
Expand All @@ -130,7 +132,7 @@
let(:netmask) { "255.255.255.0" }

it "converts netmask to CIDR" do
expect(Yast::NetworkInterfaces).to receive(:Current=).with(
expect(network_interfaces).to receive(:Current=).with(
"BOOTPROTO" => "static",
"STARTMODE" => "auto",
"IPADDR" => "TheIP/24"
Expand All @@ -144,7 +146,7 @@
let(:netmask) { "16" }

it "keeps netmask untouched" do
expect(Yast::NetworkInterfaces).to receive(:Current=).with(
expect(network_interfaces).to receive(:Current=).with(
"BOOTPROTO" => "static",
"STARTMODE" => "auto",
"IPADDR" => "TheIP/#{netmask}"
Expand All @@ -169,7 +171,7 @@
end

it "sets both parameters correctly" do
expect(Yast::NetworkInterfaces).to receive(:Current=).with(
expect(network_interfaces).to receive(:Current=).with(
"BOOTPROTO" => "static",
"STARTMODE" => "auto",
"IPADDR" => "1.2.3.8/24",
Expand All @@ -185,7 +187,7 @@
let(:interface) { { "bond0" => { "bond" => "yes", "bond_slaves" => "eth1" } } }

it "sets default values" do
expect(Yast::NetworkInterfaces).to receive(:Current=).with(
expect(network_interfaces).to receive(:Current=).with(
"BOOTPROTO" => "static",
"STARTMODE" => "auto",
"BONDING_MASTER" => "yes",
Expand All @@ -209,7 +211,7 @@
end

it "sets extra parameters correctly" do
expect(Yast::NetworkInterfaces).to receive(:Current=).with(
expect(network_interfaces).to receive(:Current=).with(
"BOOTPROTO" => "static",
"STARTMODE" => "auto",
"BONDING_MASTER" => "yes",
Expand Down Expand Up @@ -239,6 +241,7 @@
mtu: "1234"
}.merge(context_attributes)
end
let(:lan_items) { Yast::LanItems }

before do
stub_network_reads
Expand Down Expand Up @@ -279,8 +282,7 @@
end

it "returns the correct hash" do
expect(Yast::YaPI::NETWORK.Read).to eql(config)
subject
expect(subject).to eql(config)
end
end

Expand Down Expand Up @@ -310,20 +312,21 @@
end

before do
allow(Yast::LanItems).to receive(:Items).with(no_args).and_return("0" => { "ifcfg" => "eth5.23" })
allow(Yast::LanItems).to receive(:GetCurrentName).and_return("eth5.23")
allow(Yast::LanItems).to receive(:getCurrentItem).and_return(
allow(lan_items).to receive(:Items).with(no_args).and_return("0" => { "ifcfg" => "eth5.23" })
allow(lan_items).to receive(:GetCurrentName).and_return("eth5.23")
allow(lan_items).to receive(:getCurrentItem).and_return(
"hwinfo" => { "dev_name" => "eth5.23", "type" => "eth", "name" => "eth5.23" }
)
allow(Yast::LanItems).to receive(:IsCurrentConfigured).and_return(true)
allow(lan_items).to receive(:IsCurrentConfigured).and_return(true)
attributes.map do |k, v|
allow(Yast::LanItems).to receive(k) { v }
allow(lan_items).to receive(k) { v }
end
allow(Yast::LanItems).to receive(:SetItem)
allow(lan_items).to receive(:SetItem)
end

it "returns the correct hash" do
expect(subject).to eql(config)
subject
end
end

Expand Down Expand Up @@ -352,18 +355,18 @@
end

before do
allow(Yast::LanItems).to receive(:Items).with(no_args).and_return("0" => { "ifcfg" => "bond0" })
allow(Yast::LanItems).to receive(:GetCurrentName).and_return("bond0")
allow(Yast::LanItems).to receive(:getCurrentItem).and_return("hwinfo" => { "type" => "bond" })
allow(Yast::LanItems).to receive(:IsCurrentConfigured).and_return(true)
allow(lan_items).to receive(:Items).with(no_args).and_return("0" => { "ifcfg" => "bond0" })
allow(lan_items).to receive(:GetCurrentName).and_return("bond0")
allow(lan_items).to receive(:getCurrentItem).and_return("hwinfo" => { "type" => "bond" })
allow(lan_items).to receive(:IsCurrentConfigured).and_return(true)
attributes.map do |k, v|
allow(Yast::LanItems).to receive(k) { v }
allow(lan_items).to receive(k) { v }
end
allow(Yast::LanItems).to receive(:SetItem)
allow(lan_items).to receive(:SetItem)
end

it "returns the correct hash" do
expect(Yast::YaPI::NETWORK.Read).to eql(config)
expect(subject).to eql(config)
subject
end

Expand Down

0 comments on commit 9769f80

Please sign in to comment.