2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Ci::Build::Context::Global do
|
2019-12-26 22:10:19 +05:30
|
|
|
let(:pipeline) { create(:ci_pipeline) }
|
|
|
|
let(:yaml_variables) { {} }
|
|
|
|
|
|
|
|
let(:context) { described_class.new(pipeline, yaml_variables: yaml_variables) }
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
shared_examples 'variables collection' do
|
2019-12-26 22:10:19 +05:30
|
|
|
it { is_expected.to include('CI_COMMIT_REF_NAME' => 'master') }
|
|
|
|
it { is_expected.to include('CI_PIPELINE_IID' => pipeline.iid.to_s) }
|
|
|
|
it { is_expected.to include('CI_PROJECT_PATH' => pipeline.project.full_path) }
|
|
|
|
|
|
|
|
it { is_expected.not_to have_key('CI_JOB_NAME') }
|
|
|
|
it { is_expected.not_to have_key('CI_BUILD_REF_NAME') }
|
|
|
|
|
|
|
|
context 'with passed yaml variables' do
|
|
|
|
let(:yaml_variables) { [{ key: 'SUPPORTED', value: 'parsed', public: true }] }
|
|
|
|
|
|
|
|
it { is_expected.to include('SUPPORTED' => 'parsed') }
|
|
|
|
end
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
|
|
|
describe '#variables' do
|
|
|
|
subject { context.variables.to_hash }
|
|
|
|
|
|
|
|
it { expect(context.variables).to be_instance_of(Gitlab::Ci::Variables::Collection) }
|
|
|
|
|
|
|
|
it_behaves_like 'variables collection'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#variables_hash' do
|
|
|
|
subject { context.variables_hash }
|
|
|
|
|
|
|
|
it { is_expected.to be_instance_of(ActiveSupport::HashWithIndifferentAccess) }
|
|
|
|
|
|
|
|
it_behaves_like 'variables collection'
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|