Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2017-02-16 03:05:44 +0300
committerTomasz Maczukin <tomasz@maczukin.pl>2017-03-02 19:45:45 +0300
commit3eafffcef0f8932bab4e06b465f9b63327e87942 (patch)
treecdb64b4be94007d4b8d0ce380862f21a027267fa /spec
parent3d26a8d0b62f70e02917f7601bc2032fb3aed7e6 (diff)
Refactor JobRequest response structure
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/ci/builds.rb26
-rw-r--r--spec/requests/api/runner_spec.rb51
-rw-r--r--spec/services/ci/register_job_service_spec.rb (renamed from spec/services/ci/register_build_service_spec.rb)2
3 files changed, 66 insertions, 13 deletions
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb
index a90534d10ba..a77b3356b9a 100644
--- a/spec/factories/ci/builds.rb
+++ b/spec/factories/ci/builds.rb
@@ -15,8 +15,8 @@ FactoryGirl.define do
options do
{
- image: "ruby:2.1",
- services: ["postgres"]
+ image: 'ruby:2.1',
+ services: ['postgres']
}
end
@@ -151,5 +151,27 @@ FactoryGirl.define do
allow(build).to receive(:commit).and_return build(:commit)
end
end
+
+ trait :extended_options do
+ options do
+ {
+ image: 'ruby:2.1',
+ services: ['postgres'],
+ after_script: "ls\ndate",
+ artifacts: {
+ name: 'artifacts_file',
+ untracked: false,
+ paths: ['out/'],
+ when: 'always',
+ expire_in: '7d'
+ },
+ cache: {
+ key: 'cache_key',
+ untracked: false,
+ paths: ['vendor/*']
+ }
+ }
+ end
+ end
end
end
diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb
index 3b94be55974..bd9dc422703 100644
--- a/spec/requests/api/runner_spec.rb
+++ b/spec/requests/api/runner_spec.rb
@@ -152,8 +152,8 @@ describe API::Runner do
describe '/api/v4/jobs' do
let(:project) { create(:empty_project, shared_runners_enabled: false) }
let(:pipeline) { create(:ci_pipeline_without_jobs, project: project, ref: 'master') }
- let!(:job) { create(:ci_build, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) }
let(:runner) { create(:ci_runner) }
+ let!(:job) { create(:ci_build, :artifacts, :extended_options, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0, commands: "ls\ndate") }
before { project.runners << runner }
@@ -271,14 +271,44 @@ describe API::Runner do
expect(response).to have_http_status(201)
expect(response.headers).not_to have_key('X-GitLab-Last-Update')
- expect(json_response['sha']).to eq(job.sha)
- expect(json_response['options']).to eq({'image' => 'ruby:2.1', 'services' => ['postgres']})
- expect(json_response['variables']).to include(
- {'key' => 'CI_BUILD_NAME', 'value' => 'spinach', 'public' => true},
- {'key' => 'CI_BUILD_STAGE', 'value' => 'test', 'public' => true},
- {'key' => 'DB_NAME', 'value' => 'postgres', 'public' => true}
- )
expect(runner.reload.platform).to eq('darwin')
+
+ expect(json_response['id']).to eq(job.id)
+ expect(json_response['token']).to eq(job.token)
+ expect(json_response['job_info']).to include({ 'name' => job.name },
+ { 'stage' => job.stage })
+ expect(json_response['git_info']).to include({ 'sha' => job.sha },
+ { 'repo_url' => job.repo_url })
+ expect(json_response['image']).to include({ 'name' => 'ruby:2.1' })
+ expect(json_response['services']).to include({ 'name' => 'postgres' })
+ expect(json_response['steps']).to include({ 'name' => 'after_script',
+ 'script' => ['ls', 'date'],
+ 'timeout' => job.timeout,
+ 'condition' => Gitlab::Ci::Build::Response::Step::CONDITION_ALWAYS,
+ 'result' => Gitlab::Ci::Build::Response::Step::RESULT_DOESNT_FAIL_JOB })
+ expect(json_response['variables']).to include({ 'key' => 'CI_BUILD_NAME', 'value' => 'spinach', 'public' => true },
+ { 'key' => 'CI_BUILD_STAGE', 'value' => 'test', 'public' => true },
+ { 'key' => 'DB_NAME', 'value' => 'postgres', 'public' => true })
+ expect(json_response['artifacts']).to include({ 'name' => 'artifacts_file' },
+ { 'paths' => ['out/'] })
+ end
+
+ context 'when job is made for tag' do
+ let!(:job) { create(:ci_build_tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) }
+
+ it 'sets branch as ref_type' do
+ request_job
+ expect(response).to have_http_status(201)
+ expect(json_response['git_info']['ref_type']).to eq('tag')
+ end
+ end
+
+ context 'when job is made for branch' do
+ it 'sets tag as ref_type' do
+ request_job
+ expect(response).to have_http_status(201)
+ expect(json_response['git_info']['ref_type']).to eq('branch')
+ end
end
it 'updates runner info' do
@@ -322,8 +352,8 @@ describe API::Runner do
expect(response).to have_http_status(201)
expect(json_response['id']).to eq(test_job.id)
- expect(json_response['depends_on_builds'].count).to eq(1)
- expect(json_response['depends_on_builds'][0]).to include('id' => job.id, 'name' => 'spinach')
+ expect(json_response['dependencies'].count).to eq(1)
+ expect(json_response['dependencies'][0]).to include('id' => job.id, 'name' => 'spinach')
end
end
@@ -381,6 +411,7 @@ describe API::Runner do
it 'sends registry credentials key' do
request_job
+
expect(json_response).to have_key('credentials')
expect(json_response['credentials']).to include(registry_credentials)
end
diff --git a/spec/services/ci/register_build_service_spec.rb b/spec/services/ci/register_job_service_spec.rb
index cd7dd53025c..ea8b996d481 100644
--- a/spec/services/ci/register_build_service_spec.rb
+++ b/spec/services/ci/register_job_service_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
module Ci
- describe RegisterBuildService, services: true do
+ describe RegisterJobService, services: true do
let!(:project) { FactoryGirl.create :empty_project, shared_runners_enabled: false }
let!(:pipeline) { FactoryGirl.create :ci_pipeline, project: project }
let!(:pending_build) { FactoryGirl.create :ci_build, pipeline: pipeline }