From 40b648d3bd75016415a02ab7de5bff59b23acf2e Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 18 Oct 2016 16:45:09 +0200 Subject: [PATCH] fixes from review --- src/modules/NtpClient.rb | 4 +-- test/ntp_client_test.rb | 75 ++++++++++++++++++---------------------- 2 files changed, 35 insertions(+), 44 deletions(-) diff --git a/src/modules/NtpClient.rb b/src/modules/NtpClient.rb index 4d7bb585..111ae074 100644 --- a/src/modules/NtpClient.rb +++ b/src/modules/NtpClient.rb @@ -793,8 +793,8 @@ def sntp_test(server, ip_version = 4) # so this is a workaround at least to return false in case server is not # reachable. return false if output["stderr"].include?("lookup error") - # this check is for valid address, but without ntp. If it break in future - # start complaining to sntp maintainer to not return 0 in this case. + # this happens for valid address, but without ntp server. If it breaks in the + # future start complaining to sntp maintainer to not return 0 in this case. # customer case: bsc#972842 return false if output["stdout"] =~ /no (U|B)CST/ diff --git a/test/ntp_client_test.rb b/test/ntp_client_test.rb index 0e58cc2d..cdc44839 100644 --- a/test/ntp_client_test.rb +++ b/test/ntp_client_test.rb @@ -1,5 +1,7 @@ require_relative "test_helper" +require "fileutils" + Yast.import "NtpClient" Yast.import "NetworkInterfaces" Yast.import "PackageSystem" @@ -414,55 +416,44 @@ let(:server) { "sntp.server.de" } let(:output) { { "stdout" => "", "stderr" => "", "exit" => 0 } } - context "given a server" do - context "when no ip_version is passed as argument" do - let(:output) do - { - "stderr" => "server_name lookup error Name or service not known", - "stdout" => "sntp 4.2.8p7@1.3265-o Thu May 12 16:14:59 UTC 2016", - "exit" => 0 - } - end - - it "calls sntp 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}") - .and_return(output) + it "calls sntp 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}") + .and_return(output) - subject.sntp_test(server) - end + subject.sntp_test(server) + end - it "returns false if server is not reachable" do - 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) + it "returns false if server is not reachable" do + output["stderr"] = "server_name lookup error Name or service not known" + 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 + expect(subject.sntp_test(server)).to eql(false) + end - it "returns false if sntp respong 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) + 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 + expect(subject.sntp_test(server)).to eql(false) + end - it "returns true if sntp command's exit code is 0" do - output["stderr"] = "" - 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) + it "returns true if sntp 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}") + .and_return(output) - expect(subject.sntp_test(server)).to eql(true) - end - end + expect(subject.sntp_test(server)).to eql(true) end end