From 9856008e4d7a3567609500b556d10c8f3cedb6a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Tue, 1 Sep 2020 09:04:39 +0100 Subject: [PATCH] Unify Lan writeIPv6 tests --- test/lan_test.rb | 87 ++++++++++-------------------------------------- 1 file changed, 17 insertions(+), 70 deletions(-) diff --git a/test/lan_test.rb b/test/lan_test.rb index a6efe83bd..7cd4f2c64 100755 --- a/test/lan_test.rb +++ b/test/lan_test.rb @@ -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 @@ -279,6 +281,7 @@ 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 @@ -286,6 +289,12 @@ 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 @@ -293,6 +302,7 @@ 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 @@ -300,6 +310,12 @@ 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 @@ -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