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)}"
end
def perform(&block)
@block ||= block
end
def fabricate!
project.visit!
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|
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
##
# TODO, refactor to support non-blocking wait time until
# GitLab Runner sucessfully registers itself.
#
sleep 5
settings.refresh
settings.expand_runners_settings do |runners|
perform&.call(runners, runner)
runner.remove!
# TODO, wait for runner to register using non-blocking method.
sleep 5
end
end
end

View File

@ -6,11 +6,11 @@ module QA
include Scenario::Actable
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'
@name = "qa-runner-#{SecureRandom.hex(4)}"
@name = name || "qa-runner-#{SecureRandom.hex(4)}"
end
def pull

View File

@ -1,15 +1,63 @@
module QA
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
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials }
Factory::Resource::Runner.fabricate! do |runner|
runner.perform do |page, runner|
expect(page).to have_content(runner.name)
runner.name = executor
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
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

View File

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