2023-04-23 21:23:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe Gitlab::Ci::Interpolation::Block, feature_category: :pipeline_composition do
|
2023-04-23 21:23:45 +05:30
|
|
|
subject { described_class.new(block, data, ctx) }
|
|
|
|
|
|
|
|
let(:data) do
|
|
|
|
'inputs.data'
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:block) do
|
|
|
|
"$[[ #{data} ]]"
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:ctx) do
|
|
|
|
{ inputs: { data: 'abc' }, env: { 'ENV' => 'dev' } }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'knows its content' do
|
|
|
|
expect(subject.content).to eq 'inputs.data'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'properly evaluates the access pattern' do
|
|
|
|
expect(subject.value).to eq 'abc'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.match' do
|
|
|
|
it 'matches each block in a string' do
|
|
|
|
expect { |b| described_class.match('$[[ access1 ]] $[[ access2 ]]', &b) }
|
|
|
|
.to yield_successive_args(['$[[ access1 ]]', 'access1'], ['$[[ access2 ]]', 'access2'])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'matches an empty block' do
|
|
|
|
expect { |b| described_class.match('$[[]]', &b) }
|
|
|
|
.to yield_with_args('$[[]]', '')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|