Skip to content

Commit

Permalink
fix ig loading and disable web connect in testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaumik-Ashraf committed Nov 30, 2023
1 parent e6971cf commit c41d874
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
1 change: 0 additions & 1 deletion lib/inferno/apps/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def suites
subcommand 'suite', Suite

register(New, 'new', 'new TEST_KIT_NAME [-i IG_URL]', 'Run `inferno new --help` for full help')

end
end
end
35 changes: 19 additions & 16 deletions lib/inferno/apps/cli/new.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'thor'
require_relative '../../utils/named_thor_actions.rb'
require_relative '../../utils/named_thor_actions'

module Inferno
module CLI
Expand Down Expand Up @@ -52,22 +52,8 @@ def self.source_root
add_runtime_options!

def create_app
normalized_ig_uri = options['implementation_guide']

directory('.', root_name, { mode: :preserve, recursive: true, verbose: !options['quiet'] })

if normalized_ig_uri
begin
get(normalized_ig_uri, ig_file, verbose: !options['quiet'])
rescue StandardError => e
say_error e.message, :red
say_error "Failed to load #{normalized_ig_uri}", :red
say_error "Please add the implementation guide package.tgz file into #{ig_path}", :red
else
say_unless_quiet "Loaded implementation guide #{normalized_ig_uri}", :green
end
end

load_ig
say_unless_quiet "Created #{root_name} Inferno test kit!", :green

return unless options['pretend']
Expand All @@ -77,11 +63,28 @@ def create_app
end

private

def load_ig
return unless normalized_ig_uri

begin
get(normalized_ig_uri, ig_file, verbose: !options['quiet'])
rescue StandardError => e
say_error e.message, :red
say_error "Failed to load #{normalized_ig_uri}", :red
say_error "Please add the implementation guide package.tgz file into #{ig_path}", :red
else
say_unless_quiet "Loaded implementation guide #{normalized_ig_uri}", :green
end
end

def normalized_ig_uri
uri = options['implementation_guide']
return if uri.nil?

uri = uri.gsub(%r{[^/]*\.html\s*$}, 'package.tgz')
uri = File.join(uri, 'package.tgz') unless uri.ends_with? 'package.tgz'
uri
end

def ig_path
Expand Down
2 changes: 0 additions & 2 deletions lib/inferno/utils/named_thor_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module Inferno
module Utils
module NamedThorActions

INFLECTOR = Dry::Inflector.new

def root_name
Expand All @@ -29,7 +28,6 @@ def title_name
def test_suite_id
"#{library_name}_test_suite"
end

end
end
end
15 changes: 8 additions & 7 deletions spec/inferno/apps/cli/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
ABSOLUTE_PATH_TO_IG = File.expand_path('../../../fixtures/small_package.tgz', __dir__)

RSpec.describe Inferno::CLI::New do # rubocop:disable RSpec/FilePath
# Wrap all 'it' examples in a temp dir
before do |_test|
stub_request(:get, %r{https?://.*package.tgz})
.to_return(status: 200, body: File.read(ABSOLUTE_PATH_TO_IG), headers: { 'Content-Type' => 'application/gzip' })
end

around do |test|
Dir.mktmpdir do |tmpdir|
FileUtils.chdir(tmpdir) do
WebMock.allow_net_connect!
test.run
WebMock.disable_net_connect!
end
end
end

# test various `inferno new ...` options
[
%w[test-fhir-app],
%w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/],
%w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/index.html],
%w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/package.tgz],
%w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/fhir-udap-security-ig/],
%w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/fhir-udap-security-ig/index.html],
%w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/fhir-udap-security-ig/package.tgz],
%W[test-fhir-app --implementation-guide #{ABSOLUTE_PATH_TO_IG}],
%w[test-fhir-app --author ABC --author DEF]
].each do |cli_args|
Expand Down
2 changes: 1 addition & 1 deletion spec/inferno/utils/named_thor_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
end

it 'returns library name in snake case' do
expect(dummy.library_name).to eq('test_fhir_app')
expect(dummy.library_name).to eq('test_fhir_app')
end

it 'returns module name in pascal case' do
Expand Down

0 comments on commit c41d874

Please sign in to comment.