diff options
author | Ash McKenzie <amckenzie@gitlab.com> | 2018-09-13 15:11:38 +1000 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2018-09-13 15:11:38 +1000 |
commit | 14738fae29d5b89d558613bb603e416a9d0ccc07 (patch) | |
tree | fe2ab321e691b09ef86fe4dc56cedfd35eed1317 | |
parent | 4656cd714f04f30d4542e57d46434829a09ff696 (diff) | |
download | gitlab-shell-ash.mckenzie/display-feedback.tar.gz |
primary_repo can be a String or a Hashash.mckenzie/display-feedback
-rw-r--r-- | spec/action/custom_spec.rb | 78 |
1 files changed, 44 insertions, 34 deletions
diff --git a/spec/action/custom_spec.rb b/spec/action/custom_spec.rb index 24c6ce8..78533c3 100644 --- a/spec/action/custom_spec.rb +++ b/spec/action/custom_spec.rb @@ -26,52 +26,62 @@ describe Action::Custom do end context 'that are valid' do - let(:payload) do - { - 'action' => 'geo_proxy_to_primary', - 'data' => { - 'api_endpoints' => %w{/api/v4/fake/info_refs /api/v4/fake/push}, - 'gl_username' => 'user1', - 'primary_repo' => 'http://localhost:3001/user1/repo1.git' - } - } + where(:primary_repo_data) do + [ + [ 'http://localhost:3001/user1/repo1.git' ], + [{ 'http' => 'http://localhost:3001/user1/repo1.git' }], + [{ 'http' => 'http://localhost:3001/user1/repo1.git', 'ssh' => 'ssh://user@localhost:3002/user1/repo1.git' }] + ] end - context 'and responds correctly' do - it 'prints a Base64 encoded result to $stdout' do - VCR.use_cassette("custom-action-ok") do - expect($stdout).to receive(:print).with('info_refs-result').ordered - expect($stdout).to receive(:print).with('push-result').ordered - subject.execute - end + with_them do + let(:payload) do + { + 'action' => 'geo_proxy_to_primary', + 'data' => { + 'api_endpoints' => %w{/api/v4/fake/info_refs /api/v4/fake/push}, + 'gl_username' => 'user1', + 'primary_repo' => primary_repo_data + } + } end - context 'with results printed to $stdout' do - before do - allow($stdout).to receive(:print).with('info_refs-result') - allow($stdout).to receive(:print).with('push-result') + context 'and responds correctly' do + it 'prints a Base64 encoded result to $stdout' do + VCR.use_cassette("custom-action-ok") do + expect($stdout).to receive(:print).with('info_refs-result').ordered + expect($stdout).to receive(:print).with('push-result').ordered + subject.execute + end end - it 'prints a message to $stderr' do - VCR.use_cassette("custom-action-ok-with-message") do - expect { subject.execute }.to output(/NOTE: Message here/).to_stderr + context 'with results printed to $stdout' do + before do + allow($stdout).to receive(:print).with('info_refs-result') + allow($stdout).to receive(:print).with('push-result') end - end - it 'returns an instance of Net::HTTPCreated' do - VCR.use_cassette("custom-action-ok") do - expect(subject.execute ).to be_instance_of(Net::HTTPCreated) + it 'prints a message to $stderr' do + VCR.use_cassette("custom-action-ok-with-message") do + expect { subject.execute }.to output(/NOTE: Message here/).to_stderr + end + end + + it 'returns an instance of Net::HTTPCreated' do + VCR.use_cassette("custom-action-ok") do + expect(subject.execute ).to be_instance_of(Net::HTTPCreated) + end end end end - end - context 'but responds incorrectly' do - it 'raises an UnsuccessfulError exception' do - VCR.use_cassette("custom-action-ok-not-json") do - expect { - subject.execute - }.to raise_error(Action::Custom::UnsuccessfulError, 'Response was not valid JSON') + context 'but responds incorrectly' do + it 'raises an UnsuccessfulError exception' do + VCR.use_cassette("custom-action-ok-not-json") do + expect { + subject.execute + }.to raise_error(Action::Custom::UnsuccessfulError, 'Response was not valid JSON') + end end end end |