Commit 50a82f64 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add end-to-end test for registering GitLab Runner

parent d0b08f1c
......@@ -26,6 +26,7 @@ module QA
autoload :Group, 'qa/factory/resource/group'
autoload :Project, 'qa/factory/resource/project'
autoload :DeployKey, 'qa/factory/resource/deploy_key'
autoload :Runner, 'qa/factory/resource/runner'
end
module Repository
......@@ -104,7 +105,9 @@ module QA
module Settings
autoload :Common, 'qa/page/project/settings/common'
autoload :Repository, 'qa/page/project/settings/repository'
autoload :CICD, 'qa/page/project/settings/ci_cd'
autoload :DeployKeys, 'qa/page/project/settings/deploy_keys'
autoload :Runners, 'qa/page/project/settings/runners'
end
end
......@@ -130,7 +133,7 @@ module QA
# with these services, like through the shell.
#
module Service
autoload :Shellable, 'qa/service/shellable'
autoload :Shellout, 'qa/service/shellout'
autoload :Omnibus, 'qa/service/omnibus'
autoload :Runner, 'qa/service/runner'
end
......
......@@ -13,7 +13,7 @@ module QA
project.visit!
Page::Menu::Side.act do
click_repository_setting
click_repository_settings
end
Page::Project::Settings::Repository.perform do |setting|
......
require 'securerandom'
module QA
module Factory
module Resource
class Runner < Factory::Base
attr_writer :name
dependency Factory::Resource::Project, as: :project do |project|
project.name = 'project-with-ci-cd'
project.description = 'Project with CI/CD Pipelines'
end
def name
@name || "qa-runner-#{SecureRandom.hex(4)}"
end
def perform(&block)
@block ||= block
end
def fabricate!
project.visit!
Page::Menu::Side.act { click_ci_cd_settings }
Service::Runner.perform do |runner|
Page::Project::Settings::CICD.perform do |settings|
settings.expand_runners_settings do |runners|
runner.pull
runner.name = name
runner.token = runners.registration_token
runner.address = runners.coordinator_address
runner.tags = %w[qa test]
runner.register!
end
sleep 5 # TODO, non-blocking waiting for Runner to register.
settings.refresh
settings.expand_runners_settings do |runners|
perform&.call(runners)
runner.remove!
end
end
end
end
end
end
end
end
......@@ -5,18 +5,29 @@ module QA
view 'app/views/layouts/nav/sidebar/_project.html.haml' do
element :settings_item
element :repository_link, "title: 'Repository'"
element :repository_link, "title: 'CI / CD'"
element :top_level_items, '.sidebar-top-level-items'
end
def click_repository_setting
hover_setting do
click_link('Repository')
def click_repository_settings
hover_settings do
within_submenu do
click_link('Repository')
end
end
end
def click_ci_cd_settings
hover_settings do
within_submenu do
click_link('CI / CD')
end
end
end
private
def hover_setting
def hover_settings
within_sidebar do
find('.qa-settings-item').hover
......@@ -29,6 +40,12 @@ module QA
yield
end
end
def within_submenu
page.within('.fly-out-list') do
yield
end
end
end
end
end
......
module QA
module Page
module Project
module Settings
class CICD < Page::Base
include Common
view 'app/views/projects/settings/ci_cd/show.html.haml' do
element :runners_settings, 'Runners settings'
end
def expand_runners_settings(&block)
expand_section('Runners settings') do
Settings::Runners.perform(&block)
end
end
end
end
end
end
end
......@@ -10,6 +10,16 @@ module QA
yield
end
end
def expand_section(name)
page.within('#content-body') do
page.within('section', text: name) do
click_button 'Expand'
yield
end
end
end
end
end
end
......
module QA
module Page
module Project
module Settings
class Runners < Page::Base
def registration_token
find('code#registration_token').text
end
def coordinator_address
# TODO, this needs a specific ID or QA class
#
all('code').first.text
end
end
end
end
end
end
require 'securerandom'
module QA
module Service
class Runner
include Scenario::Actable
include Service::Shellout
def initialize(image)
@image = image
attr_writer :token, :address, :tags, :image, :name
def initialize
@image = 'gitlab/gitlab-runner:alpine'
@name = "gitlab-runner-qa-#{SecureRandom.hex(4)}"
end
def pull
shell "docker pull #{@image}"
end
def register(token)
raise NotImplementedError
end
def run
raise NotImplementedError
def register!
shell <<~CMD.tr("\n", ' ')
docker run -d --rm --entrypoint=/bin/sh
--network test --name #{@name}
-e CI_SERVER_URL=#{@address}
-e REGISTER_NON_INTERACTIVE=true
-e REGISTRATION_TOKEN=#{@token}
-e RUNNER_EXECUTOR=shell
-e RUNNER_TAG_LIST=#{@tags.to_a.join(',')}
-e RUNNER_NAME=#{@name}
#{@image} -c 'gitlab-runner register && gitlab-runner run'
CMD
end
def remove
raise NotImplementedError
def remove!
shell "docker rm -f #{@name}"
end
end
end
......
module QA
feature 'CI/CD Pipelines', :core, :docker do
scenario 'user registers a new specific runner' do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials }
Factory::Resource::Runner.fabricate! do |runner|
runner.name = 'my-qa-runner'
runner.perform do |page|
expect(page).to have_content('my-qa-runner')
expect(page).to have_css('.runner-status-online')
end
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