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
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-11-20 13:36:52 +0300
committerSean McGivern <sean@gitlab.com>2018-11-20 13:36:52 +0300
commit2742b871fe44c649b4b503d10f5875276fb8fd87 (patch)
tree4c022342bd0b7f2f9464b2fe6ee5a8d1e8a58a34 /spec/lib/gitlab/gitaly_client_spec.rb
parent799486373e74711db65c2f77d11b1ec77fd7f4d9 (diff)
Revert "Merge branch 'zj-improve-gitaly-pb' into 'master'"
This reverts merge request !23140
Diffstat (limited to 'spec/lib/gitlab/gitaly_client_spec.rb')
-rw-r--r--spec/lib/gitlab/gitaly_client_spec.rb101
1 files changed, 95 insertions, 6 deletions
diff --git a/spec/lib/gitlab/gitaly_client_spec.rb b/spec/lib/gitlab/gitaly_client_spec.rb
index 3ae319456da..81bcd8c28ed 100644
--- a/spec/lib/gitlab/gitaly_client_spec.rb
+++ b/spec/lib/gitlab/gitaly_client_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
# We stub Gitaly in `spec/support/gitaly.rb` for other tests. We don't want
# those stubs while testing the GitalyClient itself.
-describe Gitlab::GitalyClient do
+describe Gitlab::GitalyClient, skip_gitaly_mock: true do
describe '.stub_class' do
it 'returns the gRPC health check stub' do
expect(described_class.stub_class(:health_check)).to eq(::Grpc::Health::V1::Health::Stub)
@@ -191,13 +191,102 @@ describe Gitlab::GitalyClient do
let(:feature_name) { 'my_feature' }
let(:real_feature_name) { "gitaly_#{feature_name}" }
- before do
- allow(Feature).to receive(:enabled?).and_return(false)
+ context 'when Gitaly is disabled' do
+ before do
+ allow(described_class).to receive(:enabled?).and_return(false)
+ end
+
+ it 'returns false' do
+ expect(described_class.feature_enabled?(feature_name)).to be(false)
+ end
end
- it 'returns false' do
- expect(Feature).to receive(:enabled?).with(real_feature_name)
- expect(described_class.feature_enabled?(feature_name)).to be(false)
+ context 'when the feature status is DISABLED' do
+ let(:feature_status) { Gitlab::GitalyClient::MigrationStatus::DISABLED }
+
+ it 'returns false' do
+ expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(false)
+ end
+ end
+
+ context 'when the feature_status is OPT_IN' do
+ let(:feature_status) { Gitlab::GitalyClient::MigrationStatus::OPT_IN }
+
+ context "when the feature flag hasn't been set" do
+ it 'returns false' do
+ expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(false)
+ end
+ end
+
+ context "when the feature flag is set to disable" do
+ before do
+ Feature.get(real_feature_name).disable
+ end
+
+ it 'returns false' do
+ expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(false)
+ end
+ end
+
+ context "when the feature flag is set to enable" do
+ before do
+ Feature.get(real_feature_name).enable
+ end
+
+ it 'returns true' do
+ expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(true)
+ end
+ end
+
+ context "when the feature flag is set to a percentage of time" do
+ before do
+ Feature.get(real_feature_name).enable_percentage_of_time(70)
+ end
+
+ it 'bases the result on pseudo-random numbers' do
+ expect(Random).to receive(:rand).and_return(0.3)
+ expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(true)
+
+ expect(Random).to receive(:rand).and_return(0.8)
+ expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(false)
+ end
+ end
+
+ context "when a feature is not persisted" do
+ it 'returns false when opt_into_all_features is off' do
+ allow(Feature).to receive(:persisted?).and_return(false)
+ allow(described_class).to receive(:opt_into_all_features?).and_return(false)
+
+ expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(false)
+ end
+
+ it 'returns true when the override is on' do
+ allow(Feature).to receive(:persisted?).and_return(false)
+ allow(described_class).to receive(:opt_into_all_features?).and_return(true)
+
+ expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(true)
+ end
+ end
+ end
+
+ context 'when the feature_status is OPT_OUT' do
+ let(:feature_status) { Gitlab::GitalyClient::MigrationStatus::OPT_OUT }
+
+ context "when the feature flag hasn't been set" do
+ it 'returns true' do
+ expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(true)
+ end
+ end
+
+ context "when the feature flag is set to disable" do
+ before do
+ Feature.get(real_feature_name).disable
+ end
+
+ it 'returns false' do
+ expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(false)
+ end
+ end
end
end