debian-mirror-gitlab/spec/lib/gitlab/checks/project_created_spec.rb

76 lines
2.4 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2018-03-17 18:26:18 +05:30
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Checks::ProjectCreated, :clean_gitlab_redis_shared_state do
2020-04-08 14:13:33 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, namespace: user.namespace) }
2021-04-29 21:17:54 +05:30
2020-04-08 14:13:33 +05:30
let(:protocol) { 'http' }
let(:git_user) { user }
let(:repository) { project.repository }
subject { described_class.new(repository, git_user, 'http') }
2018-03-17 18:26:18 +05:30
describe '.fetch_message' do
2021-09-30 23:02:18 +05:30
let(:key) { "project_created:#{user.id}:#{project.repository.gl_repository}" }
let(:legacy_key) { "project_created:#{user.id}:#{project.id}" }
2018-03-17 18:26:18 +05:30
context 'with a project created message queue' do
before do
2020-04-08 14:13:33 +05:30
subject.add_message
2018-03-17 18:26:18 +05:30
end
it 'returns project created message' do
2021-09-30 23:02:18 +05:30
expect(described_class.fetch_message(user, project.repository)).to eq(subject.message)
2018-03-17 18:26:18 +05:30
end
it 'deletes the project created message from redis' do
2021-09-30 23:02:18 +05:30
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(key) }).not_to be_nil
described_class.fetch_message(user, project.repository)
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(key) }).to be_nil
end
context 'with a message in the legacy key' do
before do
Gitlab::Redis::SharedState.with do |redis|
redis.set(legacy_key, 'legacy message')
end
end
it 'returns and deletes the legacy message' do
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(key) }).not_to be_nil
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(legacy_key) }).not_to be_nil
2020-04-08 14:13:33 +05:30
2021-09-30 23:02:18 +05:30
expect(described_class.fetch_message(user, project.repository)).to eq('legacy message')
2020-04-08 14:13:33 +05:30
2021-09-30 23:02:18 +05:30
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(key) }).to be_nil
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(legacy_key) }).to be_nil
end
2018-03-17 18:26:18 +05:30
end
end
context 'with no project created message queue' do
it 'returns nil' do
2021-09-30 23:02:18 +05:30
expect(described_class.fetch_message(user, project.repository)).to be_nil
2018-03-17 18:26:18 +05:30
end
end
end
describe '#add_message' do
it 'queues a project created message' do
2020-04-08 14:13:33 +05:30
expect(subject.add_message).to eq('OK')
2018-03-17 18:26:18 +05:30
end
2020-04-08 14:13:33 +05:30
context 'when user is nil' do
let(:git_user) { nil }
2018-03-17 18:26:18 +05:30
2020-04-08 14:13:33 +05:30
it 'handles anonymous push' do
expect(subject.add_message).to be_nil
end
2018-03-17 18:26:18 +05:30
end
end
end