diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2018-02-12 23:25:18 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2018-02-12 23:49:09 +0800 |
commit | 565fdd63cf49c266c7a6a2a0d2a843339a9d30e6 (patch) | |
tree | 3567619e22cdf16df541c67aaf6f7809d8f4e14b /qa | |
parent | 2f34ef34fa230c1954e47504cd8ead1a6ab019fe (diff) | |
download | gitlab-ce-565fdd63cf49c266c7a6a2a0d2a843339a9d30e6.tar.gz |
Rearrange the test structure and introduce
a new repository location class.
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa/git/repository.rb | 15 | ||||
-rw-r--r-- | qa/qa/git/repository/location.rb | 41 | ||||
-rw-r--r-- | qa/qa/page/project/show.rb | 4 | ||||
-rw-r--r-- | qa/qa/specs/features/project/deploy_key_clone_spec.rb | 79 | ||||
-rw-r--r-- | qa/spec/git/repository/location_spec.rb (renamed from qa/spec/git/repository_spec.rb) | 15 |
5 files changed, 103 insertions, 51 deletions
diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb index 606fc66b4d5..903d292b69c 100644 --- a/qa/qa/git/repository.rb +++ b/qa/qa/git/repository.rb @@ -4,20 +4,9 @@ require 'uri' module QA module Git class Repository - include Scenario::Actable + autoload :Location, 'qa/git/repository/location' - # See: config/initializers/1_settings.rb - # Settings#build_gitlab_shell_ssh_path_prefix - def self.parse_uri(git_uri) - if git_uri.start_with?('ssh://') - 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') - URI.parse("ssh://#{user_host}/#{path}") - end - end + include Scenario::Actable def self.perform(*args) Dir.mktmpdir do |dir| diff --git a/qa/qa/git/repository/location.rb b/qa/qa/git/repository/location.rb new file mode 100644 index 00000000000..dce8327ce82 --- /dev/null +++ b/qa/qa/git/repository/location.rb @@ -0,0 +1,41 @@ +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/qa/page/project/show.rb b/qa/qa/page/project/show.rb index 93fcfe6d5e5..834a36c4bd0 100644 --- a/qa/qa/page/project/show.rb +++ b/qa/qa/page/project/show.rb @@ -33,6 +33,10 @@ module QA find('#project_clone').value end + def repository_location_uri + Git::Repository::Location.parse(repository_location) + end + def project_name find('.qa-project-name').text end diff --git a/qa/qa/specs/features/project/deploy_key_clone_spec.rb b/qa/qa/specs/features/project/deploy_key_clone_spec.rb index 297e677175f..9b4897a1f96 100644 --- a/qa/qa/specs/features/project/deploy_key_clone_spec.rb +++ b/qa/qa/specs/features/project/deploy_key_clone_spec.rb @@ -3,71 +3,86 @@ require 'digest/sha1' module QA feature 'cloning code using a deploy key', :core, :docker do let(:runner_name) { "qa-runner-#{Time.now.to_i}" } + let(:key) { Runtime::RSAKey.new } - after do - Service::Runner.new(runner_name).remove! - end - - scenario 'user sets up a deploy key to clone code using pipelines' do - Runtime::Browser.visit(:gitlab, Page::Main::Login) - Page::Main::Login.act { sign_in_using_credentials } - - project = Factory::Resource::Project.fabricate! do |resource| + given(:project) do + Factory::Resource::Project.fabricate! do |resource| resource.name = 'deploy-key-clone-project' end + end - Factory::Resource::Runner.fabricate! do |runner| - runner.project = project - runner.name = runner_name - runner.tags = %w[qa docker] - runner.image = 'gitlab/gitlab-runner:ubuntu' + def fabricate_runner + Factory::Resource::Runner.fabricate! do |resource| + resource.project = project + resource.name = runner_name + resource.tags = %w[qa docker] + resource.image = 'gitlab/gitlab-runner:ubuntu' end + end - key = Runtime::RSAKey.new - + def fabricate_deploy_key Factory::Resource::DeployKey.fabricate! do |resource| resource.project = project resource.title = 'deploy key title' resource.key = key.public_key end + end + def fabricate_secret_variable Factory::Resource::SecretVariable.fabricate! do |resource| resource.project = project resource.key = 'DEPLOY_KEY' resource.value = key.to_pem end + end - project.visit! - - repository_url = Page::Project::Show.act do + def fabricate_gitlab_ci + repository_uri = Page::Project::Show.act do choose_repository_clone_ssh - repository_location + repository_location_uri end - repository_uri = Git::Repository.parse_uri(repository_url) - - gitlab_ci = <<~YAML + <<~YAML cat-config: script: - mkdir -p ~/.ssh - - ssh-keyscan -p #{repository_uri.port || 22} #{repository_uri.host} >> ~/.ssh/known_hosts + - ssh-keyscan -p #{repository_uri.port} #{repository_uri.host} >> ~/.ssh/known_hosts - eval $(ssh-agent -s) - echo "$DEPLOY_KEY" | ssh-add - - - git clone #{repository_url} + - git clone #{repository_uri.git_uri} - sha1sum #{project.name}/.gitlab-ci.yml tags: - qa - docker YAML + end - sha1sum = Digest::SHA1.hexdigest(gitlab_ci) - - Factory::Repository::Push.fabricate! do |push| - push.project = project - push.file_name = '.gitlab-ci.yml' - push.commit_message = 'Add .gitlab-ci.yml' - push.file_content = gitlab_ci + def fabricate_push(gitlab_ci) + Factory::Repository::Push.fabricate! do |resource| + resource.project = project + resource.file_name = '.gitlab-ci.yml' + resource.commit_message = 'Add .gitlab-ci.yml' + resource.file_content = gitlab_ci end + end + + after do + Service::Runner.new(runner_name).remove! + end + + scenario 'user sets up a deploy key to clone code using pipelines' do + Runtime::Browser.visit(:gitlab, Page::Main::Login) + Page::Main::Login.act { sign_in_using_credentials } + + fabricate_runner + fabricate_deploy_key + fabricate_secret_variable + + project.visit! + + gitlab_ci = fabricate_gitlab_ci + fabricate_push(gitlab_ci) + sha1sum = Digest::SHA1.hexdigest(gitlab_ci) Page::Project::Show.act { wait_for_push } Page::Menu::Side.act { click_ci_cd_pipelines } diff --git a/qa/spec/git/repository_spec.rb b/qa/spec/git/repository/location_spec.rb index ae58355d199..c1fe01becd7 100644 --- a/qa/spec/git/repository_spec.rb +++ b/qa/spec/git/repository/location_spec.rb @@ -1,10 +1,10 @@ -describe QA::Git::Repository do - describe '.parse_uri' do +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_uri('ssh://git@qa.test:2222/sandbox/qa/repo.git') + .parse('ssh://git@qa.test:2222/sandbox/qa/repo.git') expect(uri.user).to eq('git') expect(uri.host).to eq('qa.test') @@ -16,10 +16,11 @@ describe QA::Git::Repository do context 'when URI does not have port' do it 'parses correctly' do uri = described_class - .parse_uri('ssh://git@qa.test/sandbox/qa/repo.git') + .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 @@ -29,10 +30,11 @@ describe QA::Git::Repository do context 'when host does not have colons' do it 'parses correctly' do uri = described_class - .parse_uri('git@qa.test:sandbox/qa/repo.git') + .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 @@ -40,10 +42,11 @@ describe QA::Git::Repository do context 'when host has a colon' do it 'parses correctly' do uri = described_class - .parse_uri('[git@qa:test]:sandbox/qa/repo.git') + .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 |