Skip to content

Commit

Permalink
Add specs for the check_connection? method.
Browse files Browse the repository at this point in the history
djberg96 committed Nov 2, 2020
1 parent 28c384f commit 1ff084b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec/models/git_repository_spec.rb
Original file line number Diff line number Diff line change
@@ -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("[email protected]: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

0 comments on commit 1ff084b

Please sign in to comment.