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

Address review comments

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