diff options
Diffstat (limited to 'spec/gitlab_shell_spec.rb')
-rw-r--r-- | spec/gitlab_shell_spec.rb | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb index af84b29..b3279fd 100644 --- a/spec/gitlab_shell_spec.rb +++ b/spec/gitlab_shell_spec.rb @@ -1,6 +1,7 @@ require_relative 'spec_helper' require_relative '../lib/gitlab_shell' -require_relative '../lib/gitlab_access_status' +require_relative '../lib/git_access_status' +require_relative '../lib/custom_action_status' describe GitlabShell do before do @@ -153,7 +154,7 @@ describe GitlabShell do after { subject.exec(ssh_cmd) } it "should process the command" do - subject.should_receive(:process_cmd).with(%W(git-upload-pack gitlab-ci.git)) + subject.should_receive(:exec_cmd_for_gitaly).with(instance_of(GitAccessStatus), %W(git-upload-pack gitlab-ci.git)) end it "should execute the command" do @@ -188,7 +189,7 @@ describe GitlabShell do after { subject.exec(ssh_cmd) } it "should process the command" do - subject.should_receive(:process_cmd).with(%W(git-upload-pack gitlab-ci.git)) + subject.should_receive(:exec_cmd_for_gitaly).with(instance_of(GitAccessStatus), %W(git-upload-pack gitlab-ci.git)) end it "should execute the command" do @@ -212,7 +213,7 @@ describe GitlabShell do after { subject.exec(ssh_cmd) } it "should process the command" do - subject.should_receive(:process_cmd).with(%W(git-receive-pack gitlab-ci.git)) + subject.should_receive(:exec_cmd_for_gitaly).with(instance_of(GitAccessStatus), %W(git-receive-pack gitlab-ci.git)) end it "should execute the command" do @@ -234,7 +235,7 @@ describe GitlabShell do after { subject.exec(ssh_cmd) } it "should process the command" do - subject.should_receive(:process_cmd).with(%W(git-receive-pack gitlab-ci.git)) + subject.should_receive(:exec_cmd_for_gitaly).with(instance_of(GitAccessStatus), %W(git-receive-pack gitlab-ci.git)) end it "should execute the command" do @@ -253,6 +254,28 @@ describe GitlabShell do end end + context 'custom action' do + let(:ssh_cmd) { "git-receive-pack gitlab-ci.git" } + let(:custom_action_access_result) { CustomActionStatus.create_from_json('{"status":true,"message":"Attempting to proxy to primary..","payload":{"api_endpoints":["fake/info_refs","fake/push"],"data":{"username":"user1","primary_repo":"http://localhost:3001/user1/repo1.git"}}}') } + let(:http_success) { double(Net::HTTPOK, code: '200', body: 'OK') } + let(:http_error) { double(Net::HTTPInternalServerError, code: '500', body: 'Internal Server Error') } + + before { api.stub(check_access: custom_action_access_result) } + after { subject.exec(ssh_cmd) } + + it "should attempt execute the custom action" do + subject.should_receive(:exec_custom_action).with(custom_action_access_result) + end + + it "should execute the custom action" do + custom_action_access_result.should_receive(:execute).with(key_id).and_return(http_success) + end + + it "should raise an exception when the custom action is unsuccessful" do + custom_action_access_result.should_receive(:execute).with(key_id).and_return(http_error) + end + end + shared_examples_for 'upload-archive' do |command| let(:ssh_cmd) { "#{command} gitlab-ci.git" } let(:exec_cmd_params) { ['git-upload-archive', repo_path] } @@ -261,7 +284,7 @@ describe GitlabShell do after { subject.exec(ssh_cmd) } it "should process the command" do - subject.should_receive(:process_cmd).with(%W(git-upload-archive gitlab-ci.git)) + subject.should_receive(:exec_cmd_for_gitaly).with(instance_of(GitAccessStatus), %W(git-upload-archive gitlab-ci.git)) end it "should execute the command" do |