2018-02-28 07:08:42 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Ci::Build::Policy::Variables do
|
|
|
|
let(:pipeline) { build(:ci_pipeline, ref: 'master') }
|
2018-03-01 07:08:39 -05:00
|
|
|
let(:attributes) { double(:attributes) }
|
2018-02-28 07:08:42 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
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'])
|
|
|
|
|
2018-03-01 07:08:39 -05:00
|
|
|
expect(policy).to be_satisfied_by(pipeline, attributes)
|
2018-02-28 07:08:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not satisfied by an overriden empty variable' do
|
|
|
|
policy = described_class.new(['$CI_PROJECT_NAME'])
|
|
|
|
|
2018-03-01 07:08:39 -05:00
|
|
|
expect(policy).not_to be_satisfied_by(pipeline, attributes)
|
2018-02-28 07:08:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is satisfied by a truthy pipeline expression' do
|
|
|
|
policy = described_class.new([%($CI_PIPELINE_SOURCE == "#{pipeline.source}")])
|
|
|
|
|
2018-03-01 07:08:39 -05:00
|
|
|
expect(policy).to be_satisfied_by(pipeline, attributes)
|
2018-02-28 07:08:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not satisfied by a falsy pipeline expression' do
|
|
|
|
policy = described_class.new([%($CI_PIPELINE_SOURCE == "invalid source")])
|
|
|
|
|
2018-03-01 07:08:39 -05:00
|
|
|
expect(policy).not_to be_satisfied_by(pipeline, attributes)
|
2018-02-28 07:08:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is satisfied by a truthy expression using undefined variable' do
|
|
|
|
policy = described_class.new(['$UNDEFINED', '$UNDEFINED == null'])
|
|
|
|
|
2018-03-01 07:08:39 -05:00
|
|
|
expect(policy).to be_satisfied_by(pipeline, attributes)
|
2018-02-28 07:08:42 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|