Commit f8476338 authored by João Cunha's avatar João Cunha Committed by Grzegorz Bizon

Enforce Gitlab::Utils::DeepSize `max_size` and `max_depth` defaults

parent 63fe208c
...@@ -13,8 +13,8 @@ module Gitlab ...@@ -13,8 +13,8 @@ module Gitlab
def initialize(root, max_size: DEFAULT_MAX_SIZE, max_depth: DEFAULT_MAX_DEPTH) def initialize(root, max_size: DEFAULT_MAX_SIZE, max_depth: DEFAULT_MAX_DEPTH)
@root = root @root = root
@max_size = max_size @max_size = max_size || DEFAULT_MAX_SIZE
@max_depth = max_depth @max_depth = max_depth || DEFAULT_MAX_DEPTH
@size = 0 @size = 0
@depth = 0 @depth = 0
......
...@@ -17,29 +17,45 @@ describe Gitlab::Utils::DeepSize do ...@@ -17,29 +17,45 @@ describe Gitlab::Utils::DeepSize do
let(:max_size) { 1.kilobyte } let(:max_size) { 1.kilobyte }
let(:max_depth) { 10 } let(:max_depth) { 10 }
let(:deep_size) { described_class.new(data, max_size: max_size, max_depth: max_depth) }
describe '#evaluate' do subject(:deep_size) { described_class.new(data, max_size: max_size, max_depth: max_depth) }
context 'when data within size and depth limits' do
it 'returns true' do it { expect(described_class::DEFAULT_MAX_SIZE).to eq(1.megabyte) }
expect(deep_size).to be_valid it { expect(described_class::DEFAULT_MAX_DEPTH).to eq(100) }
describe '#initialize' do
context 'when max_size is nil' do
let(:max_size) { nil }
it 'sets max_size to DEFAULT_MAX_SIZE' do
expect(subject.instance_variable_get(:@max_size)).to eq(described_class::DEFAULT_MAX_SIZE)
end
end
context 'when max_depth is nil' do
let(:max_depth) { nil }
it 'sets max_depth to DEFAULT_MAX_DEPTH' do
expect(subject.instance_variable_get(:@max_depth)).to eq(described_class::DEFAULT_MAX_DEPTH)
end
end end
end end
describe '#valid?' do
context 'when data within size and depth limits' do
it { is_expected.to be_valid }
end
context 'when data not within size limit' do context 'when data not within size limit' do
let(:max_size) { 200.bytes } let(:max_size) { 200.bytes }
it 'returns false' do it { is_expected.not_to be_valid }
expect(deep_size).not_to be_valid
end
end end
context 'when data not within depth limit' do context 'when data not within depth limit' do
let(:max_depth) { 2 } let(:max_depth) { 2 }
it 'returns false' do it { is_expected.not_to be_valid }
expect(deep_size).not_to be_valid
end
end end
end end
......
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