Commit b1ce3ba1 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Improve specs for predefined build variables

parent a60ccef9
...@@ -49,11 +49,9 @@ describe Gitlab::Ci::Build::Policy::Variables do ...@@ -49,11 +49,9 @@ describe Gitlab::Ci::Build::Policy::Variables do
end end
it 'allows to evaluate regular secret variables' do it 'allows to evaluate regular secret variables' do
secret = create(:ci_variable, project: project, create(:ci_variable, project: project, key: 'SECRET', value: 'my secret')
key: 'SECRET',
value: 'secret value')
policy = described_class.new(["$SECRET == 'secret value'"]) policy = described_class.new(["$SECRET == 'my secret'"])
expect(policy).to be_satisfied_by(pipeline, seed) expect(policy).to be_satisfied_by(pipeline, seed)
end end
......
...@@ -2054,17 +2054,31 @@ describe Ci::Build do ...@@ -2054,17 +2054,31 @@ describe Ci::Build do
end end
describe '#variables_hash' do describe '#variables_hash' do
context 'when overriding secret variables' do
before do before do
project.variables.create!(key: 'MY_VAR', value: 'my value 1') project.variables.create!(key: 'MY_VAR', value: 'my value 1')
pipeline.variables.create!(key: 'MY_VAR', value: 'my value 2') pipeline.variables.create!(key: 'MY_VAR', value: 'my value 2')
end end
it 'returns a regular hash created in valid order' do it 'returns a regular hash created using valid ordering' do
expect(build.variables_hash).to include('MY_VAR': 'my value 2') expect(build.variables_hash).to include('MY_VAR': 'my value 2')
expect(build.variables_hash).not_to include('MY_VAR': 'my value 1') expect(build.variables_hash).not_to include('MY_VAR': 'my value 1')
end end
end end
context 'when overriding user-provided variables' do
before do
pipeline.variables.build(key: 'MY_VAR', value: 'pipeline value')
build.yaml_variables = [{ key: 'MY_VAR', value: 'myvar', public: true }]
end
it 'returns a hash including variable with higher precedence' do
expect(build.variables_hash).to include('MY_VAR': 'pipeline value')
expect(build.variables_hash).not_to include('MY_VAR': 'myvar')
end
end
end
describe 'state transition: any => [:pending]' do describe 'state transition: any => [:pending]' do
let(:build) { create(:ci_build, :created) } let(:build) { create(:ci_build, :created) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment