diff options
author | ddavison <ddavison@gitlab.com> | 2019-01-08 13:44:23 -0800 |
---|---|---|
committer | Sanad Liaquat <sliaquat@gitlab.com> | 2019-01-09 12:02:56 +0500 |
commit | 7f780046c41b99c408bc0b6b25f58fc0150dd9f1 (patch) | |
tree | ba73b1dc3d22ecea5d0cf89d96761af6f0e7a04e | |
parent | 8677d408ee4686ddc6f9b49779de226d1dba08c7 (diff) | |
download | gitlab-ce-7f780046c41b99c408bc0b6b25f58fc0150dd9f1.tar.gz |
Add specs to remote grid. Raise errors for #remote_grid_credentials
Signed-off-by: ddavison <ddavison@gitlab.com>
-rw-r--r-- | qa/qa/runtime/env.rb | 8 | ||||
-rw-r--r-- | qa/spec/runtime/env_spec.rb | 59 |
2 files changed, 66 insertions, 1 deletions
diff --git a/qa/qa/runtime/env.rb b/qa/qa/runtime/env.rb index 1e293c3a0de..79b40223d84 100644 --- a/qa/qa/runtime/env.rb +++ b/qa/qa/runtime/env.rb @@ -187,7 +187,13 @@ module QA private def remote_grid_credentials - remote_grid_username ? "#{remote_grid_username}:#{remote_grid_access_key}@" : '' + if remote_grid_username + raise ArgumentError, %Q(Please provide an access key for user "#{remote_grid_username}") unless remote_grid_access_key + + return "#{remote_grid_username}:#{remote_grid_access_key}@" + end + + '' end def enabled?(value, default: true) diff --git a/qa/spec/runtime/env_spec.rb b/qa/spec/runtime/env_spec.rb index ded51d5bb7c..bc0ec08d66d 100644 --- a/qa/spec/runtime/env_spec.rb +++ b/qa/spec/runtime/env_spec.rb @@ -207,4 +207,63 @@ describe QA::Runtime::Env do expect { described_class.can_test? :foo }.to raise_error(ArgumentError, 'Unknown feature "foo"') end end + + describe 'remote grid credentials' do + it 'is blank if username is empty' do + stub_env('QA_REMOTE_GRID_USERNAME', nil) + + expect(described_class.send(:remote_grid_credentials)).to eq('') + end + + it 'throws ArgumentError if GRID_ACCESS_KEY is not specified with USERNAME' do + stub_env('QA_REMOTE_GRID_USERNAME', 'foo') + + expect { described_class.send(:remote_grid_credentials) }.to raise_error(ArgumentError, 'Please provide an access key for user "foo"') + end + + it 'returns a user:key@ combination when all args are satiated' do + stub_env('QA_REMOTE_GRID_USERNAME', 'foo') + stub_env('QA_REMOTE_GRID_ACCESS_KEY', 'bar') + + expect(described_class.send(:remote_grid_credentials)).to eq('foo:bar@') + end + end + + describe '.remote_grid_protocol' do + it 'defaults protocol to http' do + stub_env('QA_REMOTE_GRID_PROTOCOL', nil) + expect(described_class.remote_grid_protocol).to eq('http') + end + end + + describe '.remote_grid' do + it 'is falsey if QA_REMOTE_GRID is not set' do + expect(described_class.remote_grid).to be_falsey + end + + it 'accepts https protocol' do + stub_env('QA_REMOTE_GRID', 'localhost:4444') + stub_env('QA_REMOTE_GRID_PROTOCOL', 'https') + + expect(described_class.remote_grid).to eq('https://localhost:4444/wd/hub') + end + + context 'with credentials' do + it 'has a grid of http://user:key@grid/wd/hub' do + stub_env('QA_REMOTE_GRID_USERNAME', 'foo') + stub_env('QA_REMOTE_GRID_ACCESS_KEY', 'bar') + stub_env('QA_REMOTE_GRID', 'localhost:4444') + + expect(described_class.remote_grid).to eq('http://foo:bar@localhost:4444/wd/hub') + end + end + + context 'without credentials' do + it 'has a grid of http://grid/wd/hub' do + stub_env('QA_REMOTE_GRID', 'localhost:4444') + + expect(described_class.remote_grid).to eq('http://localhost:4444/wd/hub') + end + end + end end |