Fix variables expression build policy specs
This commit is contained in:
parent
b6e4e449fb
commit
713502b002
1 changed files with 14 additions and 12 deletions
|
@ -3,54 +3,56 @@ require 'spec_helper'
|
|||
describe Gitlab::Ci::Build::Policy::Variables do
|
||||
set(:project) { create(:project) }
|
||||
|
||||
let(:ci_pipeline) do
|
||||
let(:pipeline) do
|
||||
build(:ci_empty_pipeline, project: project, ref: 'master')
|
||||
end
|
||||
|
||||
let(:ci_build) do
|
||||
build(:ci_build, pipeline: ci_pipeline, project: project, ref: 'master')
|
||||
build(:ci_build, pipeline: pipeline, project: project, ref: 'master')
|
||||
end
|
||||
|
||||
let(:seed) { double('build seed', to_resource: ci_build) }
|
||||
|
||||
before do
|
||||
ci_pipeline.variables.build(key: 'CI_PROJECT_NAME', value: '')
|
||||
pipeline.variables.build(key: 'CI_PROJECT_NAME', value: '')
|
||||
end
|
||||
|
||||
describe '#satisfied_by?' do
|
||||
it 'is satisfied by a defined and existing variable' do
|
||||
policy = described_class.new(['$CI_PROJECT_ID', '$UNDEFINED'])
|
||||
|
||||
expect(policy).to be_satisfied_by(ci_pipeline, ci_build)
|
||||
expect(policy).to be_satisfied_by(pipeline, seed)
|
||||
end
|
||||
|
||||
it 'is not satisfied by an overriden empty variable' do
|
||||
policy = described_class.new(['$CI_PROJECT_NAME'])
|
||||
|
||||
expect(policy).not_to be_satisfied_by(ci_pipeline, ci_build)
|
||||
expect(policy).not_to be_satisfied_by(pipeline, seed)
|
||||
end
|
||||
|
||||
it 'is satisfied by a truthy pipeline expression' do
|
||||
policy = described_class.new([%($CI_PIPELINE_SOURCE == "#{ci_pipeline.source}")])
|
||||
policy = described_class.new([%($CI_PIPELINE_SOURCE == "#{pipeline.source}")])
|
||||
|
||||
expect(policy).to be_satisfied_by(ci_pipeline, ci_build)
|
||||
expect(policy).to be_satisfied_by(pipeline, seed)
|
||||
end
|
||||
|
||||
it 'is not satisfied by a falsy pipeline expression' do
|
||||
policy = described_class.new([%($CI_PIPELINE_SOURCE == "invalid source")])
|
||||
|
||||
expect(policy).not_to be_satisfied_by(ci_pipeline, ci_build)
|
||||
expect(policy).not_to be_satisfied_by(pipeline, seed)
|
||||
end
|
||||
|
||||
it 'is satisfied by a truthy expression using undefined variable' do
|
||||
policy = described_class.new(['$UNDEFINED', '$UNDEFINED == null'])
|
||||
|
||||
expect(policy).to be_satisfied_by(ci_pipeline, ci_build)
|
||||
expect(policy).to be_satisfied_by(pipeline, seed)
|
||||
end
|
||||
|
||||
it 'does not persist neither pipeline nor build' do
|
||||
described_class.new('$VAR').satisfied_by?(ci_pipeline, ci_build)
|
||||
described_class.new('$VAR').satisfied_by?(pipeline, seed)
|
||||
|
||||
expect(ci_pipeline).not_to be_persisted
|
||||
expect(ci_build).not_to be_persisted
|
||||
expect(pipeline).not_to be_persisted
|
||||
expect(seed.to_resource).not_to be_persisted
|
||||
end
|
||||
|
||||
pending 'test for secret variables'
|
||||
|
|
Loading…
Reference in a new issue