From 59d49f70c3b36e633b78e82fe3bd85b53f06900b Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 13 Feb 2018 23:35:45 +0800 Subject: Rename Git::Repository::Location to Git::Location --- qa/qa.rb | 1 + qa/qa/git/location.rb | 39 +++++++++++++++++++++++ qa/qa/git/repository.rb | 2 -- qa/qa/git/repository/location.rb | 41 ------------------------ qa/spec/git/location_spec.rb | 55 +++++++++++++++++++++++++++++++++ qa/spec/git/repository/location_spec.rb | 55 --------------------------------- 6 files changed, 95 insertions(+), 98 deletions(-) create mode 100644 qa/qa/git/location.rb delete mode 100644 qa/qa/git/repository/location.rb create mode 100644 qa/spec/git/location_spec.rb delete mode 100644 qa/spec/git/repository/location_spec.rb (limited to 'qa') diff --git a/qa/qa.rb b/qa/qa.rb index c1b5d278186..c6de8625f3d 100644 --- a/qa/qa.rb +++ b/qa/qa.rb @@ -169,6 +169,7 @@ module QA # module Git autoload :Repository, 'qa/git/repository' + autoload :Location, 'qa/git/location' end ## diff --git a/qa/qa/git/location.rb b/qa/qa/git/location.rb new file mode 100644 index 00000000000..fa3f5721d7a --- /dev/null +++ b/qa/qa/git/location.rb @@ -0,0 +1,39 @@ +require 'uri' +require 'forwardable' + +module QA + module Git + class Location + extend Forwardable + + attr_reader :git_uri, :uri + def_delegators :@uri, :user, :host, :path + + # See: config/initializers/1_settings.rb + # Settings#build_gitlab_shell_ssh_path_prefix + def self.parse(git_uri) + if git_uri.start_with?('ssh://') + new(git_uri, URI.parse(git_uri)) + else + *rest, path = git_uri.split(':') + # Host cannot have : so we'll need to escape it + user_host = rest.join('%3A').sub(/\A\[(.+)\]\z/, '\1') + new(git_uri, URI.parse("ssh://#{user_host}/#{path}")) + end + end + + def initialize(git_uri, uri) + @git_uri = git_uri + @uri = uri + end + + def scheme + uri.scheme || 'ssh' + end + + def port + uri.port || 22 + end + end + end +end diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb index 903d292b69c..8eb7031f609 100644 --- a/qa/qa/git/repository.rb +++ b/qa/qa/git/repository.rb @@ -4,8 +4,6 @@ require 'uri' module QA module Git class Repository - autoload :Location, 'qa/git/repository/location' - include Scenario::Actable def self.perform(*args) diff --git a/qa/qa/git/repository/location.rb b/qa/qa/git/repository/location.rb deleted file mode 100644 index dce8327ce82..00000000000 --- a/qa/qa/git/repository/location.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'uri' -require 'forwardable' - -module QA - module Git - class Repository - class Location - extend Forwardable - - attr_reader :git_uri, :uri - def_delegators :@uri, :user, :host, :path - - # See: config/initializers/1_settings.rb - # Settings#build_gitlab_shell_ssh_path_prefix - def self.parse(git_uri) - if git_uri.start_with?('ssh://') - new(git_uri, URI.parse(git_uri)) - else - *rest, path = git_uri.split(':') - # Host cannot have : so we'll need to escape it - user_host = rest.join('%3A').sub(/\A\[(.+)\]\z/, '\1') - new(git_uri, URI.parse("ssh://#{user_host}/#{path}")) - end - end - - def initialize(git_uri, uri) - @git_uri = git_uri - @uri = uri - end - - def scheme - uri.scheme || 'ssh' - end - - def port - uri.port || 22 - end - end - end - end -end diff --git a/qa/spec/git/location_spec.rb b/qa/spec/git/location_spec.rb new file mode 100644 index 00000000000..4c68a0cda61 --- /dev/null +++ b/qa/spec/git/location_spec.rb @@ -0,0 +1,55 @@ +describe QA::Git::Location do + describe '.parse' do + context 'when URI starts with ssh://' do + context 'when URI has port' do + it 'parses correctly' do + uri = described_class + .parse('ssh://git@qa.test:2222/sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.port).to eq(2222) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + + context 'when URI does not have port' do + it 'parses correctly' do + uri = described_class + .parse('ssh://git@qa.test/sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.port).to eq(22) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + end + + context 'when URI does not start with ssh://' do + context 'when host does not have colons' do + it 'parses correctly' do + uri = described_class + .parse('git@qa.test:sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.port).to eq(22) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + + context 'when host has a colon' do + it 'parses correctly' do + uri = described_class + .parse('[git@qa:test]:sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa%3Atest') + expect(uri.port).to eq(22) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + end + end +end diff --git a/qa/spec/git/repository/location_spec.rb b/qa/spec/git/repository/location_spec.rb deleted file mode 100644 index c1fe01becd7..00000000000 --- a/qa/spec/git/repository/location_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -describe QA::Git::Repository::Location do - describe '.parse' do - context 'when URI starts with ssh://' do - context 'when URI has port' do - it 'parses correctly' do - uri = described_class - .parse('ssh://git@qa.test:2222/sandbox/qa/repo.git') - - expect(uri.user).to eq('git') - expect(uri.host).to eq('qa.test') - expect(uri.port).to eq(2222) - expect(uri.path).to eq('/sandbox/qa/repo.git') - end - end - - context 'when URI does not have port' do - it 'parses correctly' do - uri = described_class - .parse('ssh://git@qa.test/sandbox/qa/repo.git') - - expect(uri.user).to eq('git') - expect(uri.host).to eq('qa.test') - expect(uri.port).to eq(22) - expect(uri.path).to eq('/sandbox/qa/repo.git') - end - end - end - - context 'when URI does not start with ssh://' do - context 'when host does not have colons' do - it 'parses correctly' do - uri = described_class - .parse('git@qa.test:sandbox/qa/repo.git') - - expect(uri.user).to eq('git') - expect(uri.host).to eq('qa.test') - expect(uri.port).to eq(22) - expect(uri.path).to eq('/sandbox/qa/repo.git') - end - end - - context 'when host has a colon' do - it 'parses correctly' do - uri = described_class - .parse('[git@qa:test]:sandbox/qa/repo.git') - - expect(uri.user).to eq('git') - expect(uri.host).to eq('qa%3Atest') - expect(uri.port).to eq(22) - expect(uri.path).to eq('/sandbox/qa/repo.git') - end - end - end - end -end -- cgit v1.2.3