From 04c6d102616b48c95b09656efc720c7dfdc99d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Mon, 4 Dec 2017 01:59:29 +0100 Subject: [PATCH] Use RequestOptions in GCP Client user_agent_header --- lib/google_api/cloud_platform/client.rb | 4 +++- spec/lib/google_api/cloud_platform/client_spec.rb | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/google_api/cloud_platform/client.rb b/lib/google_api/cloud_platform/client.rb index 615cd7dc60a..15401057903 100644 --- a/lib/google_api/cloud_platform/client.rb +++ b/lib/google_api/cloud_platform/client.rb @@ -84,7 +84,9 @@ module GoogleApi end def user_agent_header - { 'User-Agent': "GitLab/#{Gitlab::VERSION.match('(\d+\.\d+)').captures.first} (GPN:GitLab;)" } + options = Google::Apis::RequestOptions.new + options.header = { 'User-Agent': "GitLab/#{Gitlab::VERSION.match('(\d+\.\d+)').captures.first} (GPN:GitLab;)" } + options end end end diff --git a/spec/lib/google_api/cloud_platform/client_spec.rb b/spec/lib/google_api/cloud_platform/client_spec.rb index 41964034062..ee8f7afc285 100644 --- a/spec/lib/google_api/cloud_platform/client_spec.rb +++ b/spec/lib/google_api/cloud_platform/client_spec.rb @@ -129,9 +129,14 @@ describe GoogleApi::CloudPlatform::Client do describe '#user_agent_header' do subject { client.instance_eval { user_agent_header } } - it 'returns the correct major and minor GitLab version ' do + it 'returns a RequestOptions object' do + expect(subject).to be_instance_of(Google::Apis::RequestOptions) + end + + it 'has the correct GitLab version in User-Agent header' do stub_const('Gitlab::VERSION', '10.3.0-pre') - expect(subject).to eq({ 'User-Agent': 'GitLab/10.3 (GPN:GitLab;)' }) + + expect(subject.header).to eq({ 'User-Agent': 'GitLab/10.3 (GPN:GitLab;)' }) end end end