Skip to content

Commit

Permalink
Changes based on code review proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Jan 29, 2016
1 parent a06079c commit 6a8900d
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions test/yapi_network_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,76 +26,72 @@
allow(routing).to receive(:Write)
end

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

let(:success) { { "error" => "", "exit" => "0" } }

context "with no gateway in the default route" do
let(:route) { { "default" => nil } }

it "returns success" do
expect(subject).to eq success
expect(subject.Write("route" => route)).to eq success
end

it "empties the routes" do
expect(routing).to receive(:Routes=).with []
subject
subject.Write("route" => route)
end
end

context "with empty gateway in the default route" do
let(:route) { { "default" => { "via" => "" } } }

it "returns success" do
expect(subject).to eq success
expect(subject.Write("route" => route)).to eq success
end

it "empties the routes" do
expect(routing).to receive(:Routes=).with []
subject
subject.Write("route" => route)
end
end

context "with a gateway in the default route" do
let(:route) { { "default" => { "via" => "TheIP" } } }
before do
expect(Yast::IP).to receive(:Check4).with("TheIP").and_return valid
end

context "if it's a valid IP4" do
let(:valid) { true }
let(:route) { { "default" => { "via" => "10.0.0.1" } } }

it "returns success" do
expect(subject).to eq success
expect(subject.Write("route" => route)).to eq success
end

it "correctly modifies the routes" do
expect(routing).to receive(:Routes=).with(
[
{
"destination" => "default",
"gateway" => "TheIP",
"gateway" => "10.0.0.1",
"netmask" => "-",
"device" => "-"
}
]
)
subject
subject.Write("route" => route)
end
end

context "if it's not a valid IP4" do
let(:valid) { false }
let(:route) { { "default" => { "via" => "256.256.256.256" } } }

it "returns failure" do
res = subject
res = subject.Write("route" => route)
expect(res["exit"]).to eq "-1"
expect(res["error"]).not_to be_empty
end

it "doesnt't modify the routes" do
expect(routing).not_to receive(:Routes=)
subject
subject.Write("route" => route)
end
end
end
Expand All @@ -104,7 +100,7 @@
context "with interfaces" do
let(:network_interfaces) { Yast::NetworkInterfaces }

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

before do
interface.keys.map do |k|
Expand All @@ -121,7 +117,7 @@
"STARTMODE" => "onboot"
)
stub_write_interfaces
subject
subject.Write("interface" => interface)
end
end

Expand All @@ -138,7 +134,7 @@
"IPADDR" => "TheIP/24"
)
stub_write_interfaces
subject
subject.Write("interface" => interface)
end
end

Expand All @@ -152,7 +148,7 @@
"IPADDR" => "TheIP/#{netmask}"
)
stub_write_interfaces
subject
subject.Write("interface" => interface)
end
end

Expand All @@ -179,7 +175,7 @@
"VLAN_ID" => "42"
)
stub_write_interfaces
subject
subject.Write("interface" => interface)
end
end

Expand All @@ -195,7 +191,7 @@
"BONDING_SLAVE0" => "eth1"
)
stub_write_interfaces
subject
subject.Write("interface" => interface)
end
end

Expand All @@ -221,7 +217,7 @@
"BONDING_SLAVE2" => "eth5"
)
stub_write_interfaces
subject
subject.Write("interface" => interface)
end

end
Expand Down Expand Up @@ -253,7 +249,7 @@
allow(Yast::DNS).to receive(:searchlist).and_return ["suse.com"]
end

subject { Yast::YaPI::NETWORK.Read }
subject { Yast::YaPI::NETWORK }

let(:config) do
{
Expand Down Expand Up @@ -282,7 +278,7 @@
end

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

Expand Down Expand Up @@ -325,8 +321,7 @@
end

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

Expand Down Expand Up @@ -366,8 +361,7 @@
end

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

end
Expand Down

0 comments on commit 6a8900d

Please sign in to comment.