Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FI-2533: Add general test endpoints #472

Merged
merged 14 commits into from
May 10, 2024
Merged
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ AllCops:
- 'vendor/**/*'
- 'lib/inferno/db/schema.rb'
- 'tmp/**/*'
- 'lib/inferno/ext/rack.rb'

Layout/LineLength:
Max: 120
Expand Down
66 changes: 26 additions & 40 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ PATH
base62-rb (= 0.3.1)
blueprinter (= 0.25.2)
dotenv (~> 2.7)
dry-configurable (= 0.13.0)
dry-container (= 0.9.0)
dry-core (= 0.8.1)
dry-inflector (= 0.3)
dry-system (= 0.20.0)
dry-configurable (= 1.0.0)
dry-container (= 0.10.0)
dry-core (= 1.0.0)
dry-inflector (= 1.0.0)
dry-system (= 1.0.0)
faraday (~> 1.2)
faraday_middleware (~> 1.2)
fhir_client (>= 5.0.3)
fhir_models (>= 4.2.2)
hanami-controller (= 2.0.0.beta1)
hanami-controller (= 2.0.0)
hanami-router (= 2.0.0)
oj (= 3.11.0)
pry
Expand Down Expand Up @@ -67,40 +67,25 @@ GEM
docile (1.4.0)
domain_name (0.6.20240107)
dotenv (2.8.1)
dry-auto_inject (0.9.0)
dry-container (>= 0.3.4)
dry-configurable (0.13.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.6)
dry-container (0.9.0)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.13, >= 0.13.0)
dry-core (0.8.1)
concurrent-ruby (~> 1.0)
dry-inflector (0.3.0)
dry-logic (1.2.0)
dry-auto_inject (1.0.1)
dry-core (~> 1.0)
zeitwerk (~> 2.6)
dry-configurable (1.0.0)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-container (0.10.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.5, >= 0.5)
dry-struct (1.4.0)
dry-core (~> 0.5, >= 0.5)
dry-types (~> 1.5)
ice_nine (~> 0.11)
dry-system (0.20.0)
dry-core (1.0.0)
concurrent-ruby (~> 1.0)
dry-auto_inject (>= 0.4.0)
dry-configurable (~> 0.13, >= 0.13.0)
dry-container (~> 0.9, >= 0.9.0)
dry-core (~> 0.5, >= 0.5)
dry-inflector (~> 0.1, >= 0.1.2)
dry-struct (~> 1.0)
zeitwerk (~> 2.6)
dry-inflector (1.0.0)
dry-system (1.0.0)
dry-auto_inject (~> 1.0.0.rc1, < 2)
dry-configurable (~> 1.0, < 2)
dry-core (~> 1.0, < 2)
dry-inflector (~> 1.0, < 2)
dry-transformer (1.0.1)
zeitwerk (~> 2.6)
dry-types (1.5.1)
concurrent-ruby (~> 1.0)
dry-container (~> 0.3)
dry-core (~> 0.5, >= 0.5)
dry-inflector (~> 0.1, >= 0.1.2)
dry-logic (~> 1.0, >= 1.0.2)
factory_bot (6.2.0)
activesupport (>= 5.0.0)
faraday (1.10.3)
Expand Down Expand Up @@ -154,10 +139,12 @@ GEM
date_time_precision (>= 0.8)
mime-types (>= 3.0)
nokogiri (>= 1.11.4)
hanami-controller (2.0.0.beta1)
dry-configurable (~> 0.13, >= 0.13.0)
hanami-utils (~> 2.0.beta)
hanami-controller (2.0.0)
dry-configurable (~> 1.0, < 2)
dry-core (~> 1.0)
hanami-utils (~> 2.0)
rack (~> 2.0)
zeitwerk (~> 2.6)
hanami-router (2.0.0)
mustermann (~> 1.0)
mustermann-contrib (~> 1.0)
Expand All @@ -172,7 +159,6 @@ GEM
domain_name (~> 0.5)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
io-console (0.6.0)
irb (1.6.2)
reline (>= 0.3.0)
Expand Down
25 changes: 25 additions & 0 deletions dev_suites/dev_demo_ig_stu1/demo_endpoint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module DemoIG_STU1 # rubocop:disable Naming/ClassAndModuleCamelCase
class DemoEndpoint < Inferno::DSL::SuiteEndpoint
def test_run_identifier
arscan marked this conversation as resolved.
Show resolved Hide resolved
request.headers['authorization']&.delete_prefix('Bearer ')
end

def make_response
response.status = 200
response.body = { abc: 123 }.to_json
response.format = :json
end

def tags
['abc', 'def']
end

def name
'custom_request'
end

def update_result
results_repo.update(result.id, result: 'pass')
end
end
end
43 changes: 43 additions & 0 deletions dev_suites/dev_demo_ig_stu1/demo_suite.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# require 'onc_certification_g10_test_kit'
require_relative 'demo_endpoint'
require_relative 'groups/demo_group'

module DemoIG_STU1 # rubocop:disable Naming/ClassAndModuleCamelCase
Expand Down Expand Up @@ -299,5 +300,47 @@ class DemoSuite < Inferno::TestSuite
end
end
end

group do
title 'Custom Suite Endpoints'
description %(
This group demonstrates custom suite endpoint functionality.
)

input :custom_bearer_token,
description: 'This bearer token will be used to identify the incoming request'

suite_endpoint :post, '/suite_endpoint', DemoEndpoint
arscan marked this conversation as resolved.
Show resolved Hide resolved

test do
title 'Wait for request to suite endpoint'

run do
wait(
identifier: custom_bearer_token,
message: "Waiting for a POST with bearer token: `#{custom_bearer_token}` to " \
"`#{Inferno::Application['base_url']}/custom/demo/suite_endpoint`"
)
end
end

test do
title 'Named request from suite endpoint'
uses_request :custom_request

run do
assert request.present?, 'Named request not found'
end
end

test do
title 'Tagged request from suite endpoint'

run do
load_tagged_requests('abc', 'def')
assert request.present?, 'Tagged request not found'
end
end
end
end
end
12 changes: 6 additions & 6 deletions inferno_core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'base62-rb', '0.3.1'
spec.add_runtime_dependency 'blueprinter', '0.25.2'
spec.add_runtime_dependency 'dotenv', '~> 2.7'
spec.add_runtime_dependency 'dry-configurable', '0.13.0'
spec.add_runtime_dependency 'dry-container', '0.9.0'
spec.add_runtime_dependency 'dry-core', '0.8.1'
spec.add_runtime_dependency 'dry-inflector', '0.3'
spec.add_runtime_dependency 'dry-system', '0.20.0'
spec.add_runtime_dependency 'dry-configurable', '1.0.0'
spec.add_runtime_dependency 'dry-container', '0.10.0'
spec.add_runtime_dependency 'dry-core', '1.0.0'
spec.add_runtime_dependency 'dry-inflector', '1.0.0'
spec.add_runtime_dependency 'dry-system', '1.0.0'
spec.add_runtime_dependency 'faraday', '~> 1.2'
spec.add_runtime_dependency 'faraday_middleware', '~> 1.2'
spec.add_runtime_dependency 'fhir_client', '>= 5.0.3'
spec.add_runtime_dependency 'fhir_models', '>= 4.2.2'
spec.add_runtime_dependency 'hanami-controller', '2.0.0.beta1'
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 'pry'
Expand Down
10 changes: 7 additions & 3 deletions lib/inferno/apps/web/controllers/controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'hanami/action/mime/request_mime_weight'

module Inferno
module Web
module Controllers
Expand All @@ -11,12 +13,14 @@ def self.inherited(subclass)

subclass.include Import[repo: "inferno.repositories.#{subclass.resource_name}"]

subclass.config.default_request_format = :json
subclass.config.default_response_format = :json

