Commit 645442af authored by Tyler Amos's avatar Tyler Amos

Adjustments based on review feedback

Reworded some spec descriptions.
Removed a shared example as it was used in one place.
Other minor refactors.
Avoids error when namespace is nil.
parent 88a1537f
...@@ -27,7 +27,7 @@ module EE ...@@ -27,7 +27,7 @@ module EE
def additional_repo_storage_available? def additional_repo_storage_available?
return false unless ::Gitlab::CurrentSettings.automatic_purchased_storage_allocation? return false unless ::Gitlab::CurrentSettings.automatic_purchased_storage_allocation?
namespace.additional_repo_storage_by_namespace_enabled? !!namespace&.additional_repo_storage_by_namespace_enabled?
end end
def total_repository_size_excess def total_repository_size_excess
......
...@@ -228,9 +228,11 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do ...@@ -228,9 +228,11 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do
before do before do
allow(::Gitlab).to receive(:dev_env_or_com?).and_return(is_dev_or_com) allow(::Gitlab).to receive(:dev_env_or_com?).and_return(is_dev_or_com)
stub_application_setting(automatic_purchased_storage_allocation: auto_storage_allocation_enabled) stub_application_setting(automatic_purchased_storage_allocation: auto_storage_allocation_enabled)
stub_feature_flags(namespace_storage_limit: namespace_storage_limit_enabled) stub_feature_flags(
stub_feature_flags(additional_repo_storage_by_namespace: additional_storage_enabled) namespace_storage_limit: namespace_storage_limit_enabled,
stub_feature_flags(buy_storage_link: buy_storage_link_enabled) additional_repo_storage_by_namespace: additional_storage_enabled,
buy_storage_link: buy_storage_link_enabled
)
end end
it { is_expected.to eq(result) } it { is_expected.to eq(result) }
......
...@@ -23,30 +23,54 @@ RSpec.describe Gitlab::RepositorySizeChecker do ...@@ -23,30 +23,54 @@ RSpec.describe Gitlab::RepositorySizeChecker do
before do before do
allow(Gitlab::CurrentSettings).to receive(:automatic_purchased_storage_allocation?).and_return(gitlab_setting_enabled) allow(Gitlab::CurrentSettings).to receive(:automatic_purchased_storage_allocation?).and_return(gitlab_setting_enabled)
allow(namespace).to receive(:total_repository_size_excess).and_return(total_repository_size_excess.megabytes) allow(namespace).to receive(:total_repository_size_excess).and_return(total_repository_size_excess.megabytes) if namespace
end end
shared_examples 'original logic (without size excess and additional storage)' do describe '#above_size_limit?' do
shared_examples 'original logic (additional storage not considered)' do
include_examples 'checker size above limit' include_examples 'checker size above limit'
include_examples 'checker size above limit (with additional storage, that would bring it under the limit)'
include_examples 'checker size not over limit' include_examples 'checker size not over limit'
context 'when over the default limit but would be under the limit if additional storage was enabled' do
let(:current_size) { 100 }
let(:additional_purchased_storage) { 60 }
it 'returns true' do
expect(subject.above_size_limit?).to eq(true)
end
end
end end
describe '#above_size_limit?' do
context 'when enabled is false' do context 'when enabled is false' do
let(:enabled) { false } let(:enabled) { false }
context 'when size is under the limit' do
it 'returns false' do
expect(subject.above_size_limit?).to eq(false)
end
end
context 'when size is above the limit' do
let(:current_size) { 100 }
it 'returns false' do it 'returns false' do
expect(subject.above_size_limit?).to eq(false) expect(subject.above_size_limit?).to eq(false)
end end
end end
end
include_examples 'original logic (without size excess and additional storage)' include_examples 'original logic (additional storage not considered)'
context 'when Gitlab app setting for automatic purchased storage allocation is not enabled' do context 'when Gitlab app setting for automatic purchased storage allocation is not enabled' do
let(:gitlab_setting_enabled) { false } let(:gitlab_setting_enabled) { false }
include_examples 'original logic (without size excess and additional storage)' include_examples 'original logic (additional storage not considered)'
end
context 'when namespace is nil' do
let(:namespace) { nil }
include_examples 'original logic (additional storage not considered)'
end end
context 'with feature flag :namespace_storage_limit disabled' do context 'with feature flag :namespace_storage_limit disabled' do
...@@ -88,7 +112,7 @@ RSpec.describe Gitlab::RepositorySizeChecker do ...@@ -88,7 +112,7 @@ RSpec.describe Gitlab::RepositorySizeChecker do
stub_feature_flags(additional_repo_storage_by_namespace: false) stub_feature_flags(additional_repo_storage_by_namespace: false)
end end
include_examples 'original logic (without size excess and additional storage)' include_examples 'original logic (additional storage not considered)'
end end
end end
...@@ -101,6 +125,12 @@ RSpec.describe Gitlab::RepositorySizeChecker do ...@@ -101,6 +125,12 @@ RSpec.describe Gitlab::RepositorySizeChecker do
include_examples 'checker size exceeded' include_examples 'checker size exceeded'
end end
context 'when namespace is nil' do
let(:namespace) { nil }
include_examples 'checker size exceeded'
end
context 'with feature flag :namespace_storage_limit disabled' do context 'with feature flag :namespace_storage_limit disabled' do
before do before do
stub_feature_flags(namespace_storage_limit: false) stub_feature_flags(namespace_storage_limit: false)
......
...@@ -111,6 +111,10 @@ RSpec.describe EE::Namespace::RootExcessStorageSize do ...@@ -111,6 +111,10 @@ RSpec.describe EE::Namespace::RootExcessStorageSize do
it { is_expected.to eq(false) } it { is_expected.to eq(false) }
end end
context 'with feature flags (:namespace_storage_limit & :additional_repo_storage_by_namespace) enabled' do
it { is_expected.to eq(false) }
end
context 'with feature flag :namespace_storage_limit disabled' do context 'with feature flag :namespace_storage_limit disabled' do
before do before do
stub_feature_flags(namespace_storage_limit: false) stub_feature_flags(namespace_storage_limit: false)
......
...@@ -10,17 +10,6 @@ RSpec.shared_examples 'checker size above limit' do ...@@ -10,17 +10,6 @@ RSpec.shared_examples 'checker size above limit' do
end end
end end
RSpec.shared_examples 'checker size above limit (with additional storage, that would bring it under the limit)' do
context 'when size is above the limit' do
let(:current_size) { 100 }
let(:additional_purchased_storage) { 60 }
it 'returns true' do
expect(subject.above_size_limit?).to eq(true)
end
end
end
RSpec.shared_examples 'checker size not over limit' do RSpec.shared_examples 'checker size not over limit' do
it 'returns false when not over the limit' do it 'returns false when not over the limit' do
expect(subject.above_size_limit?).to eq(false) expect(subject.above_size_limit?).to eq(false)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment