summaryrefslogtreecommitdiff
path: root/spec/action/custom_spec.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-09-13 19:08:07 +0000
committerStan Hu <stanhu@gmail.com>2018-09-13 19:08:07 +0000
commit3cd6939527525f8d191bc0ae519059b4e3a492ad (patch)
treeb36b9c35e13c8ebef3c6af1276dff80799fcbcb4 /spec/action/custom_spec.rb
parent35807fa052fed36228991a41b78a1ca09f4f0601 (diff)
parent14738fae29d5b89d558613bb603e416a9d0ccc07 (diff)
downloadgitlab-shell-3cd6939527525f8d191bc0ae519059b4e3a492ad.tar.gz
Merge branch 'ash.mckenzie/display-feedback' into 'master'
Display helpful feedback when proxying an SSH git push to secondary request See merge request gitlab-org/gitlab-shell!244
Diffstat (limited to 'spec/action/custom_spec.rb')
-rw-r--r--spec/action/custom_spec.rb71
1 files changed, 51 insertions, 20 deletions
diff --git a/spec/action/custom_spec.rb b/spec/action/custom_spec.rb
index e85df71..78533c3 100644
--- a/spec/action/custom_spec.rb
+++ b/spec/action/custom_spec.rb
@@ -26,31 +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 'returns an instance of Net::HTTPCreated' do
- VCR.use_cassette("custom-action-ok") do
- expect(subject.execute).to be_instance_of(Net::HTTPCreated)
- 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
- end
- context 'but responds incorrectly' do
- it 'raises an UnsuccessfulError exception' do
- VCR.use_cassette("custom-action-ok-not-json") do
- expect {
+ 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
- }.to raise_error(Action::Custom::UnsuccessfulError, 'Response was not valid JSON')
+ end
+ 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')
+ 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
+ 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
+
+ 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