This commit is contained in:
Lin Jen-Shin 2018-02-02 00:35:33 +08:00
parent f50835869c
commit 1264e2b6e8
10 changed files with 181 additions and 15 deletions

View File

@ -116,6 +116,10 @@ module QA
autoload :Show, 'qa/page/project/pipeline/show'
end
module Job
autoload :Show, 'qa/page/project/job/show'
end
module Settings
autoload :Common, 'qa/page/project/settings/common'
autoload :Advanced, 'qa/page/project/settings/advanced'

View File

@ -0,0 +1,8 @@
module QA
module Factory
module Resource
class Pipeline < Factory::Base
end
end
end
end

View File

@ -4,7 +4,7 @@ module QA
module Factory
module Resource
class Runner < Factory::Base
attr_writer :name, :tags
attr_writer :name, :tags, :image, :executor, :docker_image
dependency Factory::Resource::Project, as: :project do |project|
project.name = 'project-with-ci-cd'
@ -19,6 +19,18 @@ module QA
@tags || %w[qa e2e]
end
def image
@image || 'gitlab/gitlab-runner:alpine'
end
def executor
@executor || 'shell'
end
def docker_image
@docker_image || 'ubuntu/16.04'
end
def fabricate!
project.visit!
@ -31,6 +43,9 @@ module QA
runner.token = runners.registration_token
runner.address = runners.coordinator_address
runner.tags = tags
runner.image = image
runner.executor = executor
runner.docker_image = docker_image
runner.register!
end
end

View File

@ -0,0 +1,11 @@
module QA::Page
module Project::Job
class Show < QA::Page::Base
def output
css = '.js-build-output'
wait { has_css?(css) }
find(css).text
end
end
end
end

View File

@ -8,6 +8,12 @@ module QA::Page
def go_to_latest_pipeline
first('.js-pipeline-url-link').click
end
def wait_for_latest_pipeline
wait do
first('.js-pipeline-url-link')
end
end
end
end
end

View File

@ -30,6 +30,16 @@ module QA::Page
end
end
end
def go_to_first_job
css = '.js-pipeline-graph-job-link'
wait do
has_css?(css)
end
first(css).click
end
end
end
end

View File

@ -23,16 +23,11 @@ module QA
end
def choose_repository_clone_http
wait(reload: false) do
click_element :clone_dropdown
choose_repository_clone('HTTP')
end
page.within('.clone-options-dropdown') do
click_link('HTTP')
end
# Ensure git clone textbox was updated to http URI
page.has_css?('.git-clone-holder input#project_clone[value*="http"]')
end
def choose_repository_clone_ssh
choose_repository_clone('SSH')
end
def repository_location
@ -57,6 +52,22 @@ module QA
click_link 'New issue'
end
private
def choose_repository_clone(kind)
wait(reload: false) do
click_element :clone_dropdown
page.within('.clone-options-dropdown') do
click_link(kind)
end
# Ensure git clone textbox was updated to http URI
page.has_css?(
%Q{.git-clone-holder input#project_clone[value*="#{kind}"]})
end
end
end
end
end

View File

@ -7,7 +7,7 @@ module QA
extend Forwardable
attr_reader :key
def_delegators :@key, :fingerprint
def_delegators :@key, :fingerprint, :to_pem
def initialize(bits = 4096)
@key = OpenSSL::PKey::RSA.new(bits)

View File

@ -6,13 +6,15 @@ module QA
include Scenario::Actable
include Service::Shellout
attr_accessor :token, :address, :tags, :image
attr_accessor :token, :address, :tags, :image, :executor, :docker_image
def initialize(name)
@image = 'gitlab/gitlab-runner:alpine'
@name = name || "qa-runner-#{SecureRandom.hex(4)}"
@network = Runtime::Scenario.attributes[:network] || 'test'
@tags = %w[qa test]
@image = 'gitlab/gitlab-runner:alpine'
@executor = 'shell'
@docker_image = 'ubuntu/16.04'
end
def pull
@ -26,16 +28,32 @@ module QA
-e CI_SERVER_URL=#{@address}
-e REGISTER_NON_INTERACTIVE=true
-e REGISTRATION_TOKEN=#{@token}
-e RUNNER_EXECUTOR=shell
-e RUNNER_EXECUTOR=#{@executor}
-e DOCKER_IMAGE=#{@docker_image}
-e RUNNER_TAG_LIST=#{@tags.join(',')}
-e RUNNER_NAME=#{@name}
#{@image} -c 'gitlab-runner register && gitlab-runner run'
#{@image} -c '#{docker_commands}'
CMD
end
def remove!
shell "docker rm -f #{@name}"
end
private
def docker_commands
commands = [
'gitlab-runner register',
'gitlab-runner run'
]
if @executor == 'docker'
commands.unshift('apt-get install -y docker-ce')
end
commands.join(' && ')
end
end
end
end

View File

@ -0,0 +1,83 @@
module QA
feature 'pull codes with a deploy key', :core, :docker do
let(:runner_name) { "qa-runner-#{Time.now.to_i}" }
after do
Service::Runner.new(runner_name).remove!
end
scenario 'user pushes .gitlab-ci.yml to the repository' do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials }
project = Factory::Resource::Project.fabricate! do |resource|
resource.name = 'cicd-pull-with-deploy-key'
end
Factory::Resource::Runner.fabricate! do |runner|
runner.project = project
runner.name = runner_name
runner.tags = %w[qa docker]
runner.executor = 'shell'
runner.image = 'gitlab/gitlab-runner:ubuntu'
end
key = Runtime::RSAKey.new
Factory::Resource::DeployKey.fabricate! do |resource|
resource.project = project
resource.title = 'deploy key title'
resource.key = key.public_key
end
Factory::Resource::SecretVariable.fabricate! do |resource|
resource.project = project
resource.key = 'DEPLOY_KEY'
resource.value = key.to_pem
end
project.visit!
repository_url = Page::Project::Show.act do
choose_repository_clone_ssh
repository_location
end
gitlab_ci =
<<~YAML
cat-config:
script:
- eval $(ssh-agent -s)
- echo "$DEPLOY_KEY" | tr -d '\\r' | ssh-add - > /dev/null
- git clone #{repository_url}
- cat #{project.name}/.gitlab-ci.yml
tags:
- qa
- docker
YAML
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
end
Page::Project::Show.act { wait_for_push }
Page::Menu::Side.act { click_ci_cd_pipelines }
Page::Project::Pipeline::Index.act do
wait_for_latest_pipeline
go_to_latest_pipeline
end
Page::Project::Pipeline::Show.act do
go_to_first_job
end
Page::Project::Job::Show.perform do |job|
expect(job.output).to include(gitlab_ci.tr("\n", ' '))
end
end
end
end