Skip to content

Commit

Permalink
Extend AutoinstGeneral unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed May 27, 2020
1 parent 82d9874 commit 41cb30c
Showing 1 changed file with 167 additions and 8 deletions.
175 changes: 167 additions & 8 deletions test/AutoinstGeneral_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let(:profile) do
{
"storage" => { "start_multipath" => true },
"mode" => { "confirm" => false },
"mode" => { "confirm" => true },
"signature-handling" => { "import_gpg_key" => true },
"ask-list" => ["ask1"],
"proposals" => ["proposal1"]
Expand All @@ -23,9 +23,63 @@
allow(Yast).to receive(:import).with("FileSystems").and_return(nil)
end

describe "#main" do
let(:second_stage) { false }
let(:imported_profile) { { "general" => general_settings } }
let(:general_settings) { { "mode" => true } }

before do
allow(Yast::Stage).to receive(:cont).and_return(second_stage)
end

context "on first stage" do
let(:second_stage) { false }

it "does not try to import the profile" do
expect(subject).to_not receive(:Import)
subject.main
end

it "does not set the signatures handling callbacks" do
expect(subject).to_not receive(:SetSignatureHandling)
subject.main
end
end

context "on second stage" do
let(:second_stage) { true }

before do
allow(Yast::Profile).to receive(:current).and_return(imported_profile)
end

context "and the profile contains a 'general' section" do
it "imports the profile" do
expect(subject).to receive(:Import).with(general_settings)
subject.main
end
end

context "and the profile does not contain a 'general' section" do
let(:general_settings) { {} }

it "does not try to import the profile" do
expect(subject).to_not receive(:Import)
subject.main
end
end

it "sets the signatures handling callbacks" do
expect(subject).to receive(:SetSignatureHandling)
subject.main
end
end
end

describe "#Write" do
before do
allow(Yast::AutoinstStorage).to receive(:Write)
subject.Import(profile)
end

context "when a NTP server is set" do
Expand All @@ -34,25 +88,21 @@
end

it "syncs hardware time" do
subject.Import(profile)

expect(Yast::NtpClient).to receive(:sync_once).with("ntp.suse.de").and_return(0)

expect(Yast::SCR).to receive(:Execute).with(path(".target.bash"), "/sbin/hwclock --systohc")
.and_return(0)

subject.Write()
subject.Write
end

it "does not sync hardware time if ntp sync failed" do
subject.Import(profile)

expect(Yast::NtpClient).to receive(:sync_once).with("ntp.suse.de").and_return(1)

expect(Yast::SCR).to_not receive(:Execute)
.with(path(".target.bash"), "/sbin/hwclock --systohc")

subject.Write()
subject.Write
end
end

Expand All @@ -63,7 +113,70 @@
subject.Import(profile)
expect(Yast::SCR).not_to receive(:Execute)
.with(path(".target.bash"), /hwclock/)
subject.Write()
subject.Write
end
end

context "mode options" do
context "when mode options are set" do
let(:profile) do
{
"mode" => {
"confirm" => true, "second_stage" => true, "halt" => true, "rebootmsg" => true
}
}
end

it "saves mode options" do
expect(Yast::AutoinstConfig).to receive(:second_stage=).with(true)
expect(Yast::AutoinstConfig).to receive(:Halt=).with(true)
expect(Yast::AutoinstConfig).to receive(:RebootMsg=).with(true)
subject.Write
end
end

context "when mode options are not set" do
let(:profile) { {} }

it "saves default values" do
expect(Yast::AutoinstConfig).to_not receive(:second_stage=)
expect(Yast::AutoinstConfig).to receive(:Halt=).with(false)
expect(Yast::AutoinstConfig).to receive(:RebootMsg=).with(false)
subject.Write
end
end

it "sets signature handling callbacks" do
expect(subject).to receive(:SetSignatureHandling)
subject.Write
end
end

context "when 'forceboot' is not set" do
it "does not set the kexec_reboot option in the product control" do
expect(Yast::ProductFeatures).to_not receive(:SetBooleanFeature)
.with("globals", "kexec_reboot", anything)
subject.Write
end
end

context "when 'forceboot' is set to 'false'" do
let(:profile) { { "mode" => { "forceboot" => false } } }

it "sets the kexec_reboot option in the product control to 'false'" do
expect(Yast::ProductFeatures).to_not receive(:SetBooleanFeature)
.with("globals", "kexec_reboot", false)
subject.Write
end
end

context "when 'forceboot' is set to 'true'" do
let(:profile) { { "mode" => { "forceboot" => true } } }

it "sets the kexec_reboot option in the product control to 'true'" do
expect(Yast::ProductFeatures).to_not receive(:SetBooleanFeature)
.with("globals", "kexec_reboot", true)
subject.Write
end
end
end
Expand Down Expand Up @@ -235,5 +348,51 @@
expect(summary).to include("Confirm installation?")
expect(summary).to include("Signature Handling")
end

context "when signature handling checks are disabled" do
before do
subject.Import(
"signature-handling" => {
"accept_unsigned_file" => true,
"accept_file_without_checksum" => true,
"accept_verification_failed" => true,
"accept_unknown_gpg_key" => true,
"import_gpg_key" => true
}
)
end

it "includes signature settings values" do
summary = subject.Summary
expect(summary).to include("Accepting unsigned files")
expect(summary).to include("Accepting files without a checksum")
expect(summary).to include("Accepting failed verifications")
expect(summary).to include("Accepting unknown GPG keys")
expect(summary).to include("Importing new GPG keys")
end
end

context "when signature handling checks are not disabled" do
before do
subject.Import(
"signature-settings" => {
"accept_unsigned_file" => false,
"accept_file_without_checksum" => false,
"accept_verification_failed" => false,
"accept_unknown_gpg_key" => false,
"import_gpg_key" => false
}
)
end

it "includes signature settings values" do
summary = subject.Summary
expect(summary).to include("Not accepting unsigned files")
expect(summary).to include("Not accepting files without a checksum")
expect(summary).to include("Not accepting failed verifications")
expect(summary).to include("Not accepting unknown GPG Keys")
expect(summary).to include("Not importing new GPG Keys")
end
end
end
end

0 comments on commit 41cb30c

Please sign in to comment.