2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe Gitlab::Ci::Build::Context::Build, feature_category: :pipeline_composition do
|
2019-12-26 22:10:19 +05:30
|
|
|
let(:pipeline) { create(:ci_pipeline) }
|
|
|
|
let(:seed_attributes) { { 'name' => 'some-job' } }
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
subject(:context) { described_class.new(pipeline, seed_attributes) }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
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.to include('CI_JOB_NAME' => 'some-job') }
|
2023-06-20 00:43:36 +05:30
|
|
|
|
|
|
|
context 'when FF `ci_remove_legacy_predefined_variables` is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(ci_remove_legacy_predefined_variables: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include('CI_BUILD_REF_NAME' => 'master') }
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
context 'without passed build-specific attributes' do
|
|
|
|
let(:context) { described_class.new(pipeline) }
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it { is_expected.to include('CI_JOB_NAME' => nil) }
|
|
|
|
it { is_expected.to include('CI_COMMIT_REF_NAME' => 'master') }
|
|
|
|
it { is_expected.to include('CI_PROJECT_PATH' => pipeline.project.full_path) }
|
|
|
|
|
|
|
|
context 'when FF `ci_remove_legacy_predefined_variables` is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(ci_remove_legacy_predefined_variables: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include('CI_BUILD_REF_NAME' => 'master') }
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
context 'when environment:name is provided' do
|
|
|
|
let(:seed_attributes) { { 'name' => 'some-job', 'environment' => 'test' } }
|
|
|
|
|
|
|
|
it { is_expected.to include('CI_ENVIRONMENT_NAME' => 'test') }
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
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 { expect(context.variables_hash).to be_instance_of(ActiveSupport::HashWithIndifferentAccess) }
|
|
|
|
|
|
|
|
it_behaves_like 'variables collection'
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|