Skip to content

Commit

Permalink
Merge branch 'main' into FI-3104-update-react
Browse files Browse the repository at this point in the history
  • Loading branch information
AlyssaWang authored Sep 27, 2024
2 parents 3ee479b + 04d2454 commit 9d23ed9
Show file tree
Hide file tree
Showing 23 changed files with 1,130 additions and 44 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## 0.4.43
* patch undefined method for nil on validator 500 response by @Shaumik-Ashraf in https://github.com/inferno-framework/inferno-core/pull/530
* FI-3172: Fix validator sessions by @Jammjammjamm in https://github.com/inferno-framework/inferno-core/pull/531

## 0.4.42
* FI-2887 Remove banner info from readme because that belongs in the docs site. by @arscan in https://github.com/inferno-framework/inferno-core/pull/527
* FI-3112: Fixed JWKS Template Path Used in Unit Tests by @vanessuniq in https://github.com/inferno-framework/inferno-core/pull/526


## 0.4.41
* Include JSON files in gem package by @vanessuniq in https://github.com/inferno-framework/inferno-core/pull/524

Expand Down
9 changes: 5 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
inferno_core (0.4.42)
inferno_core (0.4.43)
activesupport (~> 6.1.7.5)
base62-rb (= 0.3.1)
blueprinter (= 0.25.2)
Expand All @@ -18,6 +18,7 @@ PATH
hanami-controller (= 2.0.0)
hanami-router (= 2.0.0)
oj (= 3.11.0)
pastel (~> 0.8.0)
pry
pry-byebug
puma (~> 5.6.7)
Expand Down Expand Up @@ -88,7 +89,7 @@ GEM
zeitwerk (~> 2.6)
factory_bot (6.2.0)
activesupport (>= 5.0.0)
faraday (1.10.3)
faraday (1.10.4)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
Expand All @@ -111,7 +112,7 @@ GEM
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
faraday_middleware (1.2.0)
faraday_middleware (1.2.1)
faraday (~> 1.0)
fhir_client (5.0.3)
activesupport (>= 3)
Expand Down Expand Up @@ -163,7 +164,7 @@ GEM
io-console (0.6.0)
irb (1.6.2)
reline (>= 0.3.0)
jwt (2.9.0)
jwt (2.9.1)
base64
kramdown (2.4.0)
rexml
Expand Down
58 changes: 58 additions & 0 deletions dev_suites/dev_validator_suite/validator_suite.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

module DevValidatorSuite
class ValidatorSuite < Inferno::TestSuite
title 'Validator Suite'
id :dev_validator
description 'Inferno Core Developer Suite that makes calls to the HL7 Validator.'

input :url,
title: 'FHIR Server Base Url'

input :access_token,
title: 'Bearer/Access Token',
optional: true

fhir_client do
url :url
bearer_token :access_token
end

fhir_resource_validator do
url 'http://localhost/hl7validatorapi'
end

group do
title 'Patient Test Group'
id :patient_group

input :patient_id,
title: 'Patient ID'

test do
title 'Patient Read Test'
id :patient_read_test

makes_request :patient_read

run do
fhir_read(:patient, patient_id, name: :patient_read)

assert_response_status 200
end
end

test do
title 'Patient Validate Test'
id :patient_validate_test

uses_request :patient_read

run do
assert_resource_type(:patient)
assert_valid_resource
end
end
end
end
end
1 change: 1 addition & 0 deletions inferno_core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'hanami-controller', '2.0.0'
spec.add_runtime_dependency 'hanami-router', '2.0.0'
spec.add_runtime_dependency 'oj', '3.11.0'
spec.add_runtime_dependency 'pastel', '~> 0.8.0'
spec.add_runtime_dependency 'pry'
spec.add_runtime_dependency 'pry-byebug'
spec.add_runtime_dependency 'puma', '~> 5.6.7'
Expand Down
1 change: 0 additions & 1 deletion lib/inferno/apps/cli.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'thor'

require_relative 'cli/main'

module Inferno
Expand Down
227 changes: 227 additions & 0 deletions lib/inferno/apps/cli/execute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
require 'pastel'
require 'active_support'
require_relative '../../utils/verify_runnable'
require_relative '../../utils/persist_inputs'
require_relative 'execute/console_outputter'

module Inferno
module CLI
class Execute
include ::Inferno::Utils::VerifyRunnable
include ::Inferno::Utils::PersistInputs

attr_accessor :options

def self.suppress_output
begin
original_stdout = $stdout.clone
$stdout.reopen(File.new(File::NULL, 'w+'))
retval = yield
ensure
$stdout.reopen(original_stdout)
end
retval
end

def self.boot_full_inferno
ENV['NO_DB'] = 'false'

# Inferno boot flow triggers migration and logger outputs it
Inferno::CLI::Execute.suppress_output { require_relative '../../../inferno' }

Inferno::Application.start(:executor)
end

def run(options)
print_help_and_exit if options[:help]

self.options = options

outputter.print_start_message(options)

results = []
outputter.print_around_run(options) do
if selected_runnables.empty?
run_one(suite)
results = test_runs_repo.results_for_test_run(test_run(suite).id).reverse
else
selected_runnables.each do |runnable|
run_one(runnable)
results += test_runs_repo.results_for_test_run(test_run(runnable).id).reverse
end
end
end

outputter.print_results(options, results)

outputter.print_end_message(options)

exit(0) if results.all? { |result| result.result == 'pass' }

# exit(1) is for Thor failures
# exit(2) is for shell builtin failures
exit(3)
rescue Sequel::ValidationFailed => e
print_error_and_exit(e, 4)
rescue Sequel::ForeignKeyConstraintViolation => e
print_error_and_exit(e, 5)
rescue Inferno::Exceptions::RequiredInputsNotFound => e
print_error_and_exit(e, 6)
rescue Inferno::Exceptions::NotUserRunnableException => e
print_error_and_exit(e, 7)
rescue StandardError => e
print_error_and_exit(e, 8)
end

def print_help_and_exit
puts `NO_DB=true bundle exec inferno help execute`
exit(0)
end

def outputter
# TODO: swap outputter based on options
@outputter ||= Inferno::CLI::Execute::ConsoleOutputter.new
end

def selected_runnables
groups + tests
end

def run_one(runnable)
verify_runnable(
suite,
thor_hash_to_inputs_array(options[:inputs]),
test_session.suite_options
)

persist_inputs(session_data_repo, create_params(test_session, suite), test_run(runnable))

dispatch_job(test_run(runnable))
end

def suite
@suite ||= Inferno::Repositories::TestSuites.new.find(options[:suite])

raise StandardError, "Test suite #{options[:suite]} not found" if @suite.nil?

@suite
end

def test_runs_repo
@test_runs_repo ||= Inferno::Repositories::TestRuns.new
end

def test_run(runnable_param)
@test_runs ||= {}

@test_runs[runnable_param] ||= test_runs_repo.create(
create_params(test_session, runnable_param).merge({ status: 'queued' })
)

@test_runs[runnable_param]
end

def test_groups_repo
@test_groups_repo ||= Inferno::Repositories::TestGroups.new
end

def tests_repo
@tests_repo ||= Inferno::Repositories::Tests.new
end

def test_sessions_repo
@test_sessions_repo ||= Inferno::Repositories::TestSessions.new
end

def session_data_repo
@session_data_repo ||= Inferno::Repositories::SessionData.new
end

def test_session
@test_session ||= test_sessions_repo.create({
test_suite_id: suite.id,
suite_options: thor_hash_to_suite_options_array(
options[:suite_options]
)
})
end

def create_params(test_session, runnable)
{
test_session_id: test_session.id,
runnable_id_key(runnable) => runnable.id,
inputs: thor_hash_to_inputs_array(options[:inputs])
}
end

def dispatch_job(test_run)
# TODO: move suppression to outputter? better suppression?
if options[:verbose]
Jobs.perform(Jobs::ExecuteTestRun, test_run.id, force_synchronous: true)
else
Inferno::CLI::Execute.suppress_output do
Jobs.perform(Jobs::ExecuteTestRun, test_run.id, force_synchronous: true)
end
end
end

def groups
return [] if options[:groups].blank?

@groups ||= options[:groups]&.map { |short_id| find_by_short_id(test_groups_repo, short_id) }
end

def tests
return [] if options[:tests].blank?

@tests ||= options[:tests]&.map { |short_id| find_by_short_id(tests_repo, short_id) }
end

def find_by_short_id(repo, short_id)
repo.all.each do |entity|
return entity if short_id == entity.short_id && suite.id == entity.suite.id
end
raise StandardError, "Group or test #{short_id} not found"
end

def thor_hash_to_suite_options_array(hash = {})
hash.to_a.map { |pair| Inferno::DSL::SuiteOption.new({ id: pair[0], value: pair[1] }) }
end

def thor_hash_to_inputs_array(hash = {})
hash.to_a.map { |pair| { name: pair[0], value: pair[1] } }
end

def print_error_and_exit(err, code)
outputter.print_error(options || {}, err)
rescue StandardError => e
puts "Caught exception #{e} while printing exception #{err}. Exiting."
ensure
exit(code)
end

def runnable_type(runnable)
if Inferno::TestSuite.subclasses.include? runnable
:suite
elsif Inferno::TestGroup.subclasses.include? runnable
:group
elsif Inferno::Test.subclasses.include? runnable
:test
else
raise StandardError, "Unidentified runnable #{runnable}"
end
end

def runnable_id_key(runnable)
case runnable_type(runnable)
when :suite
:test_suite_id
when :group
:test_group_id
else
:test_id
end
end
end
end
end
Loading

0 comments on commit 9d23ed9

Please sign in to comment.