2017-04-03 13:27:14 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-05-31 21:06:01 +00:00
|
|
|
# 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, lib: true, skip_gitaly_mock: true do
|
2017-05-10 12:18:59 +00:00
|
|
|
describe '.stub' do
|
2017-05-31 21:06:01 +00:00
|
|
|
# Notice that this is referring to gRPC "stubs", not rspec stubs
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
|
|
|
described_class.clear_stubs!
|
|
|
|
end
|
2017-05-10 12:18:59 +00:00
|
|
|
|
2017-04-03 13:27:14 +00:00
|
|
|
context 'when passed a UNIX socket address' do
|
2017-05-10 12:18:59 +00:00
|
|
|
it 'passes the address as-is to GRPC' do
|
2017-04-03 13:27:14 +00:00
|
|
|
address = 'unix:/tmp/gitaly.sock'
|
2017-05-10 12:18:59 +00:00
|
|
|
allow(Gitlab.config.repositories).to receive(:storages).and_return({
|
|
|
|
'default' => { 'gitaly_address' => address }
|
|
|
|
})
|
2017-04-03 13:27:14 +00:00
|
|
|
|
2017-07-18 07:59:36 +00:00
|
|
|
expect(Gitaly::CommitService::Stub).to receive(:new).with(address, any_args)
|
2017-04-03 13:27:14 +00:00
|
|
|
|
2017-07-18 07:59:36 +00:00
|
|
|
described_class.stub(:commit_service, 'default')
|
2017-04-03 13:27:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passed a TCP address' do
|
|
|
|
it 'strips tcp:// prefix before passing it to GRPC::Core::Channel initializer' do
|
|
|
|
address = 'localhost:9876'
|
|
|
|
prefixed_address = "tcp://#{address}"
|
|
|
|
|
2017-05-10 12:18:59 +00:00
|
|
|
allow(Gitlab.config.repositories).to receive(:storages).and_return({
|
|
|
|
'default' => { 'gitaly_address' => prefixed_address }
|
|
|
|
})
|
|
|
|
|
2017-07-18 07:59:36 +00:00
|
|
|
expect(Gitaly::CommitService::Stub).to receive(:new).with(address, any_args)
|
2017-04-03 13:27:14 +00:00
|
|
|
|
2017-07-18 07:59:36 +00:00
|
|
|
described_class.stub(:commit_service, 'default')
|
2017-04-03 13:27:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-31 21:06:01 +00:00
|
|
|
|
|
|
|
describe 'feature_enabled?' do
|
|
|
|
let(:feature_name) { 'my_feature' }
|
|
|
|
let(:real_feature_name) { "gitaly_#{feature_name}" }
|
|
|
|
|
|
|
|
context 'when Gitaly is disabled' do
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:enabled?).and_return(false)
|
|
|
|
end
|
2017-05-31 21:06:01 +00:00
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(described_class.feature_enabled?(feature_name)).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
|
|
|
Feature.get(real_feature_name).disable
|
|
|
|
end
|
2017-05-31 21:06:01 +00:00
|
|
|
|
|
|
|
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
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
|
|
|
Feature.get(real_feature_name).enable
|
|
|
|
end
|
2017-05-31 21:06:01 +00:00
|
|
|
|
|
|
|
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
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
|
|
|
Feature.get(real_feature_name).enable_percentage_of_time(70)
|
|
|
|
end
|
2017-05-31 21:06:01 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
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
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
|
|
|
Feature.get(real_feature_name).disable
|
|
|
|
end
|
2017-05-31 21:06:01 +00:00
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(described_class.feature_enabled?(feature_name, status: feature_status)).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-03 13:27:14 +00:00
|
|
|
end
|