summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/workhorse_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/workhorse_spec.rb')
-rw-r--r--spec/lib/gitlab/workhorse_spec.rb75
1 files changed, 70 insertions, 5 deletions
diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb
index 535c96eeee9..fdbb55fc874 100644
--- a/spec/lib/gitlab/workhorse_spec.rb
+++ b/spec/lib/gitlab/workhorse_spec.rb
@@ -179,19 +179,84 @@ describe Gitlab::Workhorse, lib: true do
describe '.git_http_ok' do
let(:user) { create(:user) }
+ let(:repo_path) { repository.path_to_repo }
+ let(:action) { 'info_refs' }
+ let(:params) do
+ { GL_ID: "user-#{user.id}", GL_REPOSITORY: "project-#{project.id}", RepoPath: repo_path }
+ end
+
+ subject { described_class.git_http_ok(repository, false, user, action) }
- subject { described_class.git_http_ok(repository, user) }
+ it { expect(subject).to include(params) }
+
+ context 'when is_wiki' do
+ let(:params) do
+ { GL_ID: "user-#{user.id}", GL_REPOSITORY: "wiki-#{project.id}", RepoPath: repo_path }
+ end
- it { expect(subject).to eq({ GL_ID: "user-#{user.id}", RepoPath: repository.path_to_repo }) }
+ subject { described_class.git_http_ok(repository, true, user, action) }
+
+ it { expect(subject).to include(params) }
+ end
context 'when Gitaly is enabled' do
+ let(:gitaly_params) do
+ {
+ GitalyAddress: Gitlab::GitalyClient.address('default')
+ }
+ end
+
before do
allow(Gitlab.config.gitaly).to receive(:enabled).and_return(true)
end
- it 'includes Gitaly params in the returned value' do
- gitaly_socket_path = URI(Gitlab::GitalyClient.get_address('default')).path
- expect(subject).to include({ GitalySocketPath: gitaly_socket_path })
+ it 'includes a Repository param' do
+ repo_param = { Repository: {
+ path: repo_path,
+ storage_name: 'default',
+ relative_path: project.full_path + '.git'
+ } }
+
+ expect(subject).to include(repo_param)
+ end
+
+ context "when git_upload_pack action is passed" do
+ let(:action) { 'git_upload_pack' }
+ let(:feature_flag) { :post_upload_pack }
+
+ context 'when action is enabled by feature flag' do
+ it 'includes Gitaly params in the returned value' do
+ allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(feature_flag).and_return(true)
+
+ expect(subject).to include(gitaly_params)
+ end
+ end
+
+ context 'when action is not enabled by feature flag' do
+ it 'does not include Gitaly params in the returned value' do
+ allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(feature_flag).and_return(false)
+
+ expect(subject).not_to include(gitaly_params)
+ end
+ end
+ end
+
+ context "when git_receive_pack action is passed" do
+ let(:action) { 'git_receive_pack' }
+
+ it { expect(subject).not_to include(gitaly_params) }
+ end
+
+ context "when info_refs action is passed" do
+ let(:action) { 'info_refs' }
+
+ it { expect(subject).to include(gitaly_params) }
+ end
+
+ context 'when action passed is not supported by Gitaly' do
+ let(:action) { 'download' }
+
+ it { expect { subject }.to raise_exception('Unsupported action: download') }
end
end
end