Skip to content

Commit

Permalink
test(service): add an AutoYaST rules test
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed May 23, 2024
1 parent 5ae6e65 commit 8e89239
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
24 changes: 24 additions & 0 deletions service/test/agama/autoyast/converter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require "json"
require "tmpdir"
require "autoinstall/xml_checks"
require "y2storage"

describe Agama::AutoYaST::Converter do
let(:profile) { File.join(FIXTURES_PATH, "profiles", profile_name) }
Expand All @@ -43,6 +44,19 @@
content = File.read(File.join(workdir, "autoinst.json"))
JSON.parse(content)
end
let(:storage_manager) do
instance_double(
Y2Storage::StorageManager,
probed: storage_probed,
probed_disk_analyzer: disk_analyzer
)
end
let(:storage_probed) do
instance_double(Y2Storage::Devicegraph, disks: [])
end
let(:disk_analyzer) do
instance_double(Y2Storage::DiskAnalyzer, windows_partitions: [], linux_partitions: [])
end

before do
stub_const("Y2Autoinstallation::XmlChecks::ERRORS_PATH", File.join(tmpdir, "errors"))
Expand All @@ -55,6 +69,7 @@
allow(Yast::AutoinstConfig).to receive(:modified_profile)
.and_return(File.join(tmpdir, "profile", "modified.xml"))
allow(Y2Autoinstallation::XmlValidator).to receive(:new).and_return(xml_validator)
allow(Y2Storage::StorageManager).to receive(:instance).and_return(storage_manager)
end

after do
Expand Down Expand Up @@ -100,6 +115,15 @@
end
end

context "when the profile uses rules" do
let(:profile_name) { "profile/" }

it "evaluates the rules" do
subject.to_agama(workdir)
expect(result["product"]).to include("id" => "Tumbleweed")
end
end

context "when a product is selected" do
it "exports the selected product" do
subject.to_agama(workdir)
Expand Down
19 changes: 19 additions & 0 deletions service/test/fixtures/profiles/profile/rules/rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!DOCTYPE autoinstall>
<autoinstall xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
<rules config:type="list">
<rule>
<custom1>
<script>
echo -n testing.xml
</script>
<match>*</match>
<match_type>exact</match_type>
</custom1>
<result>
<profile>@custom1@</profile>
<continue config:type="boolean">false</continue>
</result>
</rule>
</rules>
</autoinstall>
14 changes: 14 additions & 0 deletions service/test/fixtures/profiles/profile/testing.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE profile>
<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
<software>
<products config:type="list">
<product>Tumbleweed</product>
</products>
<patterns config:type="list">
<pattern>enhanced_base</pattern>
</patterns>
</software>
</profile>


0 comments on commit 8e89239

Please sign in to comment.