diff options
Diffstat (limited to 'spec/lib')
4 files changed, 105 insertions, 47 deletions
diff --git a/spec/lib/gitlab/ci/templates/templates_spec.rb b/spec/lib/gitlab/ci/templates/templates_spec.rb index 685243d6315..768256ee6b3 100644 --- a/spec/lib/gitlab/ci/templates/templates_spec.rb +++ b/spec/lib/gitlab/ci/templates/templates_spec.rb @@ -7,17 +7,17 @@ RSpec.describe 'CI YML Templates' do let(:all_templates) { Gitlab::Template::GitlabCiYmlTemplate.all.map(&:full_name) } - let(:disabled_templates) do - Gitlab::Template::GitlabCiYmlTemplate.disabled_templates.map do |template| - template + Gitlab::Template::GitlabCiYmlTemplate.extension + let(:excluded_templates) do + all_templates.select do |name| + Gitlab::Template::GitlabCiYmlTemplate.excluded_patterns.any? { |pattern| pattern.match?(name) } end end - context 'included in a CI YAML configuration' do + context 'when including available templates in a CI YAML configuration' do using RSpec::Parameterized::TableSyntax where(:template_name) do - all_templates - disabled_templates + all_templates - excluded_templates end with_them do @@ -41,4 +41,29 @@ RSpec.describe 'CI YML Templates' do end end end + + context 'when including unavailable templates in a CI YAML configuration' do + using RSpec::Parameterized::TableSyntax + + where(:template_name) do + excluded_templates + end + + with_them do + let(:content) do + <<~EOS + include: + - template: #{template_name} + + concrete_build_implemented_by_a_user: + stage: test + script: do something + EOS + end + + it 'is not valid' do + expect(subject).not_to be_valid + end + end + end end diff --git a/spec/lib/gitlab/template/finders/global_template_finder_spec.rb b/spec/lib/gitlab/template/finders/global_template_finder_spec.rb index e776284b3e8..e2751d194d3 100644 --- a/spec/lib/gitlab/template/finders/global_template_finder_spec.rb +++ b/spec/lib/gitlab/template/finders/global_template_finder_spec.rb @@ -15,9 +15,9 @@ RSpec.describe Gitlab::Template::Finders::GlobalTemplateFinder do FileUtils.rm_rf(base_dir) end - subject(:finder) { described_class.new(base_dir, '', { 'General' => '', 'Bar' => 'Bar' }, exclusions: exclusions) } + subject(:finder) { described_class.new(base_dir, '', { 'General' => '', 'Bar' => 'Bar' }, excluded_patterns: excluded_patterns) } - let(:exclusions) { [] } + let(:excluded_patterns) { [] } describe '.find' do context 'with a non-prefixed General template' do @@ -38,7 +38,7 @@ RSpec.describe Gitlab::Template::Finders::GlobalTemplateFinder do end context 'while listed as an exclusion' do - let(:exclusions) { %w[test-template] } + let(:excluded_patterns) { [%r{^test-template$}] } it 'does not find the template without a prefix' do expect(finder.find('test-template')).to be_nil @@ -77,7 +77,7 @@ RSpec.describe Gitlab::Template::Finders::GlobalTemplateFinder do end context 'while listed as an exclusion' do - let(:exclusions) { %w[Bar/test-template] } + let(:excluded_patterns) { [%r{^Bar/test-template$}] } it 'does not find the template with a prefix' do expect(finder.find('Bar/test-template')).to be_nil @@ -96,6 +96,17 @@ RSpec.describe Gitlab::Template::Finders::GlobalTemplateFinder do expect(finder.find('Bar/test-template')).to be_nil end end + + context 'while listed as an exclusion' do + let(:excluded_patterns) { [%r{\.latest$}] } + + it 'excludes the template matched the pattern' do + create_template!('test-template.latest') + + expect(finder.find('test-template')).to be_present + expect(finder.find('test-template.latest')).to be_nil + end + end end end end diff --git a/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb b/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb index 55444114d39..26c83ed6793 100644 --- a/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb +++ b/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb @@ -13,6 +13,12 @@ RSpec.describe Gitlab::Template::GitlabCiYmlTemplate do expect(all).to include('Docker') expect(all).to include('Ruby') end + + it 'does not include Browser-Performance template in FOSS' do + all = subject.all.map(&:name) + + expect(all).not_to include('Browser-Performance') unless Gitlab.ee? + end end describe '#content' do diff --git a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb index 7b9650a966c..6da33a83330 100644 --- a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb @@ -62,65 +62,81 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s end describe '.track_event' do - it "raise error if metrics don't have same aggregation" do - expect { described_class.track_event(entity1, different_aggregation, Date.current) } .to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownAggregation) - end + context 'when usage_ping is disabled' do + it 'does not track the event' do + stub_application_setting(usage_ping_enabled: false) - it 'raise error if metrics of unknown aggregation' do - expect { described_class.track_event(entity1, 'unknown', Date.current) } .to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownEvent) + described_class.track_event(entity1, weekly_event, Date.current) + + expect(Gitlab::Redis::HLL).not_to receive(:add) + end end - context 'for weekly events' do - it 'sets the keys in Redis to expire automatically after the given expiry time' do - described_class.track_event(entity1, "g_analytics_contribution") + context 'when usage_ping is enabled' do + before do + stub_application_setting(usage_ping_enabled: true) + end - Gitlab::Redis::SharedState.with do |redis| - keys = redis.scan_each(match: "g_{analytics}_contribution-*").to_a - expect(keys).not_to be_empty + it "raise error if metrics don't have same aggregation" do + expect { described_class.track_event(entity1, different_aggregation, Date.current) } .to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownAggregation) + end - keys.each do |key| - expect(redis.ttl(key)).to be_within(5.seconds).of(12.weeks) + it 'raise error if metrics of unknown aggregation' do + expect { described_class.track_event(entity1, 'unknown', Date.current) } .to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownEvent) + end + + context 'for weekly events' do + it 'sets the keys in Redis to expire automatically after the given expiry time' do + described_class.track_event(entity1, "g_analytics_contribution") + + Gitlab::Redis::SharedState.with do |redis| + keys = redis.scan_each(match: "g_{analytics}_contribution-*").to_a + expect(keys).not_to be_empty + + keys.each do |key| + expect(redis.ttl(key)).to be_within(5.seconds).of(12.weeks) + end end end - end - it 'sets the keys in Redis to expire automatically after 6 weeks by default' do - described_class.track_event(entity1, "g_compliance_dashboard") + it 'sets the keys in Redis to expire automatically after 6 weeks by default' do + described_class.track_event(entity1, "g_compliance_dashboard") - Gitlab::Redis::SharedState.with do |redis| - keys = redis.scan_each(match: "g_{compliance}_dashboard-*").to_a - expect(keys).not_to be_empty + Gitlab::Redis::SharedState.with do |redis| + keys = redis.scan_each(match: "g_{compliance}_dashboard-*").to_a + expect(keys).not_to be_empty - keys.each do |key| - expect(redis.ttl(key)).to be_within(5.seconds).of(6.weeks) + keys.each do |key| + expect(redis.ttl(key)).to be_within(5.seconds).of(6.weeks) + end end end end - end - context 'for daily events' do - it 'sets the keys in Redis to expire after the given expiry time' do - described_class.track_event(entity1, "g_analytics_search") + context 'for daily events' do + it 'sets the keys in Redis to expire after the given expiry time' do + described_class.track_event(entity1, "g_analytics_search") - Gitlab::Redis::SharedState.with do |redis| - keys = redis.scan_each(match: "*-g_{analytics}_search").to_a - expect(keys).not_to be_empty + Gitlab::Redis::SharedState.with do |redis| + keys = redis.scan_each(match: "*-g_{analytics}_search").to_a + expect(keys).not_to be_empty - keys.each do |key| - expect(redis.ttl(key)).to be_within(5.seconds).of(84.days) + keys.each do |key| + expect(redis.ttl(key)).to be_within(5.seconds).of(84.days) + end end end - end - it 'sets the keys in Redis to expire after 29 days by default' do - described_class.track_event(entity1, "no_slot") + it 'sets the keys in Redis to expire after 29 days by default' do + described_class.track_event(entity1, "no_slot") - Gitlab::Redis::SharedState.with do |redis| - keys = redis.scan_each(match: "*-{no_slot}").to_a - expect(keys).not_to be_empty + Gitlab::Redis::SharedState.with do |redis| + keys = redis.scan_each(match: "*-{no_slot}").to_a + expect(keys).not_to be_empty - keys.each do |key| - expect(redis.ttl(key)).to be_within(5.seconds).of(29.days) + keys.each do |key| + expect(redis.ttl(key)).to be_within(5.seconds).of(29.days) + end end end end |