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 17d7aad commit 056200f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
56 changes: 37 additions & 19 deletions test/cfa/systemd_boot_test.rb
Expand Up @@ -3,33 +3,51 @@
require "cfa/systemd_boot"

describe CFA::SystemdBoot do
let(:file_handler) do
file_path = File.expand_path("../../data/boot/efi/loader/loader.conf", __FILE__)
CFA::SystemdBoot.new(File.read(file_path), "/boot/efi/loader/loader.conf")
subject(:selinux_config_file) do
described_class.load(file_path: file_path, file_handler: file_handler)
end

subject do
described_class.new(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") }

before do
subject.load
end
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)

describe "#load" do
it "loads all attributes" do
expect(subject.menue_timeout).to eq "10"
expect(subject.console_mode).to eq "keep"
expect(subject.default).to eq "opensuse-tumbleweed-*"
expect(file.loaded?).to eq(false)
end
end
end

describe "#save" do
it "stores properly attributes" do
subject.menue_timeout = "15"
subject.save
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

expect(file_handler.content.lines).to include("timeout=15\n")
described_class.new(file_handler: file_handler)
end
end
end
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 056200f

Please sign in to comment.