Skip to content

Commit

Permalink
Unify Lan writeIPv6 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Sep 1, 2020
1 parent fae3580 commit 9856008
Showing 1 changed file with 17 additions and 70 deletions.
87 changes: 17 additions & 70 deletions test/lan_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,15 @@
end
end

describe "#readIPv6" do
describe "#writeIPv6" do
let(:sysctl_config_file) { CFA::SysctlConfig.new }

before do
allow(CFA::SysctlConfig).to receive(:new).and_return(sysctl_config_file)
allow(sysctl_config_file).to receive(:load)
allow(sysctl_config_file).to receive(:save)
allow(Yast::SCR).to receive(:Write)
.with(path(".sysconfig.windowmanager.KDE_USE_IPV6"), String)
Yast::Lan.ipv6 = ipv6
end

Expand All @@ -279,27 +281,41 @@

it "enables IPv6 in the sysctl_config configuration" do
expect(sysctl_config_file).to receive(:disable_ipv6=).with(false)
expect(sysctl_config_file).to receive(:save)
Yast::Lan.writeIPv6
end

it "enables IPv6 in the running system" do
expect(Yast::SCR).to receive(:Execute).with(anything, /sysctl .+disable_ipv6=0/)
Yast::Lan.writeIPv6
end

it "enables IPv6 for KDE" do
expect(Yast::SCR).to receive(:Write)
.with(path(".sysconfig.windowmanager.KDE_USE_IPV6"), "yes")
subject.writeIPv6
end
end

context "when IPv6 is disabled" do
let(:ipv6) { false }

it "disables IPv6 in the sysctl_config configuration" do
expect(sysctl_config_file).to receive(:disable_ipv6=).with(true)
expect(sysctl_config_file).to receive(:save)
Yast::Lan.writeIPv6
end

it "disables IPv6 in the running system" do
expect(Yast::SCR).to receive(:Execute).with(anything, /sysctl .+disable_ipv6=1/)
Yast::Lan.writeIPv6
end

it "disables IPv6 for KDE" do
expect(Yast::SCR).to receive(:Write)
.with(path(".sysconfig.windowmanager.KDE_USE_IPV6"), "no")
subject.writeIPv6
end
end
end

Expand Down Expand Up @@ -493,72 +509,3 @@
end
end
end

describe "Yast::LanClass#writeIPv6" do
subject { Yast::Lan }

let(:sysctl_config) do
instance_double(
CFA::SysctlConfig, :conflict? => false
).as_null_object
end

before do
allow(CFA::SysctlConfig).to receive(:new).and_return(sysctl_config)
allow(Yast::SCR).to receive(:Execute)
.with(path(".target.bash"), /sysctl -w/)
allow(Yast::SCR).to receive(:Write)
.with(path(".sysconfig.windowmanager.KDE_USE_IPV6"), String)
end

around do |example|
old_ipv6 = subject.ipv6
subject.ipv6 = ipv6
example.run
subject.ipv6 = old_ipv6
end

context "when IPv6 must be enabled" do
let(:ipv6) { true }

it "enables IPv6 in sysctl.conf" do
expect(sysctl_config).to receive(:disable_ipv6=).with(false)
expect(sysctl_config).to receive(:save)
subject.writeIPv6
end

it "enables IPv6 using sysctl" do
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.bash"), /sysctl -w net.ipv6.conf.all.disable_ipv6=0/)
subject.writeIPv6
end

it "enables IPv6 for KDE" do
expect(Yast::SCR).to receive(:Write)
.with(path(".sysconfig.windowmanager.KDE_USE_IPV6"), "yes")
subject.writeIPv6
end
end

context "when IPv6 must be disabled" do
let(:ipv6) { false }

it "disables IPv6 in sysctl.conf" do
expect(sysctl_config).to receive(:disable_ipv6=).with(true)
expect(sysctl_config).to receive(:save)
subject.writeIPv6
end

it "disables IPv6 using sysctl" do
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.bash"), /sysctl -w net.ipv6.conf.all.disable_ipv6=1/)
subject.writeIPv6
end

it "disables IPv6 for KDE" do
expect(Yast::SCR).to receive(:Write)
.with(path(".sysconfig.windowmanager.KDE_USE_IPV6"), "no")
subject.writeIPv6
end
end
end

0 comments on commit 9856008

Please sign in to comment.