Commit 8e12d060 authored by Stan Hu's avatar Stan Hu

Address review comments

parent 21770a42
...@@ -4,11 +4,10 @@ ...@@ -4,11 +4,10 @@
class StorageShard class StorageShard
include ActiveModel::Model include ActiveModel::Model
attr_accessor :name, :path, :gitaly_address, :gitaly_token attr_accessor :name, :path
validates :name, presence: true validates :name, presence: true
validates :path, presence: true validates :path, presence: true
validates :gitaly_address, presence: true
# Generates an array of StorageShard objects from the currrent storage # Generates an array of StorageShard objects from the currrent storage
# configuration using the gitlab.yml array of key/value pairs: # configuration using the gitlab.yml array of key/value pairs:
...@@ -25,6 +24,6 @@ class StorageShard ...@@ -25,6 +24,6 @@ class StorageShard
end end
def self.allowed_params def self.allowed_params
%i(name path gitaly_address gitaly_token).freeze %i(name path).freeze
end end
end end
...@@ -409,7 +409,7 @@ describe GeoNodeStatus, :geo do ...@@ -409,7 +409,7 @@ describe GeoNodeStatus, :geo do
data = GeoNodeStatusSerializer.new.represent(status).as_json data = GeoNodeStatusSerializer.new.represent(status).as_json
data['id'] = 10000 data['id'] = 10000
result = GeoNodeStatus.from_json(data) result = described_class.from_json(data)
expect(result.id).to be_nil expect(result.id).to be_nil
expect(result.attachments_count).to eq(status.attachments_count) expect(result.attachments_count).to eq(status.attachments_count)
...@@ -419,16 +419,14 @@ describe GeoNodeStatus, :geo do ...@@ -419,16 +419,14 @@ describe GeoNodeStatus, :geo do
end end
describe '#storage_shards_match?' do describe '#storage_shards_match?' do
before do before { stub_primary_node }
allow(Gitlab::Geo).to receive(:primary?).and_return(true)
end
it 'returns false if the storage shards do not match' do it 'returns false if the storage shards do not match' do
status = create(:geo_node_status) status = create(:geo_node_status)
data = GeoNodeStatusSerializer.new.represent(status).as_json data = GeoNodeStatusSerializer.new.represent(status).as_json
data['storage_shards'].first['name'] = 'broken-shard' data['storage_shards'].first['name'] = 'broken-shard'
result = GeoNodeStatus.from_json(data) result = described_class.from_json(data)
expect(result.storage_shards_match?).to be false expect(result.storage_shards_match?).to be false
end end
...@@ -438,7 +436,7 @@ describe GeoNodeStatus, :geo do ...@@ -438,7 +436,7 @@ describe GeoNodeStatus, :geo do
status.storage_shards.shuffle! status.storage_shards.shuffle!
data = GeoNodeStatusSerializer.new.represent(status).as_json data = GeoNodeStatusSerializer.new.represent(status).as_json
result = GeoNodeStatus.from_json(data) result = described_class.from_json(data)
expect(result.storage_shards_match?).to be true expect(result.storage_shards_match?).to be true
end end
......
require 'spec_helper' require 'spec_helper'
describe GeoNodeStatusEntity, :postgresql do describe GeoNodeStatusEntity, :postgresql do
include ::EE::GeoHelpers
let(:geo_node_status) { build(:geo_node_status) } let(:geo_node_status) { build(:geo_node_status) }
let(:entity) { described_class.new(geo_node_status, request: double) } let(:entity) { described_class.new(geo_node_status, request: double) }
let(:error) { 'Could not connect to Geo database' } let(:error) { 'Could not connect to Geo database' }
subject { entity.as_json } subject { entity.as_json }
before do before { stub_primary_node }
allow(Gitlab::Geo).to receive(:primary?).and_return(true)
end
it { is_expected.to have_key(:geo_node_id) } it { is_expected.to have_key(:geo_node_id) }
it { is_expected.to have_key(:healthy) } it { is_expected.to have_key(:healthy) }
...@@ -143,4 +143,11 @@ describe GeoNodeStatusEntity, :postgresql do ...@@ -143,4 +143,11 @@ describe GeoNodeStatusEntity, :postgresql do
expect(subject[:storage_shards].first[:path]).to eq(shards.first.path) expect(subject[:storage_shards].first[:path]).to eq(shards.first.path)
end end
end end
context 'secondary Geo node' do
before { stub_secondary_node }
it { is_expected.to have_key(:storage_shards) }
it { is_expected.not_to have_key(:storage_shards_match) }
end
end end
...@@ -4,5 +4,14 @@ module EE ...@@ -4,5 +4,14 @@ module EE
allow(::Gitlab::Geo).to receive(:current_node).and_return(node) allow(::Gitlab::Geo).to receive(:current_node).and_return(node)
allow(node).to receive(:current?).and_return(true) unless node.nil? allow(node).to receive(:current?).and_return(true) unless node.nil?
end end
def stub_primary_node
allow(::Gitlab::Geo).to receive(:primary?).and_return(true)
end
def stub_secondary_node
allow(::Gitlab::Geo).to receive(:primary?).and_return(false)
allow(::Gitlab::Geo).to receive(:secondary?).and_return(false)
end
end end
end end
...@@ -7,7 +7,7 @@ describe StorageShard do ...@@ -7,7 +7,7 @@ describe StorageShard do
expect(shards.count).to eq(Settings.repositories.storages.count) expect(shards.count).to eq(Settings.repositories.storages.count)
expect(shards.map(&:name)).to match_array(Settings.repositories.storages.keys) expect(shards.map(&:name)).to match_array(Settings.repositories.storages.keys)
expect(shards.map(&:path)).to match_array(Settings.repositories.storages.values.map { |x| x.path }) expect(shards.map(&:path)).to match_array(Settings.repositories.storages.values.map(&:path))
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