Skip to content

Commit

Permalink
Fix input_optional method name to include ?, change check_inputs to r…
Browse files Browse the repository at this point in the history
…aise a SkipException if all required inputs are not present, fix input name in check_inputs to account for renamed inputs
  • Loading branch information
emichaud998 committed Jan 25, 2024
1 parent c936be0 commit 697f6b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/inferno/dsl/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def input_type(identifier)
end

# @private
def input_optional(identifier)
def input_optional?(identifier)
inputs[identifier]&.optional
end

Expand Down
43 changes: 17 additions & 26 deletions lib/inferno/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,28 @@ def run_test(test, scratch)
suite_options: test_session.suite_options_hash
)

result = check_inputs(test, test_instance, inputs)

if result.blank?
result = begin
raise Exceptions::CancelException, 'Test cancelled by user' if test_run_is_cancelling

test_instance.load_named_requests
test_instance.instance_eval(&test.block)
'pass'
rescue Exceptions::TestResultException => e
test_instance.result_message = format_markdown(e.message)
e.result
rescue StandardError => e
Application['logger'].error(e.full_message)
test_instance.result_message = format_markdown("Error: #{e.message}\n\n#{e.backtrace.first}")
'error'
end
result = begin
raise Exceptions::CancelException, 'Test cancelled by user' if test_run_is_cancelling
check_inputs(test, test_instance, inputs)

test_instance.load_named_requests
test_instance.instance_eval(&test.block)
'pass'
rescue Exceptions::TestResultException => e
test_instance.result_message = format_markdown(e.message)
e.result
rescue StandardError => e
Application['logger'].error(e.full_message)
test_instance.result_message = format_markdown("Error: #{e.message}\n\n#{e.backtrace.first}")
'error'
end

outputs = save_outputs(test_instance)
output_json_string = JSON.generate(outputs)

if result == 'wait'
test_runs_repo.mark_as_waiting(test_run.id, test_instance.identifier, test_instance.wait_timeout)
end
end

test_result = persist_result(
{
Expand All @@ -117,16 +114,10 @@ def run_test(test, scratch)
end

def check_inputs(test, test_instance, inputs)
result = ''
inputs.each do |key, value|
optional = test.config.input_optional(key)
next unless value.nil? && optional

result = 'skip'
test_instance.result_message = format_markdown("Input '#{key}' is nil, skipping test.")
break
optional = test.config.input_optional?(key)
raise Exceptions::SkipException, "Input '#{test.config.input_name(key)}' is nil, skipping test." if value.nil? && optional
end
result
end

def run_group(group, scratch)
Expand Down

0 comments on commit 697f6b4

Please sign in to comment.