Add build specs

This commit is contained in:
Matija Čupić 2018-10-27 18:04:09 +02:00
parent 72430483de
commit c2d49565cf
No known key found for this signature in database
GPG key ID: 4BAF84FFACD2E5DE
2 changed files with 50 additions and 2 deletions

View file

@ -801,8 +801,8 @@ module Ci
variables.append(key: "CI_COMMIT_TAG", value: ref) if tag?
variables.append(key: "CI_PIPELINE_TRIGGERED", value: 'true') if trigger_request
variables.append(key: "CI_JOB_MANUAL", value: 'true') if action?
variables.append(key: "CI_NODE_INDEX", value: node_index.to_s) if self.options[:parallel]
variables.append(key: "CI_NODE_TOTAL", value: self.options.fetch(:parallel, 1).to_s)
variables.append(key: "CI_NODE_INDEX", value: node_index.to_s) if self.options&.include?(:parallel)
variables.append(key: "CI_NODE_TOTAL", value: (self.options&.dig(:parallel) || 1).to_s)
variables.concat(legacy_variables)
end
end

View file

@ -1880,6 +1880,7 @@ describe Ci::Build do
{ key: 'CI_COMMIT_BEFORE_SHA', value: build.before_sha, public: true },
{ key: 'CI_COMMIT_REF_NAME', value: build.ref, public: true },
{ key: 'CI_COMMIT_REF_SLUG', value: build.ref_slug, public: true },
{ key: 'CI_NODE_TOTAL', value: '1', public: true },
{ key: 'CI_BUILD_REF', value: build.sha, public: true },
{ key: 'CI_BUILD_BEFORE_SHA', value: build.before_sha, public: true },
{ key: 'CI_BUILD_REF_NAME', value: build.ref, public: true },
@ -2341,6 +2342,28 @@ describe Ci::Build do
end
end
context 'when build is parallelized' do
let(:total) { 5 }
let(:index) { 3 }
before do
build.options[:parallel] = total
build.name = "#{build.name} #{index}/#{total}"
end
it 'includes CI_NODE_INDEX' do
is_expected.to include(
{ key: 'CI_NODE_INDEX', value: index.to_s, public: true }
)
end
it 'includes correct CI_NODE_TOTAL' do
is_expected.to include(
{ key: 'CI_NODE_TOTAL', value: total.to_s, public: true }
)
end
end
describe 'variables ordering' do
context 'when variables hierarchy is stubbed' do
let(:build_pre_var) { { key: 'build', value: 'value', public: true } }
@ -2447,6 +2470,31 @@ describe Ci::Build do
end
end
end
describe '#node_index' do
subject { build.send(:node_index) }
let(:index) { 4 }
context 'when build has only one index' do
before do
build.name = "#{build.name} #{index}/5"
end
it 'returns the index' do
expect(subject).to eq(index.to_s)
end
end
context 'when build has more than one one index' do
before do
build.name = "test_build 1/3 #{index}/5"
end
it 'returns the last index' do
expect(subject).to eq(index.to_s)
end
end
end
end
describe '#scoped_variables' do