forked from voxpupuli/modulesync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitService: Improve hostname extraction
This commit adds support for more repository notations and provides unit tests.
- Loading branch information
Showing
3 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require 'modulesync' | ||
require 'modulesync/git_service' | ||
|
||
describe ModuleSync::GitService do | ||
|
@@ -164,4 +165,43 @@ | |
end | ||
end | ||
end | ||
|
||
RSpec.shared_examples 'hostname_extractor' do |url, hostname| | ||
context "with '#{url}' URL" do | ||
subject { ModuleSync::GitService.extract_hostname(url) } | ||
it "should extract '#{hostname}' as hostname" do | ||
expect(subject).to eq(hostname) | ||
end | ||
end | ||
end | ||
|
||
context '#extract_hostname' do | ||
[ | ||
%w[ssh://[email protected]:4444/path/to/repo.git/ host.xz], | ||
%w[ssh://[email protected]:/path/to/repo.git/ host.xz], | ||
%w[ssh://host.xz/path/to/repo.git/ host.xz], | ||
|
||
%w[git://host.xz/path/to/repo.git/ host.xz], | ||
%w[git://host.xz/path/to/repo/ host.xz], | ||
%w[git://host.xz/path/to/repo host.xz], | ||
|
||
%w[[email protected]:path/to/repo.git/ host.xz], | ||
%w[[email protected]:path/to/repo.git host.xz], | ||
%w[[email protected]:path/to/repo host.xz], | ||
%w[host.xz:path/to/repo.git/ host.xz], | ||
|
||
%w[https://host.xz:8443/path/to/repo.git/ host.xz], | ||
%w[https://host.xz/path/to/repo.git/ host.xz], | ||
|
||
%w[ftp://host.xz/path/to/repo/ host.xz], | ||
|
||
['/path/to/repo.git/', nil], | ||
|
||
['file:///path/to/repo.git/', nil], | ||
|
||
['something-invalid', nil], | ||
].each do |url, hostname| | ||
it_should_behave_like 'hostname_extractor', url, hostname | ||
end | ||
end | ||
end |