diff options
author | Rémy Coutable <remy@rymai.me> | 2018-10-17 18:08:20 +0000 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2018-10-17 18:08:20 +0000 |
commit | b6f2f738c73b1dfe66be61e1b37ca21fa698cf1c (patch) | |
tree | b6b520d12c2051a6a1cdaa5741f48f6583e0cce8 /qa/spec/runtime | |
parent | ab9cf561c230f1b6ec630215a9a9def53e14d764 (diff) | |
download | gitlab-ce-b6f2f738c73b1dfe66be61e1b37ca21fa698cf1c.tar.gz |
First iteration to allow creating QA resources using the API
Diffstat (limited to 'qa/spec/runtime')
-rw-r--r-- | qa/spec/runtime/api/client_spec.rb | 25 | ||||
-rw-r--r-- | qa/spec/runtime/api/request_spec.rb | 18 | ||||
-rw-r--r-- | qa/spec/runtime/api_request_spec.rb | 0 | ||||
-rw-r--r-- | qa/spec/runtime/env_spec.rb | 51 |
4 files changed, 80 insertions, 14 deletions
diff --git a/qa/spec/runtime/api/client_spec.rb b/qa/spec/runtime/api/client_spec.rb index d497d8839b8..975586b505f 100644 --- a/qa/spec/runtime/api/client_spec.rb +++ b/qa/spec/runtime/api/client_spec.rb @@ -13,18 +13,27 @@ describe QA::Runtime::API::Client do end end - describe '#get_personal_access_token' do - it 'returns specified token from env' do - stub_env('PERSONAL_ACCESS_TOKEN', 'a_token') + describe '#personal_access_token' do + context 'when QA::Runtime::Env.personal_access_token is present' do + before do + allow(QA::Runtime::Env).to receive(:personal_access_token).and_return('a_token') + end - expect(described_class.new.get_personal_access_token).to eq 'a_token' + it 'returns specified token from env' do + expect(described_class.new.personal_access_token).to eq 'a_token' + end end - it 'returns a created token' do - allow_any_instance_of(described_class) - .to receive(:create_personal_access_token).and_return('created_token') + context 'when QA::Runtime::Env.personal_access_token is nil' do + before do + allow(QA::Runtime::Env).to receive(:personal_access_token).and_return(nil) + end - expect(described_class.new.get_personal_access_token).to eq 'created_token' + it 'returns a created token' do + expect(subject).to receive(:create_personal_access_token).and_return('created_token') + + expect(subject.personal_access_token).to eq 'created_token' + end end end end diff --git a/qa/spec/runtime/api/request_spec.rb b/qa/spec/runtime/api/request_spec.rb index 80e3149f32d..08233e3c1d6 100644 --- a/qa/spec/runtime/api/request_spec.rb +++ b/qa/spec/runtime/api/request_spec.rb @@ -1,17 +1,23 @@ describe QA::Runtime::API::Request do - include Support::StubENV + let(:client) { QA::Runtime::API::Client.new('http://example.com') } + let(:request) { described_class.new(client, '/users') } before do - stub_env('PERSONAL_ACCESS_TOKEN', 'a_token') + allow(client).to receive(:personal_access_token).and_return('a_token') end - let(:client) { QA::Runtime::API::Client.new('http://example.com') } - let(:request) { described_class.new(client, '/users') } - describe '#url' do - it 'returns the full api request url' do + it 'returns the full API request url' do expect(request.url).to eq 'http://example.com/api/v4/users?private_token=a_token' end + + context 'when oauth_access_token is passed in the query string' do + let(:request) { described_class.new(client, '/users', { oauth_access_token: 'foo' }) } + + it 'does not adds a private_token query string' do + expect(request.url).to eq 'http://example.com/api/v4/users?oauth_access_token=foo' + end + end end describe '#request_path' do diff --git a/qa/spec/runtime/api_request_spec.rb b/qa/spec/runtime/api_request_spec.rb deleted file mode 100644 index e69de29bb2d..00000000000 --- a/qa/spec/runtime/api_request_spec.rb +++ /dev/null diff --git a/qa/spec/runtime/env_spec.rb b/qa/spec/runtime/env_spec.rb index fda955f6600..b5ecf1afb80 100644 --- a/qa/spec/runtime/env_spec.rb +++ b/qa/spec/runtime/env_spec.rb @@ -34,6 +34,10 @@ describe QA::Runtime::Env do end end + describe '.verbose?' do + it_behaves_like 'boolean method', :verbose?, 'VERBOSE', false + end + describe '.signup_disabled?' do it_behaves_like 'boolean method', :signup_disabled?, 'SIGNUP_DISABLED', false end @@ -64,7 +68,54 @@ describe QA::Runtime::Env do end end + describe '.personal_access_token' do + around do |example| + described_class.instance_variable_set(:@personal_access_token, nil) + example.run + described_class.instance_variable_set(:@personal_access_token, nil) + end + + context 'when PERSONAL_ACCESS_TOKEN is set' do + before do + stub_env('PERSONAL_ACCESS_TOKEN', 'a_token') + end + + it 'returns specified 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' + end + + it 'returns the instance variable value' do + expect(described_class.personal_access_token).to eq 'another_token' + end + end + end + + describe '.personal_access_token=' do + around do |example| + described_class.instance_variable_set(:@personal_access_token, nil) + example.run + described_class.instance_variable_set(:@personal_access_token, nil) + end + + it 'saves the token' do + described_class.personal_access_token = 'a_token' + + expect(described_class.personal_access_token).to eq 'a_token' + end + end + describe '.forker?' do + before do + stub_env('GITLAB_FORKER_USERNAME', nil) + stub_env('GITLAB_FORKER_PASSWORD', nil) + end + it 'returns false if no forker credentials are defined' do expect(described_class).not_to be_forker end |