diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-01-22 14:03:03 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-01-22 14:03:03 +0100 |
commit | 50a82f64e53d396ca91f52c4d25af60beb52a424 (patch) | |
tree | d56e2ea17f7d9cfbd2a07c220f8ec900a411853a | |
parent | d0b08f1c50b0b4106c0ae5f398912aab596a447a (diff) | |
download | gitlab-ce-50a82f64e53d396ca91f52c4d25af60beb52a424.tar.gz |
Add end-to-end test for registering GitLab Runner
-rw-r--r-- | qa/qa.rb | 5 | ||||
-rw-r--r-- | qa/qa/factory/resource/deploy_key.rb | 2 | ||||
-rw-r--r-- | qa/qa/factory/resource/runner.rb | 52 | ||||
-rw-r--r-- | qa/qa/page/menu/side.rb | 25 | ||||
-rw-r--r-- | qa/qa/page/project/settings/ci_cd.rb | 21 | ||||
-rw-r--r-- | qa/qa/page/project/settings/common.rb | 10 | ||||
-rw-r--r-- | qa/qa/page/project/settings/runners.rb | 19 | ||||
-rw-r--r-- | qa/qa/service/runner.rb | 31 | ||||
-rw-r--r-- | qa/qa/specs/features/project/pipelines_spec.rb | 17 |
9 files changed, 166 insertions, 16 deletions
@@ -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 diff --git a/qa/qa/factory/resource/deploy_key.rb b/qa/qa/factory/resource/deploy_key.rb index 7c58e70bcc4..d51701e65ea 100644 --- a/qa/qa/factory/resource/deploy_key.rb +++ b/qa/qa/factory/resource/deploy_key.rb @@ -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| diff --git a/qa/qa/factory/resource/runner.rb b/qa/qa/factory/resource/runner.rb new file mode 100644 index 00000000000..037136dd113 --- /dev/null +++ b/qa/qa/factory/resource/runner.rb @@ -0,0 +1,52 @@ +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 diff --git a/qa/qa/page/menu/side.rb b/qa/qa/page/menu/side.rb index 1df4e0c2429..e666d570172 100644 --- a/qa/qa/page/menu/side.rb +++ b/qa/qa/page/menu/side.rb @@ -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 diff --git a/qa/qa/page/project/settings/ci_cd.rb b/qa/qa/page/project/settings/ci_cd.rb new file mode 100644 index 00000000000..5270dde7411 --- /dev/null +++ b/qa/qa/page/project/settings/ci_cd.rb @@ -0,0 +1,21 @@ +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 diff --git a/qa/qa/page/project/settings/common.rb b/qa/qa/page/project/settings/common.rb index b4ef07e1540..1357bf031d5 100644 --- a/qa/qa/page/project/settings/common.rb +++ b/qa/qa/page/project/settings/common.rb @@ -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 diff --git a/qa/qa/page/project/settings/runners.rb b/qa/qa/page/project/settings/runners.rb new file mode 100644 index 00000000000..ba3dc632c59 --- /dev/null +++ b/qa/qa/page/project/settings/runners.rb @@ -0,0 +1,19 @@ +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 diff --git a/qa/qa/service/runner.rb b/qa/qa/service/runner.rb index a6a60f53787..a9906b8627a 100644 --- a/qa/qa/service/runner.rb +++ b/qa/qa/service/runner.rb @@ -1,27 +1,38 @@ +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 diff --git a/qa/qa/specs/features/project/pipelines_spec.rb b/qa/qa/specs/features/project/pipelines_spec.rb new file mode 100644 index 00000000000..1897b2fa27c --- /dev/null +++ b/qa/qa/specs/features/project/pipelines_spec.rb @@ -0,0 +1,17 @@ +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 |