Commit 2a7b73c5 authored by Mike Kozono's avatar Mike Kozono

Setup GeoNode with factory

...instead of a helper method.
parent 8cf121e8
...@@ -23,4 +23,45 @@ FactoryBot.define do ...@@ -23,4 +23,45 @@ FactoryBot.define do
sync_object_storage { false } sync_object_storage { false }
end end
end end
factory :geo_node_with_selective_sync_for, parent: :geo_node do
transient do
model { nil }
namespaces { nil }
shards { nil }
end
after :build do |node, options|
namespaces = options.namespaces
shards = options.shards
model = options.model
if namespaces
node.selective_sync_type = 'namespaces'
elsif shards
node.selective_sync_type = 'shards'
end
case namespaces
when :model
node.namespaces = [model]
when :model_parent
node.namespaces = [model.parent]
when :model_parent_parent
node.namespaces = [model.parent.parent]
when :other
node.namespaces = [create(:group)]
end
case shards
when :model
node.selective_sync_shards = [model.repository_storage]
when :model_project
project = create(:project, namespace: model)
node.selective_sync_shards = [project.repository_storage]
when :other
node.selective_sync_shards = ['other_shard_name']
end
end
end
end end
...@@ -138,11 +138,11 @@ RSpec.describe Ci::JobArtifact do ...@@ -138,11 +138,11 @@ RSpec.describe Ci::JobArtifact do
let(:project) { create(*project_factory) } let(:project) { create(*project_factory) }
let(:ci_build) { create(:ci_build, project: project) } let(:ci_build) { create(:ci_build, project: project) }
let(:node) do let(:node) do
create_geo_node_to_test_replicables_for_geo_node( create(:geo_node_with_selective_sync_for,
project, model: project,
selective_sync_namespaces: selective_sync_namespaces, namespaces: selective_sync_namespaces,
selective_sync_shards: selective_sync_shards, shards: selective_sync_shards,
sync_object_storage: sync_object_storage) sync_object_storage: sync_object_storage)
end end
before do before do
......
...@@ -41,11 +41,11 @@ RSpec.describe Upload do ...@@ -41,11 +41,11 @@ RSpec.describe Upload do
let(:model) { create(*model_factory) } let(:model) { create(*model_factory) }
let(:node) do let(:node) do
create_geo_node_to_test_replicables_for_geo_node( create(:geo_node_with_selective_sync_for,
model, model: model,
selective_sync_namespaces: selective_sync_namespaces, namespaces: selective_sync_namespaces,
selective_sync_shards: selective_sync_shards, shards: selective_sync_shards,
sync_object_storage: sync_object_storage) sync_object_storage: sync_object_storage)
end end
before do before do
......
...@@ -117,41 +117,5 @@ module EE ...@@ -117,41 +117,5 @@ module EE
drop_table :dummy_models, force: true drop_table :dummy_models, force: true
end end
end end
def create_geo_node_to_test_replicables_for_geo_node(model, selective_sync_namespaces: nil, selective_sync_shards: nil, sync_object_storage:)
node = build(:geo_node)
if selective_sync_namespaces
node.selective_sync_type = 'namespaces'
elsif selective_sync_shards
node.selective_sync_type = 'shards'
end
case selective_sync_namespaces
when :model
node.namespaces = [model]
when :model_parent
node.namespaces = [model.parent]
when :model_parent_parent
node.namespaces = [model.parent.parent]
when :other
node.namespaces = [create(:group)]
end
case selective_sync_shards
when :model
node.selective_sync_shards = [model.repository_storage]
when :model_project
project = create(:project, namespace: model)
node.selective_sync_shards = [project.repository_storage]
when :other
node.selective_sync_shards = ['other_shard_name']
end
node.sync_object_storage = sync_object_storage
node.save!
node
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