Generate user agent header for GCP Client

This commit is contained in:
Matija Čupić 2017-12-04 00:53:04 +01:00
parent e0f8413056
commit 50c8bd6350
No known key found for this signature in database
GPG Key ID: 4BAF84FFACD2E5DE
2 changed files with 13 additions and 0 deletions

View File

@ -82,6 +82,10 @@ module GoogleApi
def token_life_time(expires_at)
DateTime.strptime(expires_at, '%s').to_time.utc - Time.now.utc
end
def user_agent_header
{ 'User-Agent': "GitLab/#{Gitlab::VERSION.match('(\d+\.\d+)').captures.first} (GPN:GitLab;)" }
end
end
end
end

View File

@ -125,4 +125,13 @@ describe GoogleApi::CloudPlatform::Client do
it { is_expected.to be_nil }
end
end
describe '#user_agent_header' do
subject { client.instance_eval { user_agent_header } }
it 'returns the correct major and minor GitLab version ' do
stub_const('Gitlab::VERSION', '10.3.0-pre')
expect(subject).to eq({ 'User-Agent': 'GitLab/10.3 (GPN:GitLab;)' })
end
end
end