summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/utils
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-15 00:08:48 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-15 00:08:48 +0000
commitb69f406585ff64b1c5140ebba775cc754fabb358 (patch)
tree9af7dfeb0c3f0f8db189a6e18c6be398a7729e2d /spec/lib/gitlab/utils
parent866ca4e49ff74ffadf8e6f6ff663a168489c2aba (diff)
downloadgitlab-ce-b69f406585ff64b1c5140ebba775cc754fabb358.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/utils')
-rw-r--r--spec/lib/gitlab/utils/log_limited_array_spec.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/lib/gitlab/utils/log_limited_array_spec.rb b/spec/lib/gitlab/utils/log_limited_array_spec.rb
new file mode 100644
index 00000000000..2729b2c7b6f
--- /dev/null
+++ b/spec/lib/gitlab/utils/log_limited_array_spec.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+
+describe Gitlab::Utils::LogLimitedArray do
+ describe '.log_limited_array' do
+ context 'when the argument is not an array' do
+ it 'returns an empty array' do
+ expect(described_class.log_limited_array('aa')).to eq([])
+ end
+ end
+
+ context 'when the argument is an array' do
+ context 'when the array is under the limit' do
+ it 'returns the array unchanged' do
+ expect(described_class.log_limited_array(%w(a b))).to eq(%w(a b))
+ end
+ end
+
+ context 'when the array exceeds the limit' do
+ it 'replaces arguments after the limit with an ellipsis string' do
+ half_limit = described_class::MAXIMUM_ARRAY_LENGTH / 2
+ long_array = ['a' * half_limit, 'b' * half_limit, 'c']
+
+ expect(described_class.log_limited_array(long_array))
+ .to eq(long_array.take(1) + ['...'])
+ end
+ end
+
+ context 'when the array contains arrays and hashes' do
+ it 'calculates the size based on the JSON representation' do
+ long_array = [
+ 'a',
+ ['b'] * 10,
+ { c: 'c' * 10 },
+ # Each character in the array takes up four characters: the
+ # character itself, the two quotes, and the comma (closing
+ # square bracket for the last item)
+ ['d'] * (described_class::MAXIMUM_ARRAY_LENGTH / 4),
+ 'e'
+ ]
+
+ expect(described_class.log_limited_array(long_array))
+ .to eq(long_array.take(3) + ['...'])
+ end
+ end
+ end
+ end
+end