Skip to content

Commit

Permalink
Added DNSSection.new_from_hashes unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed May 1, 2019
1 parent 8361573 commit 9dc7108
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/y2network/autoinst_profile/dns_section_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,64 @@
expect(section.searchlist).to eq(["example.net"])
end
end

describe "#.new_from_hashes" do
let(:hash) do
{
"hostname" => "linux.example.org",
"dhcp_hostname" => true,
"resolv_conf_policy" => "auto",
"nameservers" => ["192.168.122.1", "10.0.0.1"],
"search_domains" => ["suse.com"]
}
end

let(:minimal_hash) do
{
"dhcp_hostname" => true,
"resolv_conf_policy" => "auto"
}
end

it "initializes the hostname" do
section = described_class.new_from_hashes(hash)
expect(section.hostname).to eq("linux.example.org")
end

it "initializes dhcp_hostname" do
section = described_class.new_from_hashes(hash)
expect(section.dhcp_hostname).to eq(true)
end

it "initializes resolv_conf_policy" do
section = described_class.new_from_hashes(hash)
expect(section.resolv_conf_policy).to eq("auto")
end

it "initializes the list of nameservers" do
section = described_class.new_from_hashes(hash)
expect(section.nameservers.size).to eql(2)
expect(section.nameservers).to include("10.0.0.1")
end

it "initializes searchlist" do
section = described_class.new_from_hashes(hash)
expect(section.searchlist).to eql(["suse.com"])
end

context "when scalar attributes are not defined" do
it "does not set the attribute" do
section = described_class.new_from_hashes(minimal_hash)
expect(section.hostname).to be_nil
end
end

context "when an array attribute is not defined" do
it "is initialized as empty" do
section = described_class.new_from_hashes(minimal_hash)
expect(section.nameservers).to be_empty
expect(section.nameservers).to be_a(Array)
end
end
end
end

0 comments on commit 9dc7108

Please sign in to comment.