blob: 5962ab5a985f362576ab6d60ccb5a726a0d16747 (
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
|
require 'spec_helper'
describe FeatureFlagClient do
before do
allow(ENV).to receive(:[]).and_call_original
allow(Unleash::Client).to receive(:new).and_return("fake client instance")
described_class.instance_variable_set(:@client, nil)
end
describe '.enabled?' do
it 'returns false' do
expect(described_class.enabled?(:feature_flag)).to eq(false)
end
it 'sets configuration based on environment variables' do
allow(ENV).to receive(:[]).with('GITLAB_FEATURE_FLAG_SERVER_URL').and_return('some server url')
allow(ENV).to receive(:[]).with('GITLAB_FEATURE_FLAG_INSTANCE_ID').and_return('some instance id')
expect(Unleash::Client).to receive(:new).with(
url: 'some server url',
instance_id: 'some instance id',
app_name: Rails.env
)
described_class.enabled?(:my_feature)
end
it 'is a singleton' do
allow(ENV).to receive(:[]).with('GITLAB_FEATURE_FLAG_SERVER_URL').and_return('some server url')
allow(ENV).to receive(:[]).with('GITLAB_FEATURE_FLAG_INSTANCE_ID').and_return('some instance id')
expect(Unleash::Client).to receive(:new).with(
url: 'some server url',
instance_id: 'some instance id',
app_name: Rails.env
).once
described_class.enabled?(:my_feature)
described_class.enabled?(:my_feature)
end
it 'does not set the configuration without a server url' do
allow(ENV).to receive(:[]).with('GITLAB_FEATURE_FLAG_INSTANCE_ID').and_return('some instance id')
expect(Unleash::Client).not_to receive(:new)
described_class.enabled?(:my_feature)
end
it 'does not set the configuration without an instance id' do
allow(ENV).to receive(:[]).with('GITLAB_FEATURE_FLAG_SERVER_URL').and_return('some server url')
expect(Unleash::Client).not_to receive(:new)
described_class.enabled?(:my_feature)
end
end
end
|