Skip to content

Commit

Permalink
adapted testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Dec 30, 2016
1 parent 1af239f commit b361f44
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 10 deletions.
6 changes: 3 additions & 3 deletions test/fixtures/autoyast/autoinst.xml
Expand Up @@ -2,7 +2,7 @@
<!DOCTYPE profile>
<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
<ntp-client>
<ntp_policy>auto</ntp_policy>
<ntp_policy>STATIC</ntp_policy>
<peers config:type="list">
<peer>
<address>0.opensuse.pool.ntp.org</address>
Expand Down Expand Up @@ -51,7 +51,7 @@
</restricts>
<start_at_boot config:type="boolean">true</start_at_boot>
<start_in_chroot config:type="boolean">false</start_in_chroot>
<sync_interval config:type="integer">5</sync_interval>
<synchronize_time config:type="boolean">false</synchronize_time>
<sync_interval config:type="integer">15</sync_interval>
<synchronize_time config:type="boolean">true</synchronize_time>
</ntp-client>
</profile>
95 changes: 88 additions & 7 deletions test/ntp_client_test.rb
Expand Up @@ -22,17 +22,98 @@
CFA::NtpConf.new(file_handler: file_handler)
end

describe "#AutoYaST" do
describe "#AutoYaST methods" do
FIXTURES_PATH = File.join(File.dirname(__FILE__), "fixtures")
let(:profile) { File.join(FIXTURES_PATH, "autoyast", "autoinst.xml") }

before(:each) do
Yast::Profile.ReadXML(profile)
let(:ntp_client_section) do
file = File.join(FIXTURES_PATH, 'autoyast', profile_name)
Yast::Profile.ReadXML(file)
Yast::Profile.current["ntp-client"]
end

it "imports/exports settings from/to AutoYaST configuration file" do
subject.Import(Yast::Profile.current["ntp-client"])
expect(subject.Export()).to eql(Yast::Profile.current["ntp-client"])
describe "#Import" do
context "with a correct AutoYaST configuration file" do
let(:profile_name) { "autoinst.xml" }

before(:each) do
subject.Import(ntp_client_section)
end

it "reads the list of peers" do
expect(subject.ntp_records.size).to eq 4
end

it "reads the list of restricts" do
expect(subject.restrict_map.keys).to contain_exactly(
"default", "127.0.0.1", "::1"
)
end

it "reads synchronize flag" do
expect(subject.synchronize_time).to eq true
end

it "reads start at boot flag" do
expect(subject.run_service).to eq true
end

it "reads start in chroot environment flag" do
expect(subject.run_chroot).to eq false
end

it "reads policy" do
expect(subject.ntp_policy).to eq "STATIC"
end

it "reads sync intervall" do
expect(subject.sync_interval).to eq 15
end
end

context "with an empty AutoYaST configuration" do
let(:ntp_client_section) { {} }

before(:each) do
subject.Import(ntp_client_section)
end

it "sets an empty peer list" do
expect(subject.ntp_records).to be_empty
end

it "sets an empty restricts list" do
expect(subject.restrict_map).to be_empty
end

it "sets default synchronize flag" do
expect(subject.synchronize_time).to eq false
end

it "sets default start at boot flag" do
expect(subject.run_service).to eq false
end

it "sets default start in chroot environment flag" do
expect(subject.run_chroot).to eq true
end

it "sets default policy" do
expect(subject.ntp_policy).to eq ""
end

it "set default sync intervall" do
expect(subject.sync_interval).to eq 5
end
end
end

describe "#Export" do
let(:profile_name) { "autoinst.xml" }

it "produces an output equivalent to #Import" do
subject.Import(ntp_client_section)
expect(subject.Export()).to eq ntp_client_section
end
end
end

Expand Down

0 comments on commit b361f44

Please sign in to comment.