Commit 1264e2b6 authored by Lin Jen-Shin's avatar Lin Jen-Shin

WIP

parent f5083586
...@@ -116,6 +116,10 @@ module QA ...@@ -116,6 +116,10 @@ module QA
autoload :Show, 'qa/page/project/pipeline/show' autoload :Show, 'qa/page/project/pipeline/show'
end end
module Job
autoload :Show, 'qa/page/project/job/show'
end
module Settings module Settings
autoload :Common, 'qa/page/project/settings/common' autoload :Common, 'qa/page/project/settings/common'
autoload :Advanced, 'qa/page/project/settings/advanced' autoload :Advanced, 'qa/page/project/settings/advanced'
......
module QA
module Factory
module Resource
class Pipeline < Factory::Base
end
end
end
end
...@@ -4,7 +4,7 @@ module QA ...@@ -4,7 +4,7 @@ module QA
module Factory module Factory
module Resource module Resource
class Runner < Factory::Base class Runner < Factory::Base
attr_writer :name, :tags attr_writer :name, :tags, :image, :executor, :docker_image
dependency Factory::Resource::Project, as: :project do |project| dependency Factory::Resource::Project, as: :project do |project|
project.name = 'project-with-ci-cd' project.name = 'project-with-ci-cd'
...@@ -19,6 +19,18 @@ module QA ...@@ -19,6 +19,18 @@ module QA
@tags || %w[qa e2e] @tags || %w[qa e2e]
end 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! def fabricate!
project.visit! project.visit!
...@@ -31,6 +43,9 @@ module QA ...@@ -31,6 +43,9 @@ module QA
runner.token = runners.registration_token runner.token = runners.registration_token
runner.address = runners.coordinator_address runner.address = runners.coordinator_address
runner.tags = tags runner.tags = tags
runner.image = image
runner.executor = executor
runner.docker_image = docker_image
runner.register! runner.register!
end end
end end
......
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
...@@ -8,6 +8,12 @@ module QA::Page ...@@ -8,6 +8,12 @@ module QA::Page
def go_to_latest_pipeline def go_to_latest_pipeline
first('.js-pipeline-url-link').click first('.js-pipeline-url-link').click
end end
def wait_for_latest_pipeline
wait do
first('.js-pipeline-url-link')
end
end
end end
end end
end end
...@@ -30,6 +30,16 @@ module QA::Page ...@@ -30,6 +30,16 @@ module QA::Page
end end
end 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 end
end end
...@@ -23,16 +23,11 @@ module QA ...@@ -23,16 +23,11 @@ module QA
end end
def choose_repository_clone_http def choose_repository_clone_http
wait(reload: false) do choose_repository_clone('HTTP')
click_element :clone_dropdown
page.within('.clone-options-dropdown') do
click_link('HTTP')
end end
# Ensure git clone textbox was updated to http URI def choose_repository_clone_ssh
page.has_css?('.git-clone-holder input#project_clone[value*="http"]') choose_repository_clone('SSH')
end
end end
def repository_location def repository_location
...@@ -57,6 +52,22 @@ module QA ...@@ -57,6 +52,22 @@ module QA
click_link 'New issue' click_link 'New issue'
end 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 end
end end
......
...@@ -7,7 +7,7 @@ module QA ...@@ -7,7 +7,7 @@ module QA
extend Forwardable extend Forwardable
attr_reader :key attr_reader :key
def_delegators :@key, :fingerprint def_delegators :@key, :fingerprint, :to_pem
def initialize(bits = 4096) def initialize(bits = 4096)
@key = OpenSSL::PKey::RSA.new(bits) @key = OpenSSL::PKey::RSA.new(bits)
......
...@@ -6,13 +6,15 @@ module QA ...@@ -6,13 +6,15 @@ module QA
include Scenario::Actable include Scenario::Actable
include Service::Shellout include Service::Shellout
attr_accessor :token, :address, :tags, :image attr_accessor :token, :address, :tags, :image, :executor, :docker_image
def initialize(name) def initialize(name)
@image = 'gitlab/gitlab-runner:alpine'
@name = name || "qa-runner-#{SecureRandom.hex(4)}" @name = name || "qa-runner-#{SecureRandom.hex(4)}"
@network = Runtime::Scenario.attributes[:network] || 'test' @network = Runtime::Scenario.attributes[:network] || 'test'
@tags = %w[qa test] @tags = %w[qa test]
@image = 'gitlab/gitlab-runner:alpine'
@executor = 'shell'
@docker_image = 'ubuntu/16.04'
end end
def pull def pull
...@@ -26,16 +28,32 @@ module QA ...@@ -26,16 +28,32 @@ module QA
-e CI_SERVER_URL=#{@address} -e CI_SERVER_URL=#{@address}
-e REGISTER_NON_INTERACTIVE=true -e REGISTER_NON_INTERACTIVE=true
-e REGISTRATION_TOKEN=#{@token} -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_TAG_LIST=#{@tags.join(',')}
-e RUNNER_NAME=#{@name} -e RUNNER_NAME=#{@name}
#{@image} -c 'gitlab-runner register && gitlab-runner run' #{@image} -c '#{docker_commands}'
CMD CMD
end end
def remove! def remove!
shell "docker rm -f #{@name}" shell "docker rm -f #{@name}"
end 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 end
end end
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment