1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_category: :continuous_integration do
include StubGitlabCalls
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, shared_runners_enabled: false) }
let_it_be(:runner) { create(:ci_runner, :project, projects: [project]) }
let(:user_agent) { 'gitlab-runner 9.0.0 (9-0-stable; go1.7.4; linux/amd64)' }
before_all do
project.add_maintainer(user)
end
Dir[Rails.root.join("spec/requests/api/ci/runner/yamls/*.yml")].each do |yml_file|
context "for #{File.basename(yml_file)}" do
let(:yaml_content) { YAML.load_file(yml_file) }
let(:gitlab_ci_yml) { yaml_content.fetch("gitlab_ci") }
let(:request_response) { yaml_content.fetch("request_response") }
it 'runs a job' do
stub_ci_pipeline_yaml_file(YAML.dump(gitlab_ci_yml))
pipeline_response = create_pipeline!
expect(pipeline_response).to be_success, pipeline_response.message
expect(pipeline_response.payload).to be_created_successfully
expect(pipeline_response.payload.builds).to be_one
build = pipeline_response.payload.builds.first
process_pipeline!(pipeline_response.payload)
expect(build.reload).to be_pending
request_job(runner.token)
expect(response).to have_gitlab_http_status(:created)
expect(response.headers['Content-Type']).to eq('application/json')
expect(json_response).to include('id' => build.id, 'token' => build.token)
expect(json_response).to include(request_response)
end
end
end
def create_pipeline!
params = { ref: 'master',
before: '00000000',
after: project.commit.id,
commits: [{ message: 'some commit' }] }
Ci::CreatePipelineService.new(project, user, params).execute(:push)
end
def process_pipeline!(pipeline)
PipelineProcessWorker.new.perform(pipeline.id)
end
def request_job(token, **params)
new_params = params.merge(token: token)
post api('/jobs/request'), params: new_params.to_json,
headers: { 'User-Agent' => user_agent, 'Content-Type': 'application/json' }
end
end
|