Skip to content

Commit

Permalink
Adapted network_autoyast test
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed May 20, 2020
1 parent cfd95bc commit 488267d
Showing 1 changed file with 48 additions and 53 deletions.
101 changes: 48 additions & 53 deletions test/network_autoyast_test.rb
Expand Up @@ -27,6 +27,7 @@

Yast.import "Profile"
Yast.import "Lan"
Yast.import "Call"

describe "NetworkAutoYast" do
subject(:network_autoyast) { Yast::NetworkAutoYast.instance }
Expand Down Expand Up @@ -249,96 +250,90 @@ def nm_installed(installed)

describe "#keep_net_config?" do
let(:network_autoyast) { Yast::NetworkAutoYast.instance }
let(:profile) { { "networking" => { "keep_install_network" => true } } }

def keep_install_network_value(value)
allow(network_autoyast)
.to receive(:ay_networking_section)
.and_return(value)
before do
Yast::Lan.Import(Yast::Lan.FromAY(profile["networking"]))
end

it "succeedes when keep_install_network is set in AY profile" do
keep_install_network_value("keep_install_network" => true)
expect(network_autoyast.keep_net_config?).to be true
context "when keep_install_network is true in AY profile" do
it "returns true" do
expect(network_autoyast.keep_net_config?).to be true
end
end

it "fails when keep_install_network is not set in AY profile" do
keep_install_network_value("keep_install_network" => false)
expect(network_autoyast.keep_net_config?).to be false
context "when keep_install_network is false in AY profile" do
let(:profile) { { "networking" => { "keep_install_network" => false } } }
it "returns false" do
expect(network_autoyast.keep_net_config?).to be false
end
end

it "succeedes when keep_install_network is not present in AY profile" do
keep_install_network_value({})
expect(network_autoyast.keep_net_config?).to be true
context "when keep_install_network is not present in AY profile" do
let(:profile) { { "networking" => { "setup_before_proposal" => true } } }

it "returns true" do
expect(network_autoyast.keep_net_config?).to be true
end
end
end

describe "#configure_lan" do
before do
Yast::Lan.autoinst = nil
allow(Yast::Profile).to receive(:current)
.and_return("general" => general_section, "networking" => networking_section)
allow(Yast::AutoInstall).to receive(:valid_imported_values).and_return(true)
allow(Yast::Lan).to receive(:Write)
Yast::Call.Function("lan_auto", ["Import", networking_section])
end

let(:networking_section) { nil }
let(:general_section) { nil }
let(:before_proposal) { false }

context "when second stage is disabled" do
let(:general_section) do
{ "mode" => { "second_stage" => false } }
end
context "when the configuration was done before the proposal" do
let(:before_proposal) { true }
let(:networking_section) { { "setup_before_proposal" => before_proposal } }

it "does not write anything" do
expect(Yast::Lan).to_not receive(:WriteOnly)

it "writes the Lan module configuration" do
expect(Yast::Lan).to receive(:Write)
subject.configure_lan
end
end

context "when writing the configuration is disabled" do
it "writes the Lan module configuration" do
expect(Yast::Lan).to_not receive(:Write)
subject.configure_lan(write: false)
end
end
context "when the configuration is not done before the proposal" do
let(:before_proposal) { true }
let(:networking_section) { { "setup_before_proposal" => before_proposal } }

context "when second stage is enabled" do
let(:general_section) do
{ "mode" => { "second_stage" => true } }
end
it "does not write anything" do
expect(Yast::Lan).to_not receive(:WriteOnly)

it "does not write the Lan module configuration" do
expect(Yast::Lan).to_not receive(:Write)
subject.configure_lan
end
end

context "when second stage is not explicitly enabled" do
let(:general_section) { nil }
context "and the user wants to keep the installation network" do
let(:networking_section) { { "keep_install_network" => true } }

it "does not write the Lan module configuration" do
expect(Yast::Lan).to_not receive(:Write)
subject.configure_lan
it "merges the installation configuration" do
expect(Yast::NetworkAutoYast.instance).to_not receive(:merge_configs)
subject.configure_lan
end
end
end

it "merges the installation configuration" do
expect(Yast::NetworkAutoYast.instance).to receive(:merge_configs)
subject.configure_lan
end

context "when the user wants to keep the installation network" do
let(:networking_section) { { "keep_install_network" => true } }
context "and the user does not want to keep the installation network" do
let(:networking_section) { { "keep_install_network" => false } }

it "merges the installation configuration" do
expect(Yast::NetworkAutoYast.instance).to receive(:merge_configs)
subject.configure_lan
it "does not merge the installation configuration" do
expect(Yast::NetworkAutoYast.instance).to_not receive(:merge_configs)
subject.configure_lan
end
end
end

context "when the user does not want to keep the installation network" do
let(:networking_section) { { "keep_install_network" => false } }
it "writes the current configuration taking into account if needs to start it immediately" do
expect(Yast::Lan).to_not receive(:WriteOnly)

it "does not merge the installation configuration" do
expect(Yast::NetworkAutoYast.instance).to_not receive(:merge_configs)
subject.configure_lan
end
end
Expand Down

0 comments on commit 488267d

Please sign in to comment.