blob: 77346f328ca8521a8e599d05d7a4567b86d07ac0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Ci::YamlProcessor::FeatureFlags do
let(:feature_flag) { :my_feature_flag }
context 'when the actor is set' do
let(:actor) { double }
let(:another_actor) { double }
it 'checks the feature flag using the given actor' do
described_class.with_actor(actor) do
expect(Feature).to receive(:enabled?).with(feature_flag, actor)
described_class.enabled?(feature_flag)
end
end
it 'returns the value of the block' do
result = described_class.with_actor(actor) do
:test
end
expect(result).to eq(:test)
end
it 'restores the existing actor if any' do
described_class.with_actor(actor) do
described_class.with_actor(another_actor) do
expect(Feature).to receive(:enabled?).with(feature_flag, another_actor)
described_class.enabled?(feature_flag)
end
expect(Feature).to receive(:enabled?).with(feature_flag, actor)
described_class.enabled?(feature_flag)
end
end
it 'restores the actor to nil after the block' do
described_class.with_actor(actor) do
expect(Thread.current[described_class::ACTOR_KEY]).to eq(actor)
end
expect(Thread.current[described_class::ACTOR_KEY]).to be nil
end
end
context 'when feature flag is checked outside the "with_actor" block' do
context 'when yaml_processor_feature_flag_corectness is used', :yaml_processor_feature_flag_corectness do
it 'raises an error on dev/test environment' do
expect { described_class.enabled?(feature_flag) }.to raise_error(described_class::NoActorError)
end
context 'when on production' do
before do
allow(Gitlab::ErrorTracking).to receive(:should_raise_for_dev?).and_return(false)
end
it 'checks the feature flag without actor' do
expect(Feature).to receive(:enabled?).with(feature_flag, nil)
expect(Gitlab::ErrorTracking)
.to receive(:track_and_raise_for_dev_exception)
.and_call_original
described_class.enabled?(feature_flag)
end
end
end
context 'when yaml_processor_feature_flag_corectness is not used' do
it 'checks the feature flag without actor' do
expect(Feature).to receive(:enabled?).with(feature_flag, nil)
expect(Gitlab::ErrorTracking)
.to receive(:track_exception)
described_class.enabled?(feature_flag)
end
end
end
context 'when actor is explicitly nil' do
it 'checks the feature flag without actor' do
described_class.with_actor(nil) do
expect(Feature).to receive(:enabled?).with(feature_flag, nil)
described_class.enabled?(feature_flag)
end
end
end
end
|