From a4958020b4445a6231f5e7ea811dccb31175ff1b Mon Sep 17 00:00:00 2001 From: Mark Lapierre Date: Thu, 27 Dec 2018 07:54:15 -0500 Subject: Allow token env var from gitlab-qa gitlab-qa accepts an env var named GITLAB_QA_ACCESS_TOKEN, but here we only accepted PERSONAL_ACCESS_TOKEN. This change allows either to be used. --- qa/qa/runtime/env.rb | 2 +- qa/spec/runtime/env_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/qa/qa/runtime/env.rb b/qa/qa/runtime/env.rb index dae5aa3f794..566db7a988d 100644 --- a/qa/qa/runtime/env.rb +++ b/qa/qa/runtime/env.rb @@ -53,7 +53,7 @@ module QA # specifies token that can be used for the api def personal_access_token - @personal_access_token ||= ENV['PERSONAL_ACCESS_TOKEN'] + @personal_access_token ||= ENV['PERSONAL_ACCESS_TOKEN'] || ENV['GITLAB_QA_ACCESS_TOKEN'] end def user_username diff --git a/qa/spec/runtime/env_spec.rb b/qa/spec/runtime/env_spec.rb index ded51d5bb7c..f3f6d13035f 100644 --- a/qa/spec/runtime/env_spec.rb +++ b/qa/spec/runtime/env_spec.rb @@ -100,6 +100,27 @@ describe QA::Runtime::Env do end end + context 'when GITLAB_QA_ACCESS_TOKEN is set' do + before do + stub_env('GITLAB_QA_ACCESS_TOKEN', 'a_token_too') + end + + it 'returns specified token from env' do + expect(described_class.personal_access_token).to eq 'a_token_too' + end + end + + context 'when both PERSONAL_ACCESS_TOKEN and GITLAB_QA_ACCESS_TOKEN are set' do + before do + stub_env('PERSONAL_ACCESS_TOKEN', 'a_token') + stub_env('GITLAB_QA_ACCESS_TOKEN', 'a_token_too') + end + + it 'returns token specified by PERSONAL_ACCESS_TOKEN from env' do + expect(described_class.personal_access_token).to eq 'a_token' + end + end + context 'when @personal_access_token is set' do before do described_class.personal_access_token = 'another_token' -- cgit v1.2.1