From 1ff084b2467d5930b3f722d9c3c9886a17bf5e9b Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Mon, 2 Nov 2020 07:37:13 -0500 Subject: [PATCH] Add specs for the check_connection? method. --- spec/models/git_repository_spec.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/models/git_repository_spec.rb b/spec/models/git_repository_spec.rb index 961c09ae73a..f01a13fa898 100644 --- a/spec/models/git_repository_spec.rb +++ b/spec/models/git_repository_spec.rb @@ -345,5 +345,35 @@ end end end + + context "check_connection?" do + require 'net/ping/external' + let(:ext_ping) { instance_double(Net::Ping::External) } + + before do + allow(Net::Ping::External).to receive(:new).and_return(ext_ping) + allow(ext_ping).to receive(:exception) + end + + it "returns true if it can ping the repo" do + allow(ext_ping).to receive(:ping?).and_return(true) + expect($log).to receive(:debug).with(/pinging '.*' to verify network connection/) + expect(repo.check_connection?).to eq(true) + end + + it "returns false if it cannot ping the repo" do + allow(ext_ping).to receive(:ping?).and_return(false) + expect($log).to receive(:debug).with(/pinging '.*' to verify network connection/) + expect($log).to receive(:debug).with(/ping failed: .*/) + expect(repo.check_connection?).to eq(false) + end + + it "handles git urls without issue" do + allow(repo).to receive(:url).and_return("git@example.com:ManageIQ/manageiq.git") + allow(ext_ping).to receive(:ping?).and_return(true) + expect($log).to receive(:debug).with(/pinging 'example.com' to verify network connection/) + expect(repo.check_connection?).to eq(true) + end + end end end