Reduce nesting and simplify CI/CD end-to-end tests

This commit is contained in:
Grzegorz Bizon 2018-01-22 15:18:19 +01:00
parent ca4db9d25f
commit 5520e3ebc3
4 changed files with 56 additions and 24 deletions

View file

@ -15,36 +15,21 @@ module QA
@name || "qa-runner-#{SecureRandom.hex(4)}" @name || "qa-runner-#{SecureRandom.hex(4)}"
end end
def perform(&block)
@block ||= block
end
def fabricate! def fabricate!
project.visit! project.visit!
Page::Menu::Side.act { click_ci_cd_settings } Page::Menu::Side.act { click_ci_cd_settings }
Service::Runner.perform do |runner| Service::Runner.new(name).tap do |runner|
Page::Project::Settings::CICD.perform do |settings| Page::Project::Settings::CICD.perform do |settings|
settings.expand_runners_settings do |runners| settings.expand_runners_settings do |runners|
runner.pull runner.pull
runner.name = name
runner.token = runners.registration_token runner.token = runners.registration_token
runner.address = runners.coordinator_address runner.address = runners.coordinator_address
runner.tags = %w[qa test] runner.tags = %w[qa test]
runner.register! runner.register!
end # TODO, wait for runner to register using non-blocking method.
##
# TODO, refactor to support non-blocking wait time until
# GitLab Runner sucessfully registers itself.
#
sleep 5 sleep 5
settings.refresh
settings.expand_runners_settings do |runners|
perform&.call(runners, runner)
runner.remove!
end end
end end
end end

View file

@ -6,11 +6,11 @@ module QA
include Scenario::Actable include Scenario::Actable
include Service::Shellout include Service::Shellout
attr_accessor :token, :address, :tags, :image, :name attr_accessor :token, :address, :tags, :image
def initialize def initialize(name)
@image = 'gitlab/gitlab-runner:alpine' @image = 'gitlab/gitlab-runner:alpine'
@name = "qa-runner-#{SecureRandom.hex(4)}" @name = name || "qa-runner-#{SecureRandom.hex(4)}"
end end
def pull def pull

View file

@ -1,15 +1,63 @@
module QA module QA
feature 'CI/CD Pipelines', :core, :docker do feature 'CI/CD Pipelines', :core, :docker do
let(:executor) { "qa-runner-#{Time.now.to_i}" }
after do
Service::Runner.new(executor).remove!
end
scenario 'user registers a new specific runner' do scenario 'user registers a new specific runner' do
Runtime::Browser.visit(:gitlab, Page::Main::Login) Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials } Page::Main::Login.act { sign_in_using_credentials }
Factory::Resource::Runner.fabricate! do |runner| Factory::Resource::Runner.fabricate! do |runner|
runner.perform do |page, runner| runner.name = executor
expect(page).to have_content(runner.name) end
Page::Project::Settings::CICD.perform do |settings|
settings.expand_runners_settings do |page|
expect(page).to have_content(runner)
expect(page).to have_online_runner expect(page).to have_online_runner
end end
end end
end end
scenario 'users creates a new pipeline' do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials }
project = Factory::Resource::Project.fabricate! do |project|
project.name = 'project-with-pipelines'
project.description = 'Project with CI/CD Pipelines.'
end
Factory::Resource::Runner.fabricate! do |runner|
runner.project = project
runner.name = executor
end
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 = <<~EOF
echo-success-test:
script: echo 'OK'
echo-failure-test:
script:
- echo 'FAILURE'
- exit 1
echo-artifacts-test:
script: echo "CONTENTS" > my-artifacts/artifact.txt
artifacts:
paths:
- my-artifacts/
EOF
end
Page::Project::Show.act { wait_for_push }
end
end end
end end

View file

@ -19,7 +19,6 @@ describe QA::Factory::Base do
it 'returns fabrication product' do it 'returns fabrication product' do
allow(subject).to receive(:new).and_return(factory) allow(subject).to receive(:new).and_return(factory)
allow(factory).to receive(:fabricate!).and_return('something')
result = subject.fabricate!('something') result = subject.fabricate!('something')