2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-06-12 09:32:29 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Feature::Gitaly do
|
2021-02-16 10:09:50 -05:00
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:project_2) { create(:project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
skip_feature_flags_yaml_validation
|
|
|
|
end
|
2019-06-12 10:20:01 -04:00
|
|
|
|
2019-06-12 09:32:29 -04:00
|
|
|
describe ".enabled?" do
|
2021-02-16 10:09:50 -05:00
|
|
|
context 'when the flag is set globally' do
|
|
|
|
let(:feature_flag) { 'global_flag' }
|
|
|
|
|
|
|
|
context 'when the gate is closed' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(gitaly_global_flag: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(described_class.enabled?(feature_flag)).to be(false)
|
|
|
|
end
|
2019-06-12 09:32:29 -04:00
|
|
|
end
|
|
|
|
|
2021-02-16 10:09:50 -05:00
|
|
|
context 'when the flag defaults to on' do
|
|
|
|
it 'returns true' do
|
|
|
|
expect(described_class.enabled?(feature_flag)).to be(true)
|
|
|
|
end
|
2019-06-12 09:32:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-16 10:09:50 -05:00
|
|
|
context 'when the flag is enabled for a particular project' do
|
|
|
|
let(:feature_flag) { 'project_flag' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_feature_flags(gitaly_project_flag: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true for that project' do
|
|
|
|
expect(described_class.enabled?(feature_flag, project)).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false for any other project' do
|
|
|
|
expect(described_class.enabled?(feature_flag, project_2)).to be(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when no project is passed' do
|
|
|
|
expect(described_class.enabled?(feature_flag)).to be(false)
|
2019-06-12 10:20:01 -04:00
|
|
|
end
|
2019-06-12 09:32:29 -04:00
|
|
|
end
|
2019-06-12 10:20:01 -04:00
|
|
|
end
|
2019-06-12 09:32:29 -04:00
|
|
|
|
2019-06-12 10:20:01 -04:00
|
|
|
describe ".server_feature_flags" do
|
2020-02-12 07:09:01 -05:00
|
|
|
before do
|
2021-02-16 10:09:50 -05:00
|
|
|
stub_feature_flags(gitaly_global_flag: true, gitaly_project_flag: project, non_gitaly_flag: false)
|
2020-02-12 07:09:01 -05:00
|
|
|
end
|
2019-06-12 09:32:29 -04:00
|
|
|
|
2020-02-12 07:09:01 -05:00
|
|
|
subject { described_class.server_feature_flags }
|
2019-06-12 09:32:29 -04:00
|
|
|
|
2021-02-16 10:09:50 -05:00
|
|
|
it 'returns a hash of flags starting with the prefix, with dashes instead of underscores' do
|
|
|
|
expect(subject).to eq('gitaly-feature-global-flag' => 'true',
|
|
|
|
'gitaly-feature-project-flag' => 'false')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a project is passed' do
|
|
|
|
it 'returns the value for the flag on the given project' do
|
|
|
|
expect(described_class.server_feature_flags(project))
|
|
|
|
.to eq('gitaly-feature-global-flag' => 'true',
|
|
|
|
'gitaly-feature-project-flag' => 'true')
|
|
|
|
|
|
|
|
expect(described_class.server_feature_flags(project_2))
|
|
|
|
.to eq('gitaly-feature-global-flag' => 'true',
|
|
|
|
'gitaly-feature-project-flag' => 'false')
|
|
|
|
end
|
|
|
|
end
|
2020-03-31 08:08:09 -04:00
|
|
|
|
|
|
|
context 'when table does not exist' do
|
|
|
|
before do
|
2021-11-15 10:10:57 -05:00
|
|
|
allow(Feature::FlipperFeature.database)
|
|
|
|
.to receive(:cached_table_exists?)
|
|
|
|
.and_return(false)
|
2020-03-31 08:08:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty Hash' do
|
|
|
|
expect(subject).to eq({})
|
|
|
|
end
|
|
|
|
end
|
2019-06-12 09:32:29 -04:00
|
|
|
end
|
|
|
|
end
|