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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 12:09:13 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 12:09:13 +0300
commit41cb558299b483b44b45351730ee4c0e9fe4ca2c (patch)
tree00688a9e40021c66195ad826ceddd9c19385cdcf /spec
parent3d064c737e8448880e6180aeddc59000a01aa6a8 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/sidekiq_logging/json_formatter_spec.rb44
-rw-r--r--spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb19
-rw-r--r--spec/requests/api/internal/base_spec.rb45
3 files changed, 73 insertions, 35 deletions
diff --git a/spec/lib/gitlab/sidekiq_logging/json_formatter_spec.rb b/spec/lib/gitlab/sidekiq_logging/json_formatter_spec.rb
index f2092334117..2f5343627d8 100644
--- a/spec/lib/gitlab/sidekiq_logging/json_formatter_spec.rb
+++ b/spec/lib/gitlab/sidekiq_logging/json_formatter_spec.rb
@@ -9,6 +9,8 @@ describe Gitlab::SidekiqLogging::JSONFormatter do
let(:timestamp_iso8601) { now.iso8601(3) }
describe 'with a Hash' do
+ subject { JSON.parse(described_class.new.call('INFO', now, 'my program', hash_input)) }
+
let(:hash_input) do
{
foo: 1,
@@ -23,9 +25,6 @@ describe Gitlab::SidekiqLogging::JSONFormatter do
end
it 'properly formats timestamps into ISO 8601 form' do
- result = subject.call('INFO', now, 'my program', hash_input)
-
- data = JSON.parse(result)
expected_output = hash_input.stringify_keys.merge!(
{
'severity' => 'INFO',
@@ -39,20 +38,39 @@ describe Gitlab::SidekiqLogging::JSONFormatter do
}
)
- expect(data).to eq(expected_output)
+ expect(subject).to eq(expected_output)
+ end
+
+ context 'when the job args are bigger than the maximum allowed' do
+ it 'keeps args from the front until they exceed the limit' do
+ half_limit = Gitlab::Utils::LogLimitedArray::MAXIMUM_ARRAY_LENGTH / 2
+ hash_input['args'] = [1, 2, 'a' * half_limit, 'b' * half_limit, 3]
+
+ expected_args = hash_input['args'].take(3).map(&:to_s) + ['...']
+
+ expect(subject['args']).to eq(expected_args)
+ end
+ end
+
+ it 'properly flattens arguments to a String' do
+ hash_input['args'] = [1, "test", 2, { 'test' => 1 }]
+
+ expect(subject['args']).to eq(["1", "test", "2", %({"test"=>1})])
end
end
- it 'wraps a String' do
- result = subject.call('DEBUG', now, 'my string', message)
+ describe 'with a String' do
+ it 'accepts strings with no changes' do
+ result = subject.call('DEBUG', now, 'my string', message)
- data = JSON.parse(result)
- expected_output = {
- severity: 'DEBUG',
- time: timestamp_iso8601,
- message: message
- }
+ data = JSON.parse(result)
+ expected_output = {
+ severity: 'DEBUG',
+ time: timestamp_iso8601,
+ message: message
+ }
- expect(data).to eq(expected_output.stringify_keys)
+ expect(data).to eq(expected_output.stringify_keys)
+ end
end
end
diff --git a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb
index aab63ba88ad..db7c5f771b7 100644
--- a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb
+++ b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb
@@ -30,7 +30,6 @@ describe Gitlab::SidekiqLogging::StructuredLogger do
let(:clock_thread_cputime_end) { 1.333333799 }
let(:start_payload) do
job.except('error_backtrace', 'error_class', 'error_message').merge(
- 'args' => %w(1234 hello {"key"=>"value"}),
'message' => 'TestWorker JID-da883554ee4fe414012f5f42: start',
'job_status' => 'start',
'pid' => Process.pid,
@@ -113,24 +112,6 @@ describe Gitlab::SidekiqLogging::StructuredLogger do
end
end
end
-
- 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
- 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).map(&:to_s) + ['...']
-
- expect(logger).to receive(:info).with(start_payload.merge('args' => expected_args)).ordered
- expect(logger).to receive(:info).with(end_payload.merge('args' => expected_args)).ordered
- expect(subject).to receive(:log_job_start).and_call_original
- expect(subject).to receive(:log_job_done).and_call_original
-
- subject.call(job, 'test_queue') { }
- end
- end
- end
end
context 'with SIDEKIQ_LOG_ARGUMENTS disabled' do
diff --git a/spec/requests/api/internal/base_spec.rb b/spec/requests/api/internal/base_spec.rb
index 09689c5794d..f84336b64c2 100644
--- a/spec/requests/api/internal/base_spec.rb
+++ b/spec/requests/api/internal/base_spec.rb
@@ -335,6 +335,27 @@ describe API::Internal::Base do
end
end
+ shared_examples 'snippet success' do
+ it 'responds with success' do
+ subject
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response['status']).to be_truthy
+ end
+ end
+
+ shared_examples 'snippets with web protocol' do
+ it_behaves_like 'snippet success'
+
+ context 'with disabled version flag' do
+ before do
+ stub_feature_flags(version_snippets: false)
+ end
+
+ it_behaves_like 'snippet success'
+ end
+ end
+
context 'git push with personal snippet' do
subject { push(key, personal_snippet, env: env.to_json, changes: snippet_changes) }
@@ -349,14 +370,21 @@ describe API::Internal::Base do
end
it_behaves_like 'snippets with disabled feature flag'
+
+ it_behaves_like 'snippets with web protocol' do
+ subject { push(key, personal_snippet, 'web', env: env.to_json, changes: snippet_changes) }
+ end
+
it_behaves_like 'sets hook env' do
let(:gl_repository) { Gitlab::GlRepository::SNIPPET.identifier_for_container(personal_snippet) }
end
end
context 'git pull with personal snippet' do
+ subject { pull(key, personal_snippet) }
+
it 'responds with success' do
- pull(key, personal_snippet)
+ subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response["status"]).to be_truthy
@@ -365,8 +393,10 @@ describe API::Internal::Base do
expect(user.reload.last_activity_on).to eql(Date.today)
end
- it_behaves_like 'snippets with disabled feature flag' do
- subject { pull(key, personal_snippet) }
+ it_behaves_like 'snippets with disabled feature flag'
+
+ it_behaves_like 'snippets with web protocol' do
+ subject { pull(key, personal_snippet, 'web') }
end
end
@@ -384,6 +414,11 @@ describe API::Internal::Base do
end
it_behaves_like 'snippets with disabled feature flag'
+
+ it_behaves_like 'snippets with web protocol' do
+ subject { push(key, project_snippet, 'web', env: env.to_json, changes: snippet_changes) }
+ end
+
it_behaves_like 'sets hook env' do
let(:gl_repository) { Gitlab::GlRepository::SNIPPET.identifier_for_container(project_snippet) }
end
@@ -403,6 +438,10 @@ describe API::Internal::Base do
it_behaves_like 'snippets with disabled feature flag' do
subject { pull(key, project_snippet) }
end
+
+ it_behaves_like 'snippets with web protocol' do
+ subject { pull(key, project_snippet, 'web') }
+ end
end
context "git pull" do