Commit c598632b authored by Yorick Peterse's avatar Yorick Peterse

Backport try_megabytes_to_bytes from EE

EE adds this method to Gitlab::Utils, which is also required by our
SimpleCov helper. This prevents us from injecting EE modules into
Gitlab::Utils, because the necessary bits for this are not yet in place.

To work around this we just backport try_megabytes_to_bytes, as there's
no particular reason to keep this in EE only.
parent 81c6ade5
......@@ -104,7 +104,6 @@ module Gitlab
nil
end
# EE below
def try_megabytes_to_bytes(size)
Integer(size).megabytes
rescue ArgumentError
......
......@@ -213,4 +213,22 @@ describe Gitlab::Utils do
expect(subject[:variables].first[:key]).to eq('VAR1')
end
end
describe '.try_megabytes_to_bytes' do
context 'when the size can be converted to megabytes' do
it 'returns the size in megabytes' do
size = described_class.try_megabytes_to_bytes(1)
expect(size).to eq(1.megabytes)
end
end
context 'when the size can not be converted to megabytes' do
it 'returns the input size' do
size = described_class.try_megabytes_to_bytes('foo')
expect(size).to eq('foo')
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