Skip to content

Commit

Permalink
Fixed mocking in CWMFirewall interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Sep 4, 2018
1 parent 5b7242e commit 98287a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
6 changes: 1 addition & 5 deletions library/network/test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ TESTS = \
load_ipv6_cfg_test.rb \
network_interfaces_test.rb \
network_interfaces_helpers_test.rb \
network_service_test.rb \
susefirewall_proposal_test.rb \
susefirewall_services_test.rb \
susefirewall_test.rb \
susefirewalld_test.rb
network_service_test.rb

TEST_EXTENSIONS = .rb
RB_LOG_COMPILER = rspec
Expand Down
21 changes: 18 additions & 3 deletions library/network/test/cwm_firewall_interfaces_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,26 @@
end

describe "#Selected2Opened" do
let(:known_interfaces) do
[
{ "id" => "eth0", "name" => "Ethernet 1", "zone" => "external" },
{ "id" => "eth1", "name" => "Ethernet 2", "zone" => "public" },
{ "id" => "eth2", "name" => "Ethernet 3", "zone" => "dmz" }
]
end

before do
allow(subject).to receive(:known_interfaces).and_return(known_interfaces)
end

context "given a list of selected interfaces" do
let(:zone) do
instance_double("Y2Firewall::Firewalld::Zone", interfaces: ["eth0", "eth1"], name: "public")
end

before do
allow(subject).to receive(:interface_zone).with("eth0").and_return("public")
allow_any_instance_of(Y2Firewall::Firewalld).to receive(:find_zone).and_return(zone)
allow(firewalld).to receive(:find_zone).and_return(zone)
end

it "returns all the interfaces that belongs to same zone of the given interfaces" do
Expand All @@ -223,10 +235,12 @@
{ "id" => "eth2", "name" => "Ethernet 3", "zone" => nil }
]
end

let(:external_zone) do
instance_double("Y2Firewall::Firewalld::Zone", name: "external",
interfaces: ["eth0"], services: [])
end

let(:public_zone) do
instance_double("Y2Firewall::Firewalld::Zone", name: "public",
interfaces: ["eth1"], services: ["dns"])
Expand All @@ -235,8 +249,9 @@
let(:zones) { [external_zone, public_zone] }

before do
allow(subject).to receive(:known_interfaces).and_return(known_interfaces)
allow_any_instance_of(Y2Firewall::Firewalld).to receive(:zones).and_return(zones)
expect(subject).to receive(:known_interfaces).and_return(known_interfaces)
expect(subject).to receive(:allowed_interfaces).and_return(["eth0", "eth1"])
allow(firewalld).to receive(:zones).and_return(zones)
allow(subject).to receive(:default_zone).and_return(public_zone)
allow(subject).to receive(:configuration_changed).and_return(true)
allow(subject).to receive(:allowed_interfaces).and_return(["eth0", "eth1", "eth2"])
Expand Down

0 comments on commit 98287a1

Please sign in to comment.