diff options
author | Stan Hu <stanhu@gmail.com> | 2018-09-07 04:19:08 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-09-07 04:19:08 +0000 |
commit | c9116b6de56c5b21fea15de2be8b56fa811694aa (patch) | |
tree | e0958c142de8d75526fc50cdf609963dcdc75b1b /spec/models | |
parent | 07d5ee361a438fcfff28fe184bbec2aa98ce5d14 (diff) | |
parent | 9710cda30eadfac5b88aefbdc000d2432ea4fac2 (diff) | |
download | gitlab-ce-c9116b6de56c5b21fea15de2be8b56fa811694aa.tar.gz |
Merge branch 'issue_50488' into 'master'
Move project services log to a separate file
See merge request gitlab-org/gitlab-ce!21316
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/project_services/jira_service_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/service_spec.rb | 27 |
2 files changed, 30 insertions, 3 deletions
diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 54f1a0e38a5..788b3179b01 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -231,12 +231,12 @@ describe JiraService do end it 'logs exception when transition id is not valid' do - allow(Rails.logger).to receive(:info) - WebMock.stub_request(:post, @transitions_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)).and_raise('Bad Request') + allow(@jira_service).to receive(:log_error) + WebMock.stub_request(:post, @transitions_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)).and_raise("Bad Request") @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project)) - expect(Rails.logger).to have_received(:info).with('JiraService Issue Transition failed message ERROR: http://jira.example.com - Bad Request') + expect(@jira_service).to have_received(:log_error).with("Issue transition failed", error: "Bad Request", client_url: "http://jira.example.com") end it 'calls the api with jira_issue_transition_id' do diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 029ad7f3e9f..25eecb3f909 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -345,4 +345,31 @@ describe Service do expect(service.api_field_names).to eq(['safe_field']) end end + + context 'logging' do + let(:project) { create(:project) } + let(:service) { create(:service, project: project) } + let(:test_message) { "test message" } + let(:arguments) do + { + service_class: service.class.name, + project_path: project.full_path, + project_id: project.id, + message: test_message, + additional_argument: 'some argument' + } + end + + it 'logs info messages using json logger' do + expect(Gitlab::JsonLogger).to receive(:info).with(arguments) + + service.log_info(test_message, additional_argument: 'some argument') + end + + it 'logs error messages using json logger' do + expect(Gitlab::JsonLogger).to receive(:error).with(arguments) + + service.log_error(test_message, additional_argument: 'some argument') + end + end end |