diff options
| author | Nick Thomas <nick@gitlab.com> | 2018-01-12 13:37:20 +0000 |
|---|---|---|
| committer | Nick Thomas <nick@gitlab.com> | 2018-01-12 13:58:15 +0000 |
| commit | d1c01fe80b3dc94a82a62b563dbda3ebd751a033 (patch) | |
| tree | c9e1d0b73578704ed1beb619bd277794f05a0087 /spec | |
| parent | 73e2cf531ca8b92dc48da5024c8095256aa10818 (diff) | |
| download | gitlab-shell-d1c01fe80b3dc94a82a62b563dbda3ebd751a033.tar.gz | |
Remove direct redis integration
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/fixtures/gitlab_config_redis.yml | 11 | ||||
| -rw-r--r-- | spec/gitlab_config_spec.rb | 15 | ||||
| -rw-r--r-- | spec/gitlab_net_spec.rb | 56 | ||||
| -rw-r--r-- | spec/gitlab_post_receive_spec.rb | 209 | ||||
| -rw-r--r-- | spec/gitlab_reference_counter_spec.rb | 38 |
5 files changed, 31 insertions, 298 deletions
diff --git a/spec/fixtures/gitlab_config_redis.yml b/spec/fixtures/gitlab_config_redis.yml deleted file mode 100644 index cfe4166..0000000 --- a/spec/fixtures/gitlab_config_redis.yml +++ /dev/null @@ -1,11 +0,0 @@ -redis: - host: 127.0.1.1 - port: 6378 - pass: secure - database: 1 - socket: /var/run/redis/redis.sock - namespace: my:gitlab - sentinels: - - - host: 127.0.0.1 - port: 26380 diff --git a/spec/gitlab_config_spec.rb b/spec/gitlab_config_spec.rb index e33e606..63cb2b3 100644 --- a/spec/gitlab_config_spec.rb +++ b/spec/gitlab_config_spec.rb @@ -4,21 +4,6 @@ require_relative '../lib/gitlab_config' describe GitlabConfig do let(:config) { GitlabConfig.new } - describe :redis do - before do - config_file = File.read('spec/fixtures/gitlab_config_redis.yml') - config.instance_variable_set(:@config, YAML.load(config_file)) - end - - it { config.redis['host'].should eq('127.0.1.1') } - it { config.redis['port'].should eq(6378) } - it { config.redis['database'].should eq(1) } - it { config.redis['namespace'].should eq('my:gitlab') } - it { config.redis['socket'].should eq('/var/run/redis/redis.sock') } - it { config.redis['pass'].should eq('secure') } - it { config.redis['sentinels'].should eq([{ 'host' => '127.0.0.1', 'port' => 26380 }]) } - end - describe :gitlab_url do let(:url) { 'http://test.com' } subject { config.gitlab_url } diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb index c22540b..8e06fa8 100644 --- a/spec/gitlab_net_spec.rb +++ b/spec/gitlab_net_spec.rb @@ -434,60 +434,4 @@ describe GitlabNet, vcr: true do store.should_receive(:add_path).with('test_path') end end - - describe '#redis_client' do - let(:config) { double('config') } - - context "with empty redis config" do - it 'returns default parameters' do - allow(gitlab_net).to receive(:config).and_return(config) - allow(config).to receive(:redis).and_return( {} ) - - expect_any_instance_of(Redis).to receive(:initialize).with({ host: '127.0.0.1', - port: 6379, - db: 0 }) - gitlab_net.redis_client - end - end - - context "with password" do - it 'uses the specified host, port, and password' do - allow(gitlab_net).to receive(:config).and_return(config) - allow(config).to receive(:redis).and_return( { 'host' => 'localhost', 'port' => 1123, 'pass' => 'secret' } ) - - expect_any_instance_of(Redis).to receive(:initialize).with({ host: 'localhost', - port: 1123, - db: 0, - password: 'secret'}) - gitlab_net.redis_client - end - end - - context "with sentinels" do - it 'uses the specified sentinels' do - allow(gitlab_net).to receive(:config).and_return(config) - allow(config).to receive(:redis).and_return({ 'host' => 'localhost', 'port' => 1123, - 'sentinels' => [{'host' => '127.0.0.1', 'port' => 26380}] }) - - expect_any_instance_of(Redis).to receive(:initialize).with({ host: 'localhost', - port: 1123, - db: 0, - sentinels: [{host: '127.0.0.1', port: 26380}] }) - gitlab_net.redis_client - end - end - - - context "with redis socket" do - let(:socket) { '/tmp/redis.socket' } - - it 'uses the socket' do - allow(gitlab_net).to receive(:config).and_return(config) - allow(config).to receive(:redis).and_return( { 'socket' => socket }) - - expect_any_instance_of(Redis).to receive(:initialize).with({ path: socket, db: 0 }) - gitlab_net.redis_client - end - end - end end diff --git a/spec/gitlab_post_receive_spec.rb b/spec/gitlab_post_receive_spec.rb index 599dd1d..1b43db0 100644 --- a/spec/gitlab_post_receive_spec.rb +++ b/spec/gitlab_post_receive_spec.rb @@ -13,7 +13,6 @@ describe GitlabPostReceive do let(:gl_repository) { "project-1" } let(:gitlab_post_receive) { GitlabPostReceive.new(gl_repository, repo_path, actor, wrongly_encoded_changes) } let(:broadcast_message) { "test " * 10 + "message " * 10 } - let(:redis_client) { double('redis_client') } let(:enqueued_at) { Time.new(2016, 6, 23, 6, 59) } let(:new_merge_request_urls) do [{ @@ -36,199 +35,53 @@ describe GitlabPostReceive do end describe "#exec" do - context 'when the new post_receive API endpoint is not available' do - before do - GitlabNet.any_instance.stub(broadcast_message: { }) - GitlabNet.any_instance.stub(:merge_request_urls).with(gl_repository, repo_path, wrongly_encoded_changes) { [] } - GitlabNet.any_instance.stub(notify_post_receive: true) + let(:response) { { 'reference_counter_decreased' => true } } - allow_any_instance_of(GitlabNet).to receive(:post_receive).and_raise(GitlabNet::NotFound) - allow_any_instance_of(GitlabNet).to receive(:redis_client).and_return(redis_client) - allow_any_instance_of(GitlabReferenceCounter).to receive(:redis_client).and_return(redis_client) - allow(redis_client).to receive(:get).and_return(1) - allow(redis_client).to receive(:incr).and_return(true) - allow(redis_client).to receive(:decr).and_return(0) - allow(redis_client).to receive(:rpush).and_return(true) - expect(Time).to receive(:now).and_return(enqueued_at) - end - - context 'Without broad cast message' do - context 'pushing new branch' do - before do - GitlabNet.any_instance.stub(:merge_request_urls).with(gl_repository, repo_path, wrongly_encoded_changes) do - new_merge_request_urls - end - end - - it "prints the new merge request url" do - assert_new_mr_printed(gitlab_post_receive) - - gitlab_post_receive.exec - end - end - - context 'pushing existing branch with merge request created' do - before do - GitlabNet.any_instance.stub(:merge_request_urls).with(gl_repository, repo_path, wrongly_encoded_changes) do - existing_merge_request_urls - end - end - - it "prints the view merge request url" do - assert_existing_mr_printed(gitlab_post_receive) - - gitlab_post_receive.exec - end - end - end - - context 'show broadcast message and merge request link' do - before do - GitlabNet.any_instance.stub(:merge_request_urls).with(gl_repository, repo_path, wrongly_encoded_changes) do - new_merge_request_urls - end - GitlabNet.any_instance.stub(broadcast_message: { "message" => broadcast_message }) - end - - it 'prints the broadcast message and create new merge request link' do - assert_broadcast_message_printed(gitlab_post_receive) - assert_new_mr_printed(gitlab_post_receive) - - gitlab_post_receive.exec - end - end - - context 'Sidekiq jobs' do - it "pushes a Sidekiq job onto the queue" do - expect(redis_client).to receive(:rpush).with( - 'resque:gitlab:queue:post_receive', - %Q/{"class":"PostReceive","args":["#{gl_repository}","#{actor}",#{base64_changes.inspect}],"jid":"#{gitlab_post_receive.jid}","enqueued_at":#{enqueued_at.to_f}}/ - ).and_return(true) - - gitlab_post_receive.exec - end - - context 'when gl_repository is nil' do - let(:gl_repository) { nil } - - it "pushes a Sidekiq job with the repository path" do - expect(redis_client).to receive(:rpush).with( - 'resque:gitlab:queue:post_receive', - %Q/{"class":"PostReceive","args":["#{repo_path}","#{actor}",#{base64_changes.inspect}],"jid":"#{gitlab_post_receive.jid}","enqueued_at":#{enqueued_at.to_f}}/ - ).and_return(true) - - gitlab_post_receive.exec - end - end - end - - context 'reference counter' do - it 'decreases the reference counter for the project' do - expect_any_instance_of(GitlabReferenceCounter).to receive(:decrease).and_return(true) - - gitlab_post_receive.exec - end - - context "when the redis command succeeds" do - before do - allow(redis_client).to receive(:decr).and_return(0) - end - - it "returns true" do - expect(gitlab_post_receive.exec).to eq(true) - end - end + it 'calls the api to notify the execution of the hook' do + expect_any_instance_of(GitlabNet).to receive(:post_receive).and_return(response) - context "when the redis command fails" do - before do - allow(redis_client).to receive(:decr).and_raise('Fail') - end - - it "returns false" do - expect(gitlab_post_receive.exec).to eq(false) - end - end - end - - context 'post_receive notification' do - it 'calls the api to notify the execution of the hook' do - expect_any_instance_of(GitlabNet).to receive(:notify_post_receive). - with(gl_repository, repo_path) - - gitlab_post_receive.exec - end - end - - context "when the redis command succeeds" do - before do - allow(redis_client).to receive(:rpush).and_return(true) - end - - it "returns true" do - expect(gitlab_post_receive.exec).to eq(true) - end - end - - context "when the redis command fails" do - before do - allow(redis_client).to receive(:rpush).and_raise('Fail') - end - - it "returns false" do - expect(gitlab_post_receive.exec).to eq(false) - end - end + expect(gitlab_post_receive.exec).to eq(true) end - context 'when the new post_receive API endpoint is available' do - let(:response) { { 'reference_counter_decreased' => true } } + context 'merge request urls and broadcast messages' do + let(:response) do + { + 'reference_counter_decreased' => true, + 'merge_request_urls' => new_merge_request_urls, + 'broadcast_message' => broadcast_message + } + end - it 'calls the api to notify the execution of the hook' do + it 'prints the merge request urls and broadcast message' do expect_any_instance_of(GitlabNet).to receive(:post_receive).and_return(response) + assert_broadcast_message_printed(gitlab_post_receive) + assert_new_mr_printed(gitlab_post_receive) expect(gitlab_post_receive.exec).to eq(true) end + end - context 'merge request urls and broadcast messages' do - let(:response) do - { - 'reference_counter_decreased' => true, - 'merge_request_urls' => new_merge_request_urls, - 'broadcast_message' => broadcast_message - } - end - - it 'prints the merge request urls and broadcast message' do - expect_any_instance_of(GitlabNet).to receive(:post_receive).and_return(response) - assert_broadcast_message_printed(gitlab_post_receive) - assert_new_mr_printed(gitlab_post_receive) - - expect(gitlab_post_receive.exec).to eq(true) - end - end - - context 'when redirected message available' do - let(:message) do - <<-MSG + context 'when redirected message available' do + let(:message) do + <<-MSG Project 'foo/bar' was moved to 'foo/baz'. Please update your Git remote: git remote set-url origin http://localhost:3000/foo/baz.git - MSG - end - let(:response) do - { - 'reference_counter_decreased' => true, - 'redirected_message' => message - } - end + MSG + end + let(:response) do + { + 'reference_counter_decreased' => true, + 'redirected_message' => message + } + end - it 'prints redirected message' do - expect_any_instance_of(GitlabNet).to receive(:post_receive).and_return(response) - assert_redirected_message_printed(gitlab_post_receive) - expect(gitlab_post_receive.exec).to eq(true) - end + it 'prints redirected message' do + expect_any_instance_of(GitlabNet).to receive(:post_receive).and_return(response) + assert_redirected_message_printed(gitlab_post_receive) + expect(gitlab_post_receive.exec).to eq(true) end end end diff --git a/spec/gitlab_reference_counter_spec.rb b/spec/gitlab_reference_counter_spec.rb deleted file mode 100644 index 5be53ff..0000000 --- a/spec/gitlab_reference_counter_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -# coding: utf-8 -require 'spec_helper' -require 'gitlab_reference_counter' - -describe GitlabReferenceCounter do - let(:redis_client) { double('redis_client') } - let(:reference_counter_key) { "git-receive-pack-reference-counter:/test/path" } - let(:gitlab_reference_counter) { GitlabReferenceCounter.new('/test/path') } - - before do - allow(gitlab_reference_counter).to receive(:redis_client).and_return(redis_client) - $logger = double('logger').as_null_object - end - - it 'increases and set the expire time of a reference count for a path' do - expect(redis_client).to receive(:incr).with(reference_counter_key) - expect(redis_client).to receive(:expire).with(reference_counter_key, GitlabReferenceCounter::REFERENCE_EXPIRE_TIME) - expect(gitlab_reference_counter.increase).to be(true) - end - - it 'decreases the reference count for a path' do - allow(redis_client).to receive(:decr).and_return(0) - expect(redis_client).to receive(:decr).with(reference_counter_key) - expect(gitlab_reference_counter.decrease).to be(true) - end - - it 'warns if attempting to decrease a counter with a value of one or less, and resets the counter' do - expect(redis_client).to receive(:decr).and_return(-1) - expect(redis_client).to receive(:del) - expect($logger).to receive(:warn).with("Reference counter for /test/path decreased when its value was less than 1. Reseting the counter.") - expect(gitlab_reference_counter.decrease).to be(true) - end - - it 'get the reference count for a path' do - allow(redis_client).to receive(:get).and_return(1) - expect(gitlab_reference_counter.value).to be(1) - end -end |
