Commit e5ae08ac authored by Alex Ives's avatar Alex Ives

Add specs for snippet_repository replication helper

- Added specs for in_replicables_for_current_secondary? to
  EE:SnippetRepostiory

Relates to https://gitlab.com/gitlab-org/gitlab/issues/287763
parent 6f534294
...@@ -11,7 +11,7 @@ RSpec.describe SnippetRepository, :request_store, :geo, type: :model do ...@@ -11,7 +11,7 @@ RSpec.describe SnippetRepository, :request_store, :geo, type: :model do
stub_current_geo_node(node) stub_current_geo_node(node)
end end
describe '#replicables_for_current_secondary' do context 'with 3 groups, 2 projects, and 5 snippets' do
let(:group_1) { create(:group) } let(:group_1) { create(:group) }
let(:group_2) { create(:group) } let(:group_2) { create(:group) }
let(:nested_group_1) { create(:group, parent: group_1) } let(:nested_group_1) { create(:group, parent: group_1) }
...@@ -30,6 +30,53 @@ RSpec.describe SnippetRepository, :request_store, :geo, type: :model do ...@@ -30,6 +30,53 @@ RSpec.describe SnippetRepository, :request_store, :geo, type: :model do
let!(:snippet_repository_4) { create(:snippet_repository) } let!(:snippet_repository_4) { create(:snippet_repository) }
let!(:snippet_repository_5) { create(:snippet_repository, snippet: project_snippet_2) } let!(:snippet_repository_5) { create(:snippet_repository, snippet: project_snippet_2) }
describe '#in_replicables_for_current_secondary?' do
it 'all returns true if all are replicated' do
[
snippet_repository_1,
snippet_repository_2,
snippet_repository_3,
snippet_repository_4,
snippet_repository_5
].each do |repository|
expect(repository.in_replicables_for_current_secondary?).to be true
end
end
context 'with selective sync by namespace' do
before do
node.update!(selective_sync_type: 'namespaces', namespaces: [group_1])
end
it 'returns true for snippets in the namespace' do
expect(snippet_repository_1.in_replicables_for_current_secondary?).to be true
end
it 'returns true for personal snippets' do
expect(snippet_repository_2.in_replicables_for_current_secondary?).to be true
end
it 'returns false for project snippets not in an included namespace' do
expect(snippet_repository_5.in_replicables_for_current_secondary?).to be false
end
end
context 'with selective sync by shard' do
before do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['default'])
end
it 'returns true for snippets in the shard' do
expect(snippet_repository_1.in_replicables_for_current_secondary?).to be true
end
it 'returns false for project snippets not in an included shard' do
expect(snippet_repository_3.in_replicables_for_current_secondary?).to be false
end
end
end
describe '#replicables_for_current_secondary' do
it 'returns all snippet_repositories without selective sync' do it 'returns all snippet_repositories without selective sync' do
expect(described_class.replicables_for_current_secondary(1..described_class.last.id)).to match_array([ expect(described_class.replicables_for_current_secondary(1..described_class.last.id)).to match_array([
snippet_repository_1, snippet_repository_1,
...@@ -72,4 +119,5 @@ RSpec.describe SnippetRepository, :request_store, :geo, type: :model do ...@@ -72,4 +119,5 @@ RSpec.describe SnippetRepository, :request_store, :geo, type: :model do
expect(described_class.replicables_for_current_secondary(1..described_class.last.id)).to be_empty expect(described_class.replicables_for_current_secondary(1..described_class.last.id)).to be_empty
end end
end end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment