Skip to content

Commit

Permalink
adapt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Nov 1, 2017
1 parent 9ba073c commit 8ede878
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions test/ntp_client_test.rb
Expand Up @@ -171,7 +171,7 @@
allow(Yast::NetworkInterfaces).to receive(:Read)
allow(Yast::Progress)
allow(Yast::PackageSystem).to receive(:CheckAndInstallPackagesInteractive)
.with(["ntp"]).and_return(true)
.with(["chrony"]).and_return(true)
end

context "when config has been read previously" do
Expand Down Expand Up @@ -222,7 +222,7 @@
context "when Mode is not installation" do
it "returns false if the ntp package neither is installed nor available" do
expect(Yast::PackageSystem).to receive(:CheckAndInstallPackagesInteractive)
.with(["ntp"]).and_return(false)
.with(["chrony"]).and_return(false)
expect(Yast::Service).not_to receive(:Enabled)

expect(subject.Read).to eql(false)
Expand Down Expand Up @@ -541,72 +541,61 @@

describe "#reachable_ntp_server?" do
context "given a server" do
it "returns true if sntp test passed with IPv4" do
expect(subject).to receive(:sntp_test).with("server").and_return(true)
expect(subject).not_to receive(:sntp_test).with("server", 6)
it "returns true if ntp test passed with IPv4" do
expect(subject).to receive(:ntp_test).with("server").and_return(true)
expect(subject).not_to receive(:ntp_test).with("server", 6)

expect(subject.reachable_ntp_server?("server")).to eql(true)
end

it "returns true if sntp test passed with IPv6" do
expect(subject).to receive(:sntp_test).with("server").and_return(false)
expect(subject).to receive(:sntp_test).with("server", 6).and_return(true)
it "returns true if ntp test passed with IPv6" do
expect(subject).to receive(:ntp_test).with("server").and_return(false)
expect(subject).to receive(:ntp_test).with("server", 6).and_return(true)

expect(subject.reachable_ntp_server?("server")).to eql(true)
end

it "returns false if sntp test fails with IPv4 and with IPv6" do
expect(subject).to receive(:sntp_test).with("server").and_return(false)
expect(subject).to receive(:sntp_test).with("server", 6).and_return(false)
it "returns false if ntp test fails with IPv4 and with IPv6" do
expect(subject).to receive(:ntp_test).with("server").and_return(false)
expect(subject).to receive(:ntp_test).with("server", 6).and_return(false)

expect(subject.reachable_ntp_server?("server")).to eql(false)
end
end
end

describe "#sntp_test" do
describe "#ntp_test" do
let(:ip_version) { 4 }
let(:server) { "sntp.server.de" }
let(:output) { { "stdout" => "", "stderr" => "", "exit" => 0 } }

it "calls sntp command with ip version 4 by default" do
it "calls ntp command with ip version 4 by default" do
expect(Yast::SCR).to receive(:Execute)
.with(Yast::Path.new(".target.bash_output"),
"LANG=C /usr/sbin/sntp -#{ip_version} -K /dev/null -t 5 -c #{server}")
/\/usr\/sbin\/chronyd.*#{server}/)
.and_return(output)

subject.sntp_test(server)
subject.ntp_test(server)
end

it "returns false if server is not reachable" do
output["stderr"] = "server_name lookup error Name or service not known"
it "returns false if chronyd returns non-zero" do
output["exit"] = 1
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.bash_output"),
"LANG=C /usr/sbin/sntp -#{ip_version} -K /dev/null -t 5 -c #{server}")
/\/usr\/sbin\/chronyd.*#{server}/)
.and_return(output)

expect(subject.sntp_test(server)).to eql(false)
expect(subject.ntp_test(server)).to eql(false)
end

it "returns false if sntp response includes 'no UCST'" do
output["stdout"] = "sntp 4.2.8p8@1.3265-o Fri Sep 30 15:52:10 UTC 2016 (1)\n" \
"195.113.144.2 no UCST response after 5 seconds\n"
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.bash_output"),
"LANG=C /usr/sbin/sntp -#{ip_version} -K /dev/null -t 5 -c #{server}")
.and_return(output)

expect(subject.sntp_test(server)).to eql(false)
end

it "returns true if sntp command's exit code is 0" do
it "returns true if chronyd command's exit code is 0" do
output["stdout"] = "sntp 4.2.8p8@1.3265-o Fri Sep 30 15:52:10 UTC 2016 (1)\n"
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.bash_output"),
"LANG=C /usr/sbin/sntp -#{ip_version} -K /dev/null -t 5 -c #{server}")
/\/usr\/sbin\/chronyd.*#{server}/)
.and_return(output)

expect(subject.sntp_test(server)).to eql(true)
expect(subject.ntp_test(server)).to eql(true)
end
end

Expand Down

0 comments on commit 8ede878

Please sign in to comment.