subclass.define_method(:serialize) do |*args|
Inferno::Web::Serializers.const_get(self.class.resource_class).render(*args)
end

# Hanami Controller 2.0.0 removes the ability to set a default
# Content-Type response header, so set it manually if it hasn't been
# set.
subclass.after { |_req, res| res.format = :json if res.format == :all && res.body&.first&.first == '{' }
end

def self.resource_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module Web
module Controllers
module TestSessions
class ClientShow < Controller
config.default_response_format = :html

CLIENT_PAGE =
ERB.new(
File.read(
Expand All @@ -31,6 +29,7 @@ def handle(req, res)

halt 404 if test_suite.nil?

res.format = :html
res.body = CLIENT_PAGE
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/inferno/config/application.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'active_support/all'
require 'dotenv'
require 'dry/system/container'
require 'dry/system'
require 'sequel'
require_relative 'boot'

Expand All @@ -25,7 +25,7 @@ class Application < Dry::System::Container

configure do |config|
config.root = File.expand_path('../../..', __dir__)
config.bootable_dirs = [File.join('lib', 'inferno', 'config', 'boot')]
config.provider_dirs = [File.join('lib', 'inferno', 'config', 'boot')]
config.component_dirs.add 'lib'
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/inferno/config/boot/db.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'sequel'
require 'erb'

Inferno::Application.boot(:db) do
init do
use :logging
Inferno::Application.register_provider(:db) do
prepare do
target_container.start :logging

require 'yaml'

Expand Down
4 changes: 2 additions & 2 deletions lib/inferno/config/boot/logging.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Inferno::Application.boot(:logging) do
init do
Inferno::Application.register_provider(:logging) do
prepare do
logger =
if Inferno::Application.env == :test
log_file_directory = File.join(Dir.pwd, 'tmp')
Expand Down
6 changes: 3 additions & 3 deletions lib/inferno/config/boot/presets.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require_relative '../../repositories/presets'

Inferno::Application.boot(:presets) do
init do
use :suites
Inferno::Application.register_provider(:presets) do
prepare do
target_container.start :suites

files_to_load = Dir.glob(['config/presets/*.json', 'config/presets/*.json.erb'])
files_to_load.map! { |path| File.realpath(path) }
Expand Down
4 changes: 2 additions & 2 deletions lib/inferno/config/boot/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'sidekiq'

Inferno::Application.boot(:sidekiq) do
init do
Inferno::Application.register_provider(:sidekiq) do
prepare do
if Inferno::Application['async_jobs']
Sidekiq.configure_server do |config|
config.redis = { url: ENV.fetch('REDIS_URL', 'redis://127.0.0.1:6379/0') }
Expand Down
6 changes: 3 additions & 3 deletions lib/inferno/config/boot/suites.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Inferno::Application.boot(:suites) do
init do
use :logging
Inferno::Application.register_provider(:suites) do
prepare do
target_container.start :logging

require 'inferno/entities/test'
require 'inferno/entities/test_group'
Expand Down
6 changes: 3 additions & 3 deletions lib/inferno/config/boot/validator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Inferno::Application.boot(:validator) do
init do
use :suites
Inferno::Application.register_provider(:validator) do
prepare do
target_container.start :suites

# This process should only run once, to start one job per validator,
# so skipping it on workers will start it only once from the "web" process
Expand Down
4 changes: 2 additions & 2 deletions lib/inferno/config/boot/web.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Inferno::Application.boot(:web) do |_app|
init do
Inferno::Application.register_provider(:web) do |_app|
prepare do
require 'blueprinter'
require 'hanami/router'
require 'hanami/controller'
Expand Down
1 change: 1 addition & 0 deletions lib/inferno/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_relative 'dsl/http_client'
require_relative 'dsl/results'
require_relative 'dsl/runnable'
require_relative 'dsl/suite_endpoint'

module Inferno
# The DSL for writing tests.
Expand Down
Loading
Loading