Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-22 18:14:13 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-22 18:14:13 +0300
commitad765b15d8b18af8ebf26a740f679a9b3c543c1a (patch)
tree5b7152906487f56c8c5c0a4f8ac5579a7ac66589 /spec/lib
parent860dab2f5f977c7bf14c13c01e43cae2757264f1 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/feature_spec.rb22
-rw-r--r--spec/lib/gitlab/experimentation/experiment_spec.rb1
-rw-r--r--spec/lib/gitlab/lograge/custom_options_spec.rb42
3 files changed, 65 insertions, 0 deletions
diff --git a/spec/lib/feature_spec.rb b/spec/lib/feature_spec.rb
index 58e7292c125..2c4b0a85537 100644
--- a/spec/lib/feature_spec.rb
+++ b/spec/lib/feature_spec.rb
@@ -127,6 +127,10 @@ RSpec.describe Feature, stub_feature_flags: false do
end
describe '.enabled?' do
+ before do
+ allow(Feature).to receive(:log_feature_flag_states?).and_return(false)
+ end
+
it 'returns false for undefined feature' do
expect(described_class.enabled?(:some_random_feature_flag)).to be_falsey
end
@@ -179,6 +183,24 @@ RSpec.describe Feature, stub_feature_flags: false do
expect(described_class.enabled?(:a_feature, default_enabled: fake_default)).to eq(fake_default)
end
+ context 'logging is enabled', :request_store do
+ before do
+ allow(Feature).to receive(:log_feature_flag_states?).and_call_original
+ described_class.enable(:feature_flag_state_logs)
+ described_class.enable(:enabled_feature_flag)
+ described_class.enabled?(:enabled_feature_flag)
+ end
+
+ it 'does not log feature_flag_state_logs' do
+ expect(described_class.logged_states).not_to have_key("feature_flag_state_logs")
+ end
+
+ it 'logs other feature flags' do
+ expect(described_class.logged_states).to have_key(:enabled_feature_flag)
+ expect(described_class.logged_states[:enabled_feature_flag]).to be_truthy
+ end
+ end
+
context 'cached feature flag', :request_store do
let(:flag) { :some_feature_flag }
diff --git a/spec/lib/gitlab/experimentation/experiment_spec.rb b/spec/lib/gitlab/experimentation/experiment_spec.rb
index d52ab3a8983..d9bf85460b3 100644
--- a/spec/lib/gitlab/experimentation/experiment_spec.rb
+++ b/spec/lib/gitlab/experimentation/experiment_spec.rb
@@ -16,6 +16,7 @@ RSpec.describe Gitlab::Experimentation::Experiment do
before do
skip_feature_flags_yaml_validation
skip_default_enabled_yaml_check
+ allow(Feature).to receive(:log_feature_flag_states?).and_return(false)
feature = double('FeatureFlag', percentage_of_time_value: percentage, enabled?: true)
allow(Feature).to receive(:get).with(:experiment_key_experiment_percentage).and_return(feature)
end
diff --git a/spec/lib/gitlab/lograge/custom_options_spec.rb b/spec/lib/gitlab/lograge/custom_options_spec.rb
index a4ae39a835a..5c9cd86ce7d 100644
--- a/spec/lib/gitlab/lograge/custom_options_spec.rb
+++ b/spec/lib/gitlab/lograge/custom_options_spec.rb
@@ -95,5 +95,47 @@ RSpec.describe Gitlab::Lograge::CustomOptions do
expect(subject[correlation_id_key]).to eq('123456')
end
end
+
+ context 'when feature flags are present', :request_store do
+ before do
+ allow(Feature::Definition).to receive(:valid_usage!).and_return(true)
+
+ allow(Feature).to receive(:log_feature_flag_states?).and_return(false)
+
+ Feature.enable(:enabled_feature)
+ Feature.disable(:disabled_feature)
+
+ allow(Feature).to receive(:log_feature_flag_states?).with(:enabled_feature).and_call_original
+ allow(Feature).to receive(:log_feature_flag_states?).with(:disabled_feature).and_call_original
+ end
+
+ context 'and :feature_flag_log_states is enabled' do
+ before do
+ Feature.enable(:feature_flag_state_logs)
+ end
+
+ it 'adds feature flag events' do
+ Feature.enabled?(:enabled_feature)
+ Feature.enabled?(:disabled_feature)
+
+ expect(subject).to have_key(:feature_flag_states)
+ expect(subject[:feature_flag_states]).to match_array(%w[enabled_feature:1 disabled_feature:0])
+ end
+ end
+
+ context 'and :feature_flag_log_states is disabled' do
+ before do
+ Feature.disable(:feature_flag_state_logs)
+ end
+
+ it 'does not track or add feature flag events' do
+ Feature.enabled?(:enabled_feature)
+ Feature.enabled?(:disabled_feature)
+
+ expect(subject).not_to have_key(:feature_flag_states)
+ expect(Feature).not_to receive(:log_feature_flag_state)
+ end
+ end
+ end
end
end