Skip to content

Commit

Permalink
fixed testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Jun 28, 2023
1 parent 020de9c commit f67c5ab
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/lib/cfa/systemd_boot.rb
Expand Up @@ -43,7 +43,9 @@ class SystemdBoot < BaseModel
include Yast::Logger

attributes(
menue_timeout: "timeout"
menue_timeout: "timeout",
console_mode: "console_mode",
default: "default"
)

# Instantiates and loads a file when possible
Expand Down
86 changes: 86 additions & 0 deletions test/cfa/systemd_boot_test.rb
@@ -0,0 +1,86 @@
require_relative "../test_helper"

require "cfa/systemd_boot"

describe CFA::SystemdBoot do
subject(:selinux_config_file) do
described_class.load(file_path: file_path, file_handler: file_handler)
end

let(:systemd_boot_path) { "loader.conf" }
let(:file_handler) { File }
let(:file_path) { File.join(DATA_PATH, "boot/efi/loader/loader.conf") }

describe ".load" do
context "when file exist" do
it "creates an own Augeas instance using spacevars lens" do
expect(::CFA::AugeasParser).to receive(:new).with("spacevars.lns").and_call_original

described_class.load(file_path: file_path, file_handler: file_handler)
end

it "loads the file content" do
file = described_class.load(file_path: file_path, file_handler: file_handler)

expect(file.loaded?).to eq(true)
end
end

context "when file does not exist" do
let(:file_path) { "/file/not/created/yet" }

it "creates an own Augeas instance using spacevars lens" do
expect(::CFA::AugeasParser).to receive(:new).with("spacevars.lns").and_call_original

described_class.load(file_path: file_path, file_handler: file_handler)
end

it "does not load the file content" do
file = described_class.load(file_path: file_path, file_handler: file_handler)

expect(file.loaded?).to eq(false)
end
end
end

describe "#initialize" do
it "creates an own Augeas instance using spacevars lens" do
expect(::CFA::AugeasParser).to receive(:new).with("spacevars.lns").and_call_original

described_class.new(file_handler: file_handler)
end
end

describe "#menue_timeout" do
it "returns the timeout value" do
expect(subject.menue_timeout).to eq("10")
end
end

describe "#menue_timeout=" do
it "sets the menue_timeout value" do
expect { subject.menue_timeout = "15" }
.to change { subject.menue_timeout }.from("10").to("15")
end
end

describe "#save" do
let(:timeout) { "20" }

before do
allow(Yast::SCR).to receive(:Write)
allow(file_handler).to receive(:read).with(file_path)
.and_return("# Some comment\ntimeout 5")
subject.load
subject.menue_timeout = timeout
end

it "writes changes to configuration file" do
expect(file_handler).to receive(:write)
.with(file_path, /.*timeout #{timeout}.*/)

subject.save
end
end

end
2 changes: 1 addition & 1 deletion test/data/boot/efi/loader/loader.conf
@@ -1,3 +1,3 @@
timeout 10
#console-mode keep
console-mode keep
default opensuse-tumbleweed-*
2 changes: 1 addition & 1 deletion test/systemdboot_test.rb
Expand Up @@ -24,7 +24,6 @@
subject.read

expect(subject.secure_boot).to eq true
expect(subject.menue_timeout).to eq 10
end
end

Expand All @@ -40,6 +39,7 @@
allow(Yast::Installation).to receive(:destdir).and_return(File.expand_path("data/", __dir__))
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/kernel-install", "add", "testkernel", "/usr/lib/modules/testkernel/vmlinuz")
expect_any_instance_of(CFA::SystemdBoot).to receive(:save)

subject.menue_timeout = 10
subject.write
Expand Down
3 changes: 3 additions & 0 deletions test/test_helper.rb
@@ -1,5 +1,8 @@
# frozen_string_literal: true

# Set the paths
DATA_PATH = File.join(File.expand_path(File.dirname(__FILE__)), "data")

ENV["Y2DIR"] = File.expand_path("../src", __dir__)

# localization agnostic tests
Expand Down

0 comments on commit f67c5ab

Please sign in to comment.