Skip to content

Commit

Permalink
adjust unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wfeldt committed Apr 7, 2021
1 parent 9d39af3 commit 58a7a17
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 895 deletions.
807 changes: 0 additions & 807 deletions src/modules/Profile.rb~

This file was deleted.

16 changes: 9 additions & 7 deletions test/AutoinstFunctions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

context "registration has not been defined in AY configuration file" do
it "reports error to set registration" do
allow(Yast::Profile).to receive(:current).and_return({})
allow(Yast::Profile).to receive(:current).and_return(Yast::ProfileHash.new)
expect(subject.check_second_stage_environment).to(
include("configuring the registration")
)
Expand Down Expand Up @@ -132,7 +132,7 @@ def base_product(name)
"and such base product exists on media" do
allow(Yast::Profile)
.to receive(:current)
.and_return("software" => { "products" => [selected_name] })
.and_return(Yast::ProfileHash.new("software" => { "products" => [selected_name] }))

expect(subject.selected_product.name).to eql selected_name
end
Expand All @@ -141,7 +141,9 @@ def base_product(name)
"such base product doesn't exist on media" do
allow(Yast::Profile)
.to receive(:current)
.and_return("software" => { "products" => { "product" => "Fedora" } })
.and_return(
Yast::ProfileHash.new("software" => { "products" => { "product" => "Fedora" } })
)

expect(subject.selected_product).to be nil
end
Expand All @@ -150,7 +152,7 @@ def base_product(name)
"if such base product exists on media" do
allow(Yast::Profile)
.to receive(:current)
.and_return("software" => { "patterns" => ["sles-base-32bit"] })
.and_return(Yast::ProfileHash.new("software" => { "patterns" => ["sles-base-32bit"] }))

expect(subject.selected_product.name).to eql selected_name
end
Expand All @@ -159,7 +161,7 @@ def base_product(name)
"if such base product exists on media" do
allow(Yast::Profile)
.to receive(:current)
.and_return("software" => { "packages" => ["sles-release"] })
.and_return(Yast::ProfileHash.new("software" => { "packages" => ["sles-release"] }))

expect(subject.selected_product.name).to eql selected_name
end
Expand All @@ -171,7 +173,7 @@ def base_product(name)
.and_return(double(available_base_products: [base_product("SLED")]))
allow(Yast::Profile)
.to receive(:current)
.and_return("software" => {})
.and_return(Yast::ProfileHash.new("software" => {}))

expect(subject.selected_product.name).to eql "SLED"
end
Expand All @@ -180,7 +182,7 @@ def base_product(name)
before do
allow(Yast::Profile)
.to receive(:current)
.and_return("software" => nil)
.and_return(Yast::ProfileHash.new("software" => nil))
end

it "returns nil" do
Expand Down
87 changes: 47 additions & 40 deletions test/AutoinstScripts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative "test_helper"

Yast.import "Profile"
Yast.import "AutoinstScripts"

describe "Yast::AutoinstScripts" do
Expand Down Expand Up @@ -35,10 +36,12 @@
shared_examples "resolve location" do
# this examples expect to have defined type and key
it "strip white spaces from location" do
data = { key => [
{ "location" => "https://test.com/script \n \t " },
{ "location" => "\n\t https://test.com/script2" }
] }
data = Yast::ProfileHash.new(
key => [
{ "location" => "https://test.com/script \n \t " },
{ "location" => "\n\t https://test.com/script2" }
]
)
expected = [
"https://test.com/script",
"https://test.com/script2"
Expand All @@ -54,10 +57,12 @@
end

it "resolve relurl using autoyast profile url" do
data = { key => [
{ "location" => "https://test.com/script" },
{ "location" => "relurl://script2" }
] }
data = Yast::ProfileHash.new(
key => [
{ "location" => "https://test.com/script" },
{ "location" => "relurl://script2" }
]
)
expected = [
"https://test.com/script",
"https://example.com/script2"
Expand All @@ -76,10 +81,12 @@
end

it "resolve relurl using ayrelurl from install.inf" do
data = { key => [
{ "location" => "https://test.com/script" },
{ "location" => "relurl://script2" }
] }
data = Yast::ProfileHash.new(
key => [
{ "location" => "https://test.com/script" },
{ "location" => "relurl://script2" }
]
)
expected = ["https://test.com/script", "https://example2.com/ay/script2"]

subject.Import(data)
Expand Down Expand Up @@ -121,11 +128,11 @@

describe "#Export" do
it "returns hash with defined scripts" do
data = {
data = Yast::ProfileHash.new(
"pre-scripts" => [{ "location" => "http://test.com/new_script", "param-list" => [],
"filename" => "script4", "source" => "", "interpreter" => "perl", "rerun" => false,
"debug" => false, "feedback" => false, "feedback_type" => "", "notification" => "" }]
}
)

subject.Import(data)
expect(subject.Export).to eq data
Expand All @@ -134,11 +141,11 @@

describe "#Summary" do
it "returns richtext string with scripts summary" do
data = {
data = Yast::ProfileHash.new(
"pre-scripts" => [{ "location" => "http://test.com/script" }],
"post-scripts" => [{ "location" => "http://test.com/script2" },
{ "location" => "http://test.com/script3" }]
}
)

subject.Import(data)
expect(subject.Summary).to be_a(::String)
Expand All @@ -148,11 +155,11 @@
describe "#AddEditScript" do
context "given filename exists" do
it "edits existing one" do
data = {
data = Yast::ProfileHash.new(
"pre-scripts" => [{ "location" => "http://test.com/script", "filename" => "script1" }],
"post-scripts" => [{ "location" => "http://test.com/script2", "filename" => "script2" },
{ "location" => "http://test.com/script3", "filename" => "script3" }]
}
)

subject.Import(data)

Expand All @@ -170,11 +177,11 @@

context "given filename does not exist" do
it "adds new one to merged" do
data = {
data = Yast::ProfileHash.new(
"pre-scripts" => [{ "location" => "http://test.com/script", "filename" => "script1" }],
"post-scripts" => [{ "location" => "http://test.com/script2", "filename" => "script2" },
{ "location" => "http://test.com/script3", "filename" => "script3" }]
}
)

subject.Import(data)

Expand All @@ -193,11 +200,11 @@

describe "#deleteScript" do
it "removes script with given filename from merged list" do
data = {
data = Yast::ProfileHash.new(
"pre-scripts" => [{ "location" => "http://test.com/script", "filename" => "script1" }],
"post-scripts" => [{ "location" => "http://test.com/script2", "filename" => "script2" },
{ "location" => "http://test.com/script3", "filename" => "script3" }]
}
)

subject.Import(data)

Expand Down Expand Up @@ -230,9 +237,9 @@

context "for pre-scripts" do
it "downloads script from location if defined" do
data = {
data = Yast::ProfileHash.new(
"pre-scripts" => [{ "location" => "http://test.com/script", "filename" => "script1" }]
}
)

expect_any_instance_of(Yast::Transfer::FileFromUrl).to(
receive(:get_file_from_url) do |_klass, map|
Expand All @@ -250,10 +257,10 @@
end

it "creates script file from source if location not defined" do
data = {
data = Yast::ProfileHash.new(
"pre-scripts" => [{ "source" => "echo krucifix > /home/dabel/body",
"filename" => "script1" }]
}
)

expect(Yast::SCR).to receive(:Write).with(path(".target.string"),
/pre-scripts\/script1$/, "echo krucifix > /home/dabel/body")
Expand Down Expand Up @@ -283,10 +290,10 @@

context "for postpartitioning-scripts" do
it "downloads script from location if defined" do
data = {
data = Yast::ProfileHash.new(
"postpartitioning-scripts" => [{ "location" => "http://test.com/script",
"filename" => "script1" }]
}
)

expect_any_instance_of(Yast::Transfer::FileFromUrl).to(
receive(:get_file_from_url) do |_klass, map|
Expand All @@ -304,10 +311,10 @@
end

it "creates script file from source if location not defined" do
data = {
data = Yast::ProfileHash.new(
"postpartitioning-scripts" => [{ "source" => "echo krucifix > /home/dabel/body",
"filename" => "script1" }]
}
)

expect(Yast::SCR).to receive(:Write).with(path(".target.string"),
/script1$/, "echo krucifix > /home/dabel/body")
Expand All @@ -319,9 +326,9 @@

context "for init-scripts" do
it "downloads script from location if defined" do
data = {
data = Yast::ProfileHash.new(
"init-scripts" => [{ "location" => "http://test.com/script", "filename" => "script1" }]
}
)

expect_any_instance_of(Yast::Transfer::FileFromUrl).to(
receive(:get_file_from_url) do |_klass, map|
Expand All @@ -339,10 +346,10 @@
end

it "creates script file from source if location not defined" do
data = {
data = Yast::ProfileHash.new(
"init-scripts" => [{ "source" => "echo krucifix > /home/dabel/body",
"filename" => "script1" }]
}
)

expect(Yast::SCR).to receive(:Write).with(path(".target.string"),
"/var/adm/autoinstall/init.d/script1", "echo krucifix > /home/dabel/body")
Expand All @@ -353,10 +360,10 @@
end

it "executes script" do
data = {
data = Yast::ProfileHash.new(
"pre-scripts" => [{ "location" => "http://test.com/script", "filename" => "script1",
"interpreter" => "shell", "rerun" => true }]
}
)

expect(Yast::SCR).to receive(:Execute).with(path(".target.bash"), /\/bin\/sh/)

Expand All @@ -365,10 +372,10 @@
end

it "shows a feedback during script when notification is set for script" do
data = {
data = Yast::ProfileHash.new(
"pre-scripts" => [{ "location" => "http://test.com/script", "filename" => "script1",
"interpreter" => "shell", "rerun" => true, "notification" => "Script1!!!" }]
}
)

expect(Yast::Popup).to receive(:ShowFeedback).with("", "Script1!!!")
expect(Yast::Popup).to receive(:ClearFeedback)
Expand All @@ -378,10 +385,10 @@
end

it "shows a report if feedback parameter is set" do
data = {
data = Yast::ProfileHash.new(
"pre-scripts" => [{ "location" => "http://test.com/script", "filename" => "script1",
"interpreter" => "shell", "feedback" => true, "feedback_type" => "error", "rerun" => true }]
}
)

allow(Yast::SCR).to receive(:Read).and_return("test")
expect(Yast::Report).to receive(:Error)
Expand Down
22 changes: 14 additions & 8 deletions test/lib/autosetup_helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DummyClient < Yast::Client
end

describe "#suse_register" do
let(:profile_content) { { "general" => {} } }
let(:profile_content) { Yast::ProfileHash.new("general" => {}) }
let(:reg_module_available) { true }

before do
Expand Down Expand Up @@ -86,7 +86,9 @@ class DummyClient < Yast::Client
end

context "suse_register tag is defined in AY file" do
let(:profile_content) { { "suse_register" => { "reg_code" => "12345" } } }
let(:profile_content) do
Yast::ProfileHash.new("suse_register" => { "reg_code" => "12345" })
end

before do
allow(Yast::WFM).to receive(:CallFunction).with("inst_download_release_notes")
Expand Down Expand Up @@ -130,7 +132,9 @@ class DummyClient < Yast::Client
end

context "semi-automatic is defined in AY file" do
let(:profile_content) { { "general" => { "semi-automatic" => ["scc"] } } }
let(:profile_content) do
Yast::ProfileHash.new("general" => { "semi-automatic" => ["scc"] })
end
it "shows registration screen mask and returns true" do
# Showing registration screen mask
expect(Yast::WFM).to receive(:CallFunction).with("inst_scc",
Expand Down Expand Up @@ -243,7 +247,7 @@ class DummyClient < Yast::Client
end

describe "#autosetup_firewall" do
let(:profile) { { "firewall" => firewall_section } }
let(:profile) { Yast::ProfileHash.new("firewall" => firewall_section) }
let(:firewall_section) { { "default_zone" => "external" } }

before(:each) do
Expand Down Expand Up @@ -284,7 +288,7 @@ class DummyClient < Yast::Client
end

describe "#autosetup_network" do
let(:profile) { networking_section }
let(:profile) { Yast::ProfileHash.new(networking_section) }
let(:networking_section) { { "networking" => { "setup_before_proposal" => true } } }
let(:host_section) { { "host" => { "hosts" => [] } } }

Expand All @@ -311,7 +315,7 @@ class DummyClient < Yast::Client
end

context "and the setup is defined to be run before the proposal" do
let(:profile) { networking_section.merge(host_section) }
let(:profile) { Yast::ProfileHash.new(networking_section.merge(host_section)) }
let(:networking_section) { { "networking" => { "setup_before_proposal" => true } } }

context "and a host section is defined" do
Expand Down Expand Up @@ -372,7 +376,7 @@ class DummyClient < Yast::Client
end

describe "#semi_auto?" do
let(:profile) { general_section }
let(:profile) { Yast::ProfileHash.new(general_section) }
let(:general_section) { { "general" => { "semi-automatic" => ["networking"] } } }

before do
Expand All @@ -391,7 +395,9 @@ class DummyClient < Yast::Client
end

describe "#autosetup_country" do
let(:profile) { language_section.merge(timezone_section).merge(keyboard_section) }
let(:profile) do
Yast::ProfileHash.new(language_section.merge(timezone_section).merge(keyboard_section))
end
let(:language_section) { { "language" => { "language" => "de_DE", "languages" => "es_ES" } } }
let(:timezone_section) { {} }
let(:keyboard_section) { {} }
Expand Down

0 comments on commit 58a7a17

Please sign in to comment.