Skip to content

Commit

Permalink
etda hostname construction for workflow or explore
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewGearhart committed Jan 25, 2019
1 parent 546af86 commit 98ce4c5
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
/pkg/
/spec/reports/
/tmp/

.idea
# rspec failure tracking
.rspec_status
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ RSpec/MultipleExpectations:
RSpec/NamedSubject:
Exclude:
- 'spec/lib/etda_utilities_etda_file_paths_spec.rb'
- 'spec/lib/etda_utilities_hosts_spec.rb'

# Offense count: 9
# Configuration parameters: Strict, EnforcedStyle.
Expand Down
1 change: 1 addition & 0 deletions lib/etda_utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ module EtdaUtilities
require 'etda_utilities/partner'
require 'etda_utilities/access_level'
require 'etda_utilities/etda_file_paths'
require 'etda_utilities/hosts'
end
43 changes: 43 additions & 0 deletions lib/etda_utilities/hosts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

module EtdaUtilities
class Hosts
def workflow_submit_host(partner, environment = 'prod')
host_builder(partner, environment, true)
end

def explore_host(partner, environment = 'prod')
host_builder(partner, environment, false)
end

private

def host_builder(partner, environment, is_workflow)
return nil if partner.nil?
return 'localhost' if environment == 'development'
location_environment = "#{host_application(is_workflow)}-#{environment}" if environment != 'prod'
"#{host_prefix(is_workflow)}#{partner_host(partner)}#{location_environment}.libraries.psu.edu"
end

def host_prefix(is_workflow = false)
return '' unless is_workflow
'submit-'
end

def host_application(is_workflow = false)
return '' if is_workflow
'-explore'
end

def partner_host(partner)
case partner
when 'graduate'
"etda"
when 'honors'
"honors"
when 'milsch'
"millennium-scholars"
end
end
end
end
53 changes: 53 additions & 0 deletions spec/lib/etda_utilities_hosts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

RSpec.describe EtdaUtilities::Hosts, type: :model do
describe 'Hosts' do
describe '#workflow_submit_host' do
it 'returns the correct production host for workflow graduate' do
expect(subject.workflow_submit_host('graduate')).to eq('submit-etda.libraries.psu.edu')
end
it 'returns the correct production host for workflow honors' do
expect(subject.workflow_submit_host('honors')).to eq('submit-honors.libraries.psu.edu')
end
it 'returns the correct production host for workflow millennium scholars' do
expect(subject.workflow_submit_host('milsch')).to eq('submit-millennium-scholars.libraries.psu.edu')
end
it 'returns the correct QA host for workflow graduate' do
expect(subject.workflow_submit_host('graduate', 'qa')).to eq('submit-etda-qa.libraries.psu.edu')
end
it 'returns the correct QA host for workflow honors' do
expect(subject.workflow_submit_host('honors', 'qa')).to eq('submit-honors-qa.libraries.psu.edu')
end
it 'returns the correct QA host for workflow millennium scholars' do
expect(subject.workflow_submit_host('milsch', 'qa')).to eq('submit-millennium-scholars-qa.libraries.psu.edu')
end
it 'returns the correct host for workflow if environment is development' do
expect(subject.workflow_submit_host('graduate', 'development')).to eq('localhost')
end
end

describe '#explore_host' do
it 'returns the correct production host for explore graduate' do
expect(subject.explore_host('graduate')).to eq('etda.libraries.psu.edu')
end
it 'returns the correct production host for explore honors' do
expect(subject.explore_host('honors')).to eq('honors.libraries.psu.edu')
end
it 'returns the correct production host for explore millennium scholars' do
expect(subject.explore_host('milsch')).to eq('millennium-scholars.libraries.psu.edu')
end
it 'returns the correct QA host for explore graduate' do
expect(subject.explore_host('graduate', 'qa')).to eq('etda-explore-qa.libraries.psu.edu')
end
it 'returns the correct QA host for explore honors' do
expect(subject.explore_host('honors', 'qa')).to eq('honors-explore-qa.libraries.psu.edu')
end
it 'returns the correct QA host for explore millennium scholars' do
expect(subject.explore_host('milsch', 'qa')).to eq('millennium-scholars-explore-qa.libraries.psu.edu')
end
it 'returns the correct host for explore if environment is development' do
expect(subject.explore_host('graduate', 'development')).to eq('localhost')
end
end
end
end

0 comments on commit 98ce4c5

Please sign in to comment.