Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-15 03:08:48 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-15 03:08:48 +0300
commitb69f406585ff64b1c5140ebba775cc754fabb358 (patch)
tree9af7dfeb0c3f0f8db189a6e18c6be398a7729e2d /spec/lib/gitlab
parent866ca4e49ff74ffadf8e6f6ff663a168489c2aba (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/data_builder/build_spec.rb12
-rw-r--r--spec/lib/gitlab/data_builder/pipeline_spec.rb9
-rw-r--r--spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb9
-rw-r--r--spec/lib/gitlab/utils/log_limited_array_spec.rb49
4 files changed, 70 insertions, 9 deletions
diff --git a/spec/lib/gitlab/data_builder/build_spec.rb b/spec/lib/gitlab/data_builder/build_spec.rb
index fdb855de786..da27125c9a6 100644
--- a/spec/lib/gitlab/data_builder/build_spec.rb
+++ b/spec/lib/gitlab/data_builder/build_spec.rb
@@ -4,7 +4,8 @@ require 'spec_helper'
describe Gitlab::DataBuilder::Build do
let(:runner) { create(:ci_runner, :instance) }
- let(:build) { create(:ci_build, :running, runner: runner) }
+ let(:user) { create(:user) }
+ let(:build) { create(:ci_build, :running, runner: runner, user: user) }
describe '.build' do
let(:data) do
@@ -22,6 +23,15 @@ describe Gitlab::DataBuilder::Build do
it { expect(data[:project_id]).to eq(build.project.id) }
it { expect(data[:project_name]).to eq(build.project.full_name) }
it { expect(data[:pipeline_id]).to eq(build.pipeline.id) }
+ it {
+ expect(data[:user]).to eq(
+ {
+ name: user.name,
+ username: user.username,
+ avatar_url: user.avatar_url(only_path: false),
+ email: user.email
+ })
+ }
it { expect(data[:commit][:id]).to eq(build.pipeline.id) }
it { expect(data[:runner][:id]).to eq(build.runner.id) }
it { expect(data[:runner][:description]).to eq(build.runner.description) }
diff --git a/spec/lib/gitlab/data_builder/pipeline_spec.rb b/spec/lib/gitlab/data_builder/pipeline_spec.rb
index 86ab7f888ca..da22da8de0f 100644
--- a/spec/lib/gitlab/data_builder/pipeline_spec.rb
+++ b/spec/lib/gitlab/data_builder/pipeline_spec.rb
@@ -11,7 +11,8 @@ describe Gitlab::DataBuilder::Pipeline do
project: project,
status: 'success',
sha: project.commit.sha,
- ref: project.default_branch)
+ ref: project.default_branch,
+ user: user)
end
let!(:build) { create(:ci_build, pipeline: pipeline) }
@@ -37,6 +38,12 @@ describe Gitlab::DataBuilder::Pipeline do
expect(build_data[:allow_failure]).to eq(build.allow_failure)
expect(project_data).to eq(project.hook_attrs(backward: false))
expect(data[:merge_request]).to be_nil
+ expect(data[:user]).to eq({
+ name: user.name,
+ username: user.username,
+ avatar_url: user.avatar_url(only_path: false),
+ email: user.email
+ })
end
context 'pipeline without variables' do
diff --git a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb
index 43cdb998091..ac4cf1734a5 100644
--- a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb
+++ b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb
@@ -99,13 +99,8 @@ describe Gitlab::SidekiqLogging::StructuredLogger do
context 'when the job args are bigger than the maximum allowed' do
it 'keeps args from the front until they exceed the limit' do
Timecop.freeze(timestamp) do
- job['args'] = [
- 1,
- 2,
- 'a' * (described_class::MAXIMUM_JOB_ARGUMENTS_LENGTH / 2),
- 'b' * (described_class::MAXIMUM_JOB_ARGUMENTS_LENGTH / 2),
- 3
- ]
+ half_limit = Gitlab::Utils::LogLimitedArray::MAXIMUM_ARRAY_LENGTH / 2
+ job['args'] = [1, 2, 'a' * half_limit, 'b' * half_limit, 3]
expected_args = job['args'].take(3) + ['...']
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