-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add class to let us centralize shared_configs
- Loading branch information
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Lets us consolidate shared_configs for almost identical machines | ||
class HostSettings | ||
# @return [Config::Options] key/value pairs of name: file_path | ||
def self.storage_roots | ||
@storage_roots ||= Settings.storage_root_map[parsed_hostname] | ||
end | ||
|
||
# @return [String] modified hostname | ||
def self.parsed_hostname | ||
Socket.gethostname.tr('-', '_') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe HostSettings do | ||
describe '.storage_roots' do | ||
it 'gets the correct values' do | ||
expect(described_class).to receive(:parsed_hostname).and_return('default') | ||
expect(described_class.storage_roots.to_h).to eq(fixture_sr1: 'spec/fixtures/storage_root01', | ||
fixture_sr2: 'spec/fixtures/storage_root02') | ||
end | ||
end | ||
|
||
describe '.parsed_hostname' do | ||
it 'makes hyphens into underscores' do | ||
expect(Socket).to receive(:gethostname).and_return('preservation-catalog-prod-a') | ||
expect(described_class.parsed_hostname).to eq('preservation_catalog_prod_a') | ||
end | ||
end | ||
end |