2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-14 16:32:11 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ExpandVariables do
|
|
|
|
describe '#expand' do
|
|
|
|
subject { described_class.expand(value, variables) }
|
|
|
|
|
|
|
|
tests = [
|
|
|
|
{ value: 'key',
|
|
|
|
result: 'key',
|
2017-02-22 12:44:44 -05:00
|
|
|
variables: [] },
|
2016-09-14 16:32:11 -04:00
|
|
|
{ value: 'key$variable',
|
|
|
|
result: 'key',
|
2017-02-22 12:44:44 -05:00
|
|
|
variables: [] },
|
2016-09-14 16:32:11 -04:00
|
|
|
{ value: 'key$variable',
|
|
|
|
result: 'keyvalue',
|
|
|
|
variables: [
|
|
|
|
{ key: 'variable', value: 'value' }
|
2017-02-22 13:03:32 -05:00
|
|
|
] },
|
2016-09-14 16:32:11 -04:00
|
|
|
{ value: 'key${variable}',
|
|
|
|
result: 'keyvalue',
|
|
|
|
variables: [
|
|
|
|
{ key: 'variable', value: 'value' }
|
2017-02-22 13:03:32 -05:00
|
|
|
] },
|
2016-09-14 16:32:11 -04:00
|
|
|
{ value: 'key$variable$variable2',
|
|
|
|
result: 'keyvalueresult',
|
|
|
|
variables: [
|
|
|
|
{ key: 'variable', value: 'value' },
|
2017-05-03 07:22:03 -04:00
|
|
|
{ key: 'variable2', value: 'result' }
|
2017-02-22 13:03:32 -05:00
|
|
|
] },
|
2016-09-14 16:32:11 -04:00
|
|
|
{ value: 'key${variable}${variable2}',
|
|
|
|
result: 'keyvalueresult',
|
|
|
|
variables: [
|
|
|
|
{ key: 'variable', value: 'value' },
|
|
|
|
{ key: 'variable2', value: 'result' }
|
2017-02-22 13:03:32 -05:00
|
|
|
] },
|
2016-09-14 16:32:11 -04:00
|
|
|
{ value: 'key$variable2$variable',
|
|
|
|
result: 'keyresultvalue',
|
|
|
|
variables: [
|
|
|
|
{ key: 'variable', value: 'value' },
|
2017-05-03 07:22:03 -04:00
|
|
|
{ key: 'variable2', value: 'result' }
|
2017-02-22 13:03:32 -05:00
|
|
|
] },
|
2016-09-14 16:32:11 -04:00
|
|
|
{ value: 'key${variable2}${variable}',
|
|
|
|
result: 'keyresultvalue',
|
|
|
|
variables: [
|
|
|
|
{ key: 'variable', value: 'value' },
|
|
|
|
{ key: 'variable2', value: 'result' }
|
2017-02-22 13:03:32 -05:00
|
|
|
] },
|
2017-03-10 05:20:08 -05:00
|
|
|
{ value: 'review/$CI_COMMIT_REF_NAME',
|
2016-09-14 16:32:11 -04:00
|
|
|
result: 'review/feature/add-review-apps',
|
|
|
|
variables: [
|
2017-03-10 05:20:08 -05:00
|
|
|
{ key: 'CI_COMMIT_REF_NAME', value: 'feature/add-review-apps' }
|
2017-05-03 07:22:03 -04:00
|
|
|
] }
|
2016-09-14 16:32:11 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
tests.each do |test|
|
|
|
|
context "#{test[:value]} resolves to #{test[:result]}" do
|
|
|
|
let(:value) { test[:value] }
|
|
|
|
let(:variables) { test[:variables] }
|
|
|
|
|
|
|
|
it { is_expected.to eq(test[:result]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|