From b2af2fdabcc29fa27113c7ca84f8898543b4001b Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 8 Nov 2023 15:58:14 -0500 Subject: [PATCH 01/50] skeleton new thor command --- lib/inferno/apps/cli/main.rb | 7 +++++++ lib/inferno/apps/cli/new.rb | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 lib/inferno/apps/cli/new.rb diff --git a/lib/inferno/apps/cli/main.rb b/lib/inferno/apps/cli/main.rb index ad7f1c353..1306551ad 100644 --- a/lib/inferno/apps/cli/main.rb +++ b/lib/inferno/apps/cli/main.rb @@ -3,6 +3,7 @@ require_relative 'services' require_relative 'suite' require_relative 'suites' +require_relative 'new' module Inferno module CLI @@ -49,6 +50,12 @@ def suites desc 'suite SUBCOMMAND ...ARGS', 'Perform suite-based operations' subcommand 'suite', Suite + + map 'new' => :new_app + desc 'new', 'Generate a new Inferno test kit' + def new_app + New.new.run + end end end end diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb new file mode 100644 index 000000000..3773201c3 --- /dev/null +++ b/lib/inferno/apps/cli/new.rb @@ -0,0 +1,9 @@ +module Inferno + module CLI + class New + def run + puts "you called inferno new" + end + end + end +end From b5e5fe19037f5f2d13bc18595413d15353125cad Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 8 Nov 2023 16:13:48 -0500 Subject: [PATCH 02/50] add positional argument to new generator --- lib/inferno/apps/cli/main.rb | 6 +++--- lib/inferno/apps/cli/new.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/inferno/apps/cli/main.rb b/lib/inferno/apps/cli/main.rb index 1306551ad..538e3ad86 100644 --- a/lib/inferno/apps/cli/main.rb +++ b/lib/inferno/apps/cli/main.rb @@ -52,9 +52,9 @@ def suites subcommand 'suite', Suite map 'new' => :new_app - desc 'new', 'Generate a new Inferno test kit' - def new_app - New.new.run + desc 'new TEST_KIT_NAME', 'Generate a new Inferno test kit' + def new_app(name) + New.new.run(name) end end end diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index 3773201c3..66e07d72c 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -1,8 +1,8 @@ module Inferno module CLI class New - def run - puts "you called inferno new" + def run(name) + puts "This will generate a new inferno test kit called #{name}" end end end From 8c44974fc430396ffb7201019d05047406e25151 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 8 Nov 2023 17:06:16 -0500 Subject: [PATCH 03/50] add dry-inflections dep and naming helper methods --- Gemfile.lock | 1 + inferno_core.gemspec | 1 + lib/inferno/apps/cli/main.rb | 7 +++++- lib/inferno/apps/cli/new.rb | 41 ++++++++++++++++++++++++++++++++++-- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d58cc00b8..ee1716aa6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,6 +9,7 @@ PATH dry-configurable (= 0.13.0) dry-container (= 0.9.0) dry-core (= 0.8.1) + dry-inflector (= 0.3) dry-system (= 0.20.0) faraday (~> 1.2) faraday_middleware (~> 1.2) diff --git a/inferno_core.gemspec b/inferno_core.gemspec index b49d64cf8..4aef9f055 100644 --- a/inferno_core.gemspec +++ b/inferno_core.gemspec @@ -18,6 +18,7 @@ Gem::Specification.new do |spec| 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 'faraday', '~> 1.2' spec.add_runtime_dependency 'faraday_middleware', '~> 1.2' diff --git a/lib/inferno/apps/cli/main.rb b/lib/inferno/apps/cli/main.rb index 538e3ad86..4cfd1326e 100644 --- a/lib/inferno/apps/cli/main.rb +++ b/lib/inferno/apps/cli/main.rb @@ -53,8 +53,13 @@ def suites map 'new' => :new_app desc 'new TEST_KIT_NAME', 'Generate a new Inferno test kit' + option :implementation_guide, + default: nil, + type: :string, + aliases: '-i', + desc: "URL to an implementation guide to load" def new_app(name) - New.new.run(name) + New.new.run(name, options[:implementation_guide]) end end end diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index 66e07d72c..4c6dc7f2a 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -1,9 +1,46 @@ +require 'dry/inflector' + module Inferno module CLI class New - def run(name) - puts "This will generate a new inferno test kit called #{name}" + + @@inflector = Dry::Inflector.new do |inflections| + # TODO add custom inflections here... if we want to + # inflections.acronym 'FHIR', 'HTTP' end + + def run(name, implementation_guide = nil) + @name = name + + puts "This will generate a new inferno test kit called #{name} with #{implementation_guide || 'no'} IG" + puts '' + puts 'Names:' + {'folder': folder_name, 'lib': lib_name, 'file': file_name, 'module': module_name}.each do |k, v| + puts "#{k}: #{v}" + end + end + + private + # root folder name, i.e: inferno-template + def folder_name + @@inflector.dasherize(@name) + end + + # lib folder name, i.e: inferno_template + def lib_name + @@inflector.underscore(@name) + end + + # file name with suffix extension, i.e: inferno_template.rb + def file_name(suffix = '.rb') + @@inflector.underscore(@name) + suffix + end + + # module name, i.e: InfernoTemplate + def module_name + @@inflector.camelize(@name) + end + end end end From 261d4fb2bf4fa5056e2a0fb62e98513ae02d72e0 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Thu, 9 Nov 2023 20:18:04 -0500 Subject: [PATCH 04/50] github clone based implementation --- Gemfile.lock | 2 ++ inferno_core.gemspec | 1 + lib/inferno/apps/cli/new.rb | 57 ++++++++++++++++++++++++++++++++----- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ee1716aa6..c8e5780dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,6 +22,7 @@ PATH pry-byebug puma (~> 5.6.7) rake (~> 13.0) + rubyzip (= 2.3.2) sequel (~> 5.42.0) sidekiq (~> 6.5.6) sqlite3 (~> 1.4) @@ -269,6 +270,7 @@ GEM rubocop (~> 1.0) ruby-progressbar (1.11.0) ruby2_keywords (0.0.5) + rubyzip (2.3.2) sequel (5.42.0) sidekiq (6.5.12) connection_pool (>= 2.2.5, < 3) diff --git a/inferno_core.gemspec b/inferno_core.gemspec index 4aef9f055..ada391471 100644 --- a/inferno_core.gemspec +++ b/inferno_core.gemspec @@ -31,6 +31,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'pry-byebug' spec.add_runtime_dependency 'puma', '~> 5.6.7' spec.add_runtime_dependency 'rake', '~> 13.0' + spec.add_runtime_dependency 'rubyzip', '2.3.2' spec.add_runtime_dependency 'sequel', '~> 5.42.0' spec.add_runtime_dependency 'sidekiq', '~> 6.5.6' spec.add_runtime_dependency 'sqlite3', '~> 1.4' diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index 4c6dc7f2a..600bfb4ed 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -1,22 +1,44 @@ require 'dry/inflector' +require 'faraday' +require 'zip' module Inferno module CLI class New @@inflector = Dry::Inflector.new do |inflections| - # TODO add custom inflections here... if we want to - # inflections.acronym 'FHIR', 'HTTP' + inflections.acronym 'FHIR' end + GITHUB_TEMPLATE_URL = 'https://codeload.github.com/inferno-framework/inferno-template/legacy.zip/refs/heads/main' + def run(name, implementation_guide = nil) @name = name - puts "This will generate a new inferno test kit called #{name} with #{implementation_guide || 'no'} IG" - puts '' - puts 'Names:' - {'folder': folder_name, 'lib': lib_name, 'file': file_name, 'module': module_name}.each do |k, v| - puts "#{k}: #{v}" + github_template_response = Faraday.get(GITHUB_TEMPLATE_URL) + raise StandardError.new('Failed to download inferno-framework/inferno-template from GitHub.') unless github_template_response.status == 200 + + mkdir_p folder_name + extract_zip(github_template_response.body) do |name_to_sub, path, contents| + # preform all template substitutions + path.gsub! name_to_sub, folder_name + path.gsub! 'inferno-template', folder_name + path.gsub! 'inferno_template', lib_name + + contents.gsub! 'InfernoTemplate', module_name + contents.gsub! 'inferno_template', lib_name + contents.gsub! 'Inferno Template', human_name + contents.gsub! 'Inferno Test Kit Template', human_name + contents.gsub! 'Inferno Team', 'TODO' + contents.gsub! 'inferno@groups.mitre.org', 'TODO@example.com' + + unless File.exists?(path) + FileUtils.mkdir_p(File.dirname(path)) + File.create(path) do |f| + f.write(contents) + end + puts "created #{path}" + end end end @@ -41,6 +63,27 @@ def module_name @@inflector.camelize(@name) end + # English grammatical name, i.e: Inferno template + def human_name + @@inflector.humanize(@name) + end + + def extract_zip(zip_binary, &block) + # requires block: + # yields: name to sub, file path, file contents + + zip_stream = Zip::InputStream.new(StringIO.new(zip_binary)) + original_name = zip_stream.get_next_entry.name + + while zip_entry = zip_stream.get_next_entry + # unless File.exist?(zip_entry.name) + # FileUtils::mkdir_p(File.dirname(zip_entry.name)) + # zip_stream.extract(zip_entry, zip_entry.name) + # end + yield(original_name, zip_entry.name, zip_entry.get_input_stream.read) + end + end + end end end From f733014d9cd38da071540f392e0ae480b4d10823 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Fri, 10 Nov 2023 14:05:21 -0500 Subject: [PATCH 05/50] restructure to use erb templating implementation --- lib/inferno/apps/cli/main.rb | 2 +- lib/inferno/apps/cli/new.rb | 89 ------ lib/inferno/apps/cli/new/new.rb | 53 ++++ .../apps/cli/new/templates/.dockerignore | 22 ++ lib/inferno/apps/cli/new/templates/.env | 1 + .../apps/cli/new/templates/.env.development | 2 + .../apps/cli/new/templates/.env.production | 2 + lib/inferno/apps/cli/new/templates/.env.test | 2 + lib/inferno/apps/cli/new/templates/.gitignore | 20 ++ lib/inferno/apps/cli/new/templates/.rspec | 1 + .../apps/cli/new/templates/.ruby-version | 1 + .../apps/cli/new/templates/.tool-versions | 1 + lib/inferno/apps/cli/new/templates/Dockerfile | 22 ++ lib/inferno/apps/cli/new/templates/Gemfile | 9 + .../apps/cli/new/templates/Gemfile.lock | 278 ++++++++++++++++++ lib/inferno/apps/cli/new/templates/LICENSE | 201 +++++++++++++ lib/inferno/apps/cli/new/templates/Procfile | 2 + lib/inferno/apps/cli/new/templates/README.md | 201 +++++++++++++ lib/inferno/apps/cli/new/templates/Rakefile | 15 + lib/inferno/apps/cli/new/templates/config.ru | 11 + .../cli/new/templates/config/database.yml | 18 ++ .../templates/config/nginx.background.conf | 86 ++++++ .../apps/cli/new/templates/config/nginx.conf | 101 +++++++ .../apps/cli/new/templates/config/puma.rb | 2 + lib/inferno/apps/cli/new/templates/data/.keep | 0 .../apps/cli/new/templates/data/redis/.keep | 0 .../templates/docker-compose.background.yml | 30 ++ .../apps/cli/new/templates/docker-compose.yml | 35 +++ .../new/templates/inferno_template.gemspec | 26 ++ .../cli/new/templates/lib/inferno_template.rb | 53 ++++ .../igs/put_ig_package_dot_tgz_here | 0 .../lib/inferno_template/patient_group.rb | 44 +++ lib/inferno/apps/cli/new/templates/run.sh | 3 + lib/inferno/apps/cli/new/templates/setup.sh | 4 + .../inferno_template/patient_group_spec.rb | 105 +++++++ .../cli/new/templates/spec/spec_helper.rb | 141 +++++++++ lib/inferno/apps/cli/new/templates/worker.rb | 3 + 37 files changed, 1496 insertions(+), 90 deletions(-) delete mode 100644 lib/inferno/apps/cli/new.rb create mode 100644 lib/inferno/apps/cli/new/new.rb create mode 100644 lib/inferno/apps/cli/new/templates/.dockerignore create mode 100644 lib/inferno/apps/cli/new/templates/.env create mode 100644 lib/inferno/apps/cli/new/templates/.env.development create mode 100644 lib/inferno/apps/cli/new/templates/.env.production create mode 100644 lib/inferno/apps/cli/new/templates/.env.test create mode 100644 lib/inferno/apps/cli/new/templates/.gitignore create mode 100644 lib/inferno/apps/cli/new/templates/.rspec create mode 100644 lib/inferno/apps/cli/new/templates/.ruby-version create mode 100644 lib/inferno/apps/cli/new/templates/.tool-versions create mode 100644 lib/inferno/apps/cli/new/templates/Dockerfile create mode 100644 lib/inferno/apps/cli/new/templates/Gemfile create mode 100644 lib/inferno/apps/cli/new/templates/Gemfile.lock create mode 100644 lib/inferno/apps/cli/new/templates/LICENSE create mode 100644 lib/inferno/apps/cli/new/templates/Procfile create mode 100644 lib/inferno/apps/cli/new/templates/README.md create mode 100644 lib/inferno/apps/cli/new/templates/Rakefile create mode 100644 lib/inferno/apps/cli/new/templates/config.ru create mode 100644 lib/inferno/apps/cli/new/templates/config/database.yml create mode 100644 lib/inferno/apps/cli/new/templates/config/nginx.background.conf create mode 100644 lib/inferno/apps/cli/new/templates/config/nginx.conf create mode 100644 lib/inferno/apps/cli/new/templates/config/puma.rb create mode 100644 lib/inferno/apps/cli/new/templates/data/.keep create mode 100644 lib/inferno/apps/cli/new/templates/data/redis/.keep create mode 100644 lib/inferno/apps/cli/new/templates/docker-compose.background.yml create mode 100644 lib/inferno/apps/cli/new/templates/docker-compose.yml create mode 100644 lib/inferno/apps/cli/new/templates/inferno_template.gemspec create mode 100644 lib/inferno/apps/cli/new/templates/lib/inferno_template.rb create mode 100644 lib/inferno/apps/cli/new/templates/lib/inferno_template/igs/put_ig_package_dot_tgz_here create mode 100644 lib/inferno/apps/cli/new/templates/lib/inferno_template/patient_group.rb create mode 100755 lib/inferno/apps/cli/new/templates/run.sh create mode 100755 lib/inferno/apps/cli/new/templates/setup.sh create mode 100644 lib/inferno/apps/cli/new/templates/spec/inferno_template/patient_group_spec.rb create mode 100644 lib/inferno/apps/cli/new/templates/spec/spec_helper.rb create mode 100644 lib/inferno/apps/cli/new/templates/worker.rb diff --git a/lib/inferno/apps/cli/main.rb b/lib/inferno/apps/cli/main.rb index 4cfd1326e..891f03d54 100644 --- a/lib/inferno/apps/cli/main.rb +++ b/lib/inferno/apps/cli/main.rb @@ -3,7 +3,7 @@ require_relative 'services' require_relative 'suite' require_relative 'suites' -require_relative 'new' +require_relative 'new/new' module Inferno module CLI diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb deleted file mode 100644 index 600bfb4ed..000000000 --- a/lib/inferno/apps/cli/new.rb +++ /dev/null @@ -1,89 +0,0 @@ -require 'dry/inflector' -require 'faraday' -require 'zip' - -module Inferno - module CLI - class New - - @@inflector = Dry::Inflector.new do |inflections| - inflections.acronym 'FHIR' - end - - GITHUB_TEMPLATE_URL = 'https://codeload.github.com/inferno-framework/inferno-template/legacy.zip/refs/heads/main' - - def run(name, implementation_guide = nil) - @name = name - - github_template_response = Faraday.get(GITHUB_TEMPLATE_URL) - raise StandardError.new('Failed to download inferno-framework/inferno-template from GitHub.') unless github_template_response.status == 200 - - mkdir_p folder_name - extract_zip(github_template_response.body) do |name_to_sub, path, contents| - # preform all template substitutions - path.gsub! name_to_sub, folder_name - path.gsub! 'inferno-template', folder_name - path.gsub! 'inferno_template', lib_name - - contents.gsub! 'InfernoTemplate', module_name - contents.gsub! 'inferno_template', lib_name - contents.gsub! 'Inferno Template', human_name - contents.gsub! 'Inferno Test Kit Template', human_name - contents.gsub! 'Inferno Team', 'TODO' - contents.gsub! 'inferno@groups.mitre.org', 'TODO@example.com' - - unless File.exists?(path) - FileUtils.mkdir_p(File.dirname(path)) - File.create(path) do |f| - f.write(contents) - end - puts "created #{path}" - end - end - end - - private - # root folder name, i.e: inferno-template - def folder_name - @@inflector.dasherize(@name) - end - - # lib folder name, i.e: inferno_template - def lib_name - @@inflector.underscore(@name) - end - - # file name with suffix extension, i.e: inferno_template.rb - def file_name(suffix = '.rb') - @@inflector.underscore(@name) + suffix - end - - # module name, i.e: InfernoTemplate - def module_name - @@inflector.camelize(@name) - end - - # English grammatical name, i.e: Inferno template - def human_name - @@inflector.humanize(@name) - end - - def extract_zip(zip_binary, &block) - # requires block: - # yields: name to sub, file path, file contents - - zip_stream = Zip::InputStream.new(StringIO.new(zip_binary)) - original_name = zip_stream.get_next_entry.name - - while zip_entry = zip_stream.get_next_entry - # unless File.exist?(zip_entry.name) - # FileUtils::mkdir_p(File.dirname(zip_entry.name)) - # zip_stream.extract(zip_entry, zip_entry.name) - # end - yield(original_name, zip_entry.name, zip_entry.get_input_stream.read) - end - end - - end - end -end diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb new file mode 100644 index 000000000..e5b7ac22e --- /dev/null +++ b/lib/inferno/apps/cli/new/new.rb @@ -0,0 +1,53 @@ +require 'dry/inflector' +require 'thor' + +module Inferno + module CLI + class New < Thor + include Thor::Actions + + @@inflector = Dry::Inflector.new do |inflections| + inflections.acronym 'FHIR' + end + + def self.source_root + File.join(__dir__, 'templates') + end + + def run(name, implementation_guide = nil) + @name = name + + ## This defines the new inferno-template: + empty_directory(folder_name) + template( + + end + + private + # root folder name, i.e: inferno-template + def folder_name + @@inflector.dasherize(@name) + end + + # lib folder name, i.e: inferno_template + def lib_name + @@inflector.underscore(@name) + end + + # file name with suffix extension, i.e: inferno_template.rb + def file_name(suffix = '.rb') + @@inflector.underscore(@name) + suffix + end + + # module name, i.e: InfernoTemplate + def module_name + @@inflector.camelize(@name) + end + + # English grammatical name, i.e: Inferno template + def human_name + @@inflector.humanize(@name) + end + end + end +end diff --git a/lib/inferno/apps/cli/new/templates/.dockerignore b/lib/inferno/apps/cli/new/templates/.dockerignore new file mode 100644 index 000000000..aaf9ca5ca --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/.dockerignore @@ -0,0 +1,22 @@ +.env.local +.env.*.local +.env.development +.env.test +Dockerfile +.gitignore + +.byebug_history +**/.DS_Store +.vscode/* +.project +.settings/.jsdtscope +.settings/org.eclipse.wst.jsdt.ui.superType.container +.settings/org.eclipse.wst.jsdt.ui.superType.name +.idea + +/coverage +/data +/.git +/.github +/log +/tmp diff --git a/lib/inferno/apps/cli/new/templates/.env b/lib/inferno/apps/cli/new/templates/.env new file mode 100644 index 000000000..d3cc9c6b2 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/.env @@ -0,0 +1 @@ +JS_HOST="" diff --git a/lib/inferno/apps/cli/new/templates/.env.development b/lib/inferno/apps/cli/new/templates/.env.development new file mode 100644 index 000000000..da8a32249 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/.env.development @@ -0,0 +1,2 @@ +VALIDATOR_URL=http://localhost/validatorapi +REDIS_URL=redis://localhost:6379/0 \ No newline at end of file diff --git a/lib/inferno/apps/cli/new/templates/.env.production b/lib/inferno/apps/cli/new/templates/.env.production new file mode 100644 index 000000000..0f832e3e2 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/.env.production @@ -0,0 +1,2 @@ +REDIS_URL=redis://redis:6379/0 +VALIDATOR_URL=http://validator_service:4567 \ No newline at end of file diff --git a/lib/inferno/apps/cli/new/templates/.env.test b/lib/inferno/apps/cli/new/templates/.env.test new file mode 100644 index 000000000..9e95769c3 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/.env.test @@ -0,0 +1,2 @@ +VALIDATOR_URL=https://example.com/validatorapi +ASYNC_JOBS=false diff --git a/lib/inferno/apps/cli/new/templates/.gitignore b/lib/inferno/apps/cli/new/templates/.gitignore new file mode 100644 index 000000000..ee52933af --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/.gitignore @@ -0,0 +1,20 @@ +/data/*.db +/data/redis/**/*.rdb +/data/redis/**/*.aof +/data/redis/**/*.manifest +/tmp +.env.local +.env.*.local +**/.DS_Store +.vscode/* +.project +.settings/.jsdtscope +.settings/org.eclipse.wst.jsdt.ui.superType.container +.settings/org.eclipse.wst.jsdt.ui.superType.name +.idea + +/coverage +/spec/examples.txt +/docs/yard +.yardoc +node_modules diff --git a/lib/inferno/apps/cli/new/templates/.rspec b/lib/inferno/apps/cli/new/templates/.rspec new file mode 100644 index 000000000..c99d2e739 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/lib/inferno/apps/cli/new/templates/.ruby-version b/lib/inferno/apps/cli/new/templates/.ruby-version new file mode 100644 index 000000000..6ebad1488 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/.ruby-version @@ -0,0 +1 @@ +3.1.2 \ No newline at end of file diff --git a/lib/inferno/apps/cli/new/templates/.tool-versions b/lib/inferno/apps/cli/new/templates/.tool-versions new file mode 100644 index 000000000..b8ab7eae2 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/.tool-versions @@ -0,0 +1 @@ +ruby 3.1.2 \ No newline at end of file diff --git a/lib/inferno/apps/cli/new/templates/Dockerfile b/lib/inferno/apps/cli/new/templates/Dockerfile new file mode 100644 index 000000000..d32710caf --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/Dockerfile @@ -0,0 +1,22 @@ +FROM ruby:3.1.2 + +ENV INSTALL_PATH=/opt/inferno/ +ENV APP_ENV=production +RUN mkdir -p $INSTALL_PATH + +WORKDIR $INSTALL_PATH + +ADD *.gemspec $INSTALL_PATH +ADD Gemfile* $INSTALL_PATH +RUN gem install bundler +# The below RUN line is commented out for development purposes, because any change to the +# required gems will break the dockerfile build process. +# If you want to run in Deploy mode, just run `bundle install` locally to update +# Gemfile.lock, and uncomment the following line. +# RUN bundle config set --local deployment 'true' +RUN bundle install + +ADD . $INSTALL_PATH + +EXPOSE 4567 +CMD ["bundle", "exec", "puma"] diff --git a/lib/inferno/apps/cli/new/templates/Gemfile b/lib/inferno/apps/cli/new/templates/Gemfile new file mode 100644 index 000000000..382378ec4 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/Gemfile @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gemspec + +group :development, :test do + gem 'debug' +end diff --git a/lib/inferno/apps/cli/new/templates/Gemfile.lock b/lib/inferno/apps/cli/new/templates/Gemfile.lock new file mode 100644 index 000000000..dedb86273 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/Gemfile.lock @@ -0,0 +1,278 @@ +PATH + remote: . + specs: + inferno_template (0.0.1) + inferno_core (~> 0.4.4) + +GEM + remote: https://rubygems.org/ + specs: + activesupport (6.1.7) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) + bcp47 (0.3.3) + i18n + blueprinter (0.25.2) + byebug (11.1.3) + coderay (1.1.3) + concurrent-ruby (1.1.10) + connection_pool (2.3.0) + crack (0.4.5) + rexml + database_cleaner (1.99.0) + database_cleaner-sequel (1.99.0) + database_cleaner (~> 1.99.0) + sequel + date_time_precision (0.8.1) + debug (1.6.3) + irb (>= 1.3.6) + reline (>= 0.3.1) + diff-lcs (1.5.0) + domain_name (0.5.20190701) + unf (>= 0.0.5, < 1.0.0) + 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) + 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) + 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) + 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.2) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.0) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + faraday-retry (~> 1.0) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-httpclient (1.0.1) + faraday-multipart (1.0.4) + multipart-post (~> 2) + faraday-net_http (1.0.1) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday-retry (1.0.3) + faraday_middleware (1.2.0) + faraday (~> 1.0) + fhir_client (5.0.3) + activesupport (>= 3) + addressable (>= 2.3) + fhir_dstu2_models (>= 1.1.1) + fhir_models (>= 4.2.1) + fhir_stu3_models (>= 3.1.1) + nokogiri (>= 1.10.4) + oauth2 (~> 1.1) + rack (>= 1.5) + rest-client (~> 2.0) + tilt (>= 1.1) + fhir_dstu2_models (1.1.1) + bcp47 (>= 0.3) + date_time_precision (>= 0.8) + mime-types (>= 3.0) + nokogiri (>= 1.11.4) + fhir_models (4.2.2) + bcp47 (>= 0.3) + date_time_precision (>= 0.8) + mime-types (>= 3.0) + nokogiri (>= 1.11.4) + fhir_stu3_models (3.1.1) + bcp47 (>= 0.3) + 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) + rack (~> 2.0) + hanami-router (2.0.0) + mustermann (~> 1.0) + mustermann-contrib (~> 1.0) + rack (~> 2.0) + hanami-utils (2.0.0) + concurrent-ruby (~> 1.0) + dry-transformer (~> 1.0, < 2) + hansi (0.2.1) + hashdiff (1.0.1) + http-accept (1.7.0) + http-cookie (1.0.5) + domain_name (~> 0.5) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + ice_nine (0.11.2) + inferno_core (0.4.5) + activesupport (~> 6.1) + blueprinter (= 0.25.2) + dotenv (~> 2.7) + dry-configurable (= 0.13.0) + dry-container (= 0.9.0) + dry-core (= 0.8.1) + dry-system (= 0.20.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-router (= 2.0.0) + oj (= 3.11.0) + pry + pry-byebug + puma (~> 5.3) + rake (~> 13.0) + sequel (~> 5.42.0) + sidekiq (~> 6.5.6) + sqlite3 (~> 1.4) + thor (~> 1.2.1) + io-console (0.5.11) + irb (1.4.2) + reline (>= 0.3.0) + jwt (2.5.0) + method_source (1.0.0) + mime-types (3.4.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2022.0105) + mini_portile2 (2.8.0) + minitest (5.16.3) + multi_json (1.15.0) + multi_xml (0.6.0) + multipart-post (2.2.3) + mustermann (1.1.2) + ruby2_keywords (~> 0.0.1) + mustermann-contrib (1.1.2) + hansi (~> 0.2.0) + mustermann (= 1.1.2) + netrc (0.11.0) + nio4r (2.5.8) + nokogiri (1.13.9) + mini_portile2 (~> 2.8.0) + racc (~> 1.4) + nokogiri (1.13.9-arm64-darwin) + racc (~> 1.4) + nokogiri (1.13.9-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.13.9-x86_64-linux) + racc (~> 1.4) + oauth2 (1.4.11) + faraday (>= 0.17.3, < 3.0) + jwt (>= 1.0, < 3.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 4) + oj (3.11.0) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.10.1) + byebug (~> 11.0) + pry (>= 0.13, < 0.15) + public_suffix (5.0.0) + puma (5.6.5) + nio4r (~> 2.0) + racc (1.6.0) + rack (2.2.4) + rake (13.0.6) + redis (4.8.0) + reline (0.3.1) + io-console (~> 0.5) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) + rexml (3.2.5) + rspec (3.11.0) + rspec-core (~> 3.11.0) + rspec-expectations (~> 3.11.0) + rspec-mocks (~> 3.11.0) + rspec-core (3.11.0) + rspec-support (~> 3.11.0) + rspec-expectations (3.11.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.11.0) + rspec-mocks (3.11.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.11.0) + rspec-support (3.11.0) + ruby2_keywords (0.0.5) + sequel (5.42.0) + sidekiq (6.5.8) + connection_pool (>= 2.2.5, < 3) + rack (~> 2.0) + redis (>= 4.5.0, < 5) + sqlite3 (1.5.4) + mini_portile2 (~> 2.8.0) + sqlite3 (1.5.4-arm64-darwin) + sqlite3 (1.5.4-x86_64-darwin) + sqlite3 (1.5.4-x86_64-linux) + thor (1.2.1) + tilt (2.0.11) + tzinfo (2.0.5) + concurrent-ruby (~> 1.0) + unf (0.1.4) + unf_ext + unf_ext (0.0.8.2) + webmock (3.14.0) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + zeitwerk (2.6.6) + +PLATFORMS + arm64-darwin-21 + ruby + x86_64-darwin-19 + x86_64-darwin-20 + x86_64-linux + +DEPENDENCIES + database_cleaner-sequel (~> 1.8) + debug + factory_bot (~> 6.1) + inferno_template! + rspec (~> 3.10) + webmock (~> 3.11) + +BUNDLED WITH + 2.3.14 diff --git a/lib/inferno/apps/cli/new/templates/LICENSE b/lib/inferno/apps/cli/new/templates/LICENSE new file mode 100644 index 000000000..8dada3eda --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/lib/inferno/apps/cli/new/templates/Procfile b/lib/inferno/apps/cli/new/templates/Procfile new file mode 100644 index 000000000..4f784b9cc --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/Procfile @@ -0,0 +1,2 @@ +web: bundle exec puma +worker: bundle exec sidekiq -r ./worker.rb diff --git a/lib/inferno/apps/cli/new/templates/README.md b/lib/inferno/apps/cli/new/templates/README.md new file mode 100644 index 000000000..f9d125d0b --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/README.md @@ -0,0 +1,201 @@ +# Inferno Template + +This is a template repository for an +[Inferno](https://github.com/inferno-community/inferno-core) test kit. + +## Documentation +- [Inferno documentation](https://inferno-framework.github.io/inferno-core/) +- [Ruby API documentation](https://inferno-framework.github.io/inferno-core/docs) +- [JSON API documentation](https://inferno-framework.github.io/inferno-core/api-docs) + +## Instructions for Developing tests + +- Clone this repo/Click "Use this template" on github. +- Run `setup.sh` in this repo to pull the needed docker images and set up the + database. +- Put the `package.tgz` for the IG you're writing tests for in + `lib/your_test_kit_name/igs` and update this path in + `docker-compose.background.yml`. + This will ensure that the validator has access to the resources needed to + validate resources against your IG. + +All tests you write should go in the `lib` folder, which currently contains some +example tests. Refer to the [Inferno +documentation](https://inferno-framework.github.io/inferno-core/) for more +information about the specifics of writing tests. + +### Development with Docker vs Docker + ruby +Tests can be developed with or without a local ruby installation using docker. +However, it takes much longer to build/start/stop docker than to start/stop +native ruby processes. Inferno needs to be restarted whenever tests change, so +you will be starting and stopping it often during test development. For this +reason, it is highly recommended that you install ruby and do not rely solely on +docker for development if possible. + +### Development with Docker only +- Run `run.sh` to build your tests and run inferno. You will need to stop and + re-run this whenever you make changes to your tests. +- Navigate to `http://localhost` to access Inferno, where your test suite will + be available. To access the HL7® FHIR® resource validator, navigate to + `http://localhost/validator`. + +### Development with ruby +It is highly recommended that you install ruby via a [ruby version +manager](https://www.ruby-lang.org/en/documentation/installation/#managers). When you + +- Run `bundle install` to install dependencies. +- Run `bundle exec inferno migrate` to set up the database. +- Run `gem install foreman` to install foreman, which will be used to run the + Inferno web and worker processes. +- Run `bundle exec inferno services start` to start the background services. By + default, these include nginx, redis, the FHIR validator service, and the FHIR + validator UI. Background services can be added/removed/edited in + `docker-compose.background.yml`. +- Run `inferno start` to start Inferno. You will need to stop and re-run this + whenever you make changes to your tests. +- Navigate to `http://localhost:4567` to access Inferno, where your test suite will + be available. To access the FHIR resource validator, navigate to + `http://localhost/validator`. +- When you are done, run `bundle exec inferno services stop` to stop the + background services. + +#### Interactive consoles +A local ruby installation also allows you to use [pry](https://pry.github.io/), +a powerful interactive console to explore and experiment with your tests with +`inferno console`: +```ruby +ᐅ bundle exec inferno console +[1] pry(main)> suite = InfernoTemplate::Suite +=> InfernoTemplate::Suite +[2] pry(main)> suite.groups +=> [#, #] +[3] pry(main)> suite.groups.map(&:title) +=> ["Capability Statement", "Patient Tests"] +[4] pry(main)> suite.groups.first.tests.map(&:title) +=> ["Read CapabilityStatement"] +``` + +It is also possible to set a breakpoint using the [debug +gem](https://github.com/ruby/debug) within a test's `run` block to debug test +behavior: +- Add `require 'debug/open_nonstop'` and `debugger` to set the breakpoint. +- Run your tests until the breakpoint is reached. +- In a separate terminal window, run `bundle exec rdbg -A` to access the + interactive console. + +```ruby +module InfernoTemplate + class PatientGroup < Inferno::TestGroup + ... + test do + ... + run do + fhir_read(:patient, patient_id, name: :patient) + + require 'debug/open_nonstop' + debugger + + assert_response_status(200) + assert_resource_type(:patient) + assert resource.id == patient_id, + "Requested resource with id #{patient_id}, received resource with id #{resource.id}" + end + end + end +end +``` + +```ruby +ᐅ bundle exec rdbg -A +DEBUGGER (client): Connected. PID:22112, $0:sidekiq 6.5.7 [0 of 10 busy] + +[18, 27] in ~/code/inferno-template/lib/inferno_template/patient_group.rb + 18| + 19| run do + 20| fhir_read(:patient, patient_id, name: :patient) + 21| + 22| require 'debug/open_nonstop' +=> 23| debugger + 24| + 25| assert_response_status(200) + 26| assert_resource_type(:patient) + 27| assert resource.id == patient_id, +(ruby:remote) self.id +"test_suite_template-patient_group-Test01" +(ruby:remote) self.title +"Server returns requested Patient resource from the Patient read interaction" +(rdbg:remote) inputs +[:patient_id, :url, :credentials] +(ruby:remote) patient_id +"85" +(rdbg:remote) url +"https://inferno.healthit.gov/reference-server/r4" +(rdbg:remote) ls request # outline command +Inferno::Entities::Request#methods: + created_at created_at= direction direction= headers headers= id id= index index= name name= + query_parameters request request_body request_body= request_header request_headers resource response response_body response_body= response_header response_headers + result_id result_id= status status= test_session_id test_session_id= to_hash updated_at updated_at= url url= verb + verb= +instance variables: @created_at @direction @headers @id @index @name @request_body @response_body @result_id @status @test_session_id @updated_at @url @verb +(ruby:remote) request.status +200 +(ruby:remote) request.response_body +"{\n \"resourceType\": \"Patient\" ... }" +(rdbg:remote) ? # help command + +### Control flow + +* `s[tep]` + * Step in. Resume the program until next breakable point. +... +``` + +## Distributing tests + +In order to make your test suite available to others, it needs to be organized +like a standard ruby gem (ruby libraries are called gems). + +- Fill in the information in the `gemspec` file in the root of this repository. + The name of this file should match the `spec.name` within the file. This will + be the name of the gem you create. For example, if your file is + `my_test_kit.gemspec` and its `spec.name` is `'my_test_kit'`, then others will + be able to install your gem with `gem install my_test_kit`. There are + [recommended naming conventions for + gems](https://guides.rubygems.org/name-your-gem/). +- Your tests must be in `lib` +- `lib` should contain only one file. All other files should be in a + subdirectory. The file in lib be what people use to import your gem after they + have installed it. For example, if your test kit contains a file + `lib/my_test_suite.rb`, then after installing your test kit gem, I could + include your test suite with `require 'my_test_suite'`. +- **Optional:** Once your gemspec file has been updated, you can publish your + gem on [rubygems, the official ruby gem repository](https://rubygems.org/). If + you don't publish your gem on rubygems, users will still be able to install it + if it is located in a public git repository. To publish your gem on rubygems, + you will first need to [make an account on + rubygems](https://guides.rubygems.org/publishing/#publishing-to-rubygemsorg) + and then run `gem build *.gemspec` and `gem push *.gem`. + +## Example Inferno test kits + +- https://github.com/inferno-community/ips-test-kit +- https://github.com/inferno-community/shc-vaccination-test-kit + +## License +Copyright 2022 The MITRE Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at +``` +http://www.apache.org/licenses/LICENSE-2.0 +``` +Unless required by applicable law or agreed to in writing, software distributed +under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. + +## Trademark Notice + +HL7, FHIR and the FHIR [FLAME DESIGN] are the registered trademarks of Health +Level Seven International and their use does not constitute endorsement by HL7. diff --git a/lib/inferno/apps/cli/new/templates/Rakefile b/lib/inferno/apps/cli/new/templates/Rakefile new file mode 100644 index 000000000..f0f0446f7 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/Rakefile @@ -0,0 +1,15 @@ +begin + require 'rspec/core/rake_task' + RSpec::Core::RakeTask.new(:spec) + task default: :spec +rescue LoadError # rubocop:disable Lint/SuppressedException +end + +namespace :db do + desc 'Apply changes to the database' + task :migrate do + require 'inferno/config/application' + require 'inferno/utils/migration' + Inferno::Utils::Migration.new.run + end +end diff --git a/lib/inferno/apps/cli/new/templates/config.ru b/lib/inferno/apps/cli/new/templates/config.ru new file mode 100644 index 000000000..5d5e798f7 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/config.ru @@ -0,0 +1,11 @@ +require 'inferno' + +use Rack::Static, + urls: Inferno::Utils::StaticAssets.static_assets_map, + root: Inferno::Utils::StaticAssets.inferno_path + +Inferno::Application.finalize! + +use Inferno::Utils::Middleware::RequestLogger + +run Inferno::Web.app diff --git a/lib/inferno/apps/cli/new/templates/config/database.yml b/lib/inferno/apps/cli/new/templates/config/database.yml new file mode 100644 index 000000000..5ddc37fa4 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/config/database.yml @@ -0,0 +1,18 @@ +development: + adapter: sqlite + database: data/inferno_development.db + max_connections: 10 + # user: + # password: + # host: + # port: + +production: + adapter: sqlite + database: data/inferno_production.db + max_connections: 10 + +test: + adapter: sqlite + database: ':memory:' + max_connections: 10 diff --git a/lib/inferno/apps/cli/new/templates/config/nginx.background.conf b/lib/inferno/apps/cli/new/templates/config/nginx.background.conf new file mode 100644 index 000000000..f89747207 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/config/nginx.background.conf @@ -0,0 +1,86 @@ +# this sets the user nginx will run as, +#and the number of worker processes +user nobody nogroup; +worker_processes 2; +#user www-data; +#worker_processes auto; + +# setup where nginx will log errors to +# and where the nginx process id resides +error_log /var/log/nginx/error.log; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; + # set to on if you have more than 1 worker_processes + accept_mutex on; +} + +http { + include /etc/nginx/mime.types; + + default_type application/octet-stream; + access_log /tmp/nginx.access.log combined; + + # use the kernel sendfile + # sendfile on; # this causes over-caching because modified timestamps lost in VM + # prepend http headers before sendfile() + tcp_nopush on; + + keepalive_timeout 600; + tcp_nodelay on; + + gzip on; + gzip_vary on; + gzip_min_length 500; + + gzip_disable "MSIE [1-6]\.(?!.*SV1)"; + gzip_types text/plain text/xml text/css + text/comma-separated-values + text/javascript application/x-javascript + application/atom+xml image/x-icon; + + # configure the virtual host + server { + # replace with your domain name + # server_name inferno-server; + + # port to listen for requests on + listen 80; + + # maximum accepted body size of client request + client_max_body_size 4G; + # the server will close connections after this time + keepalive_timeout 600; + + location /validator { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Port $server_port; + proxy_redirect off; + proxy_set_header Connection ''; + proxy_http_version 1.1; + chunked_transfer_encoding off; + proxy_buffering off; + proxy_cache off; + + proxy_pass http://fhir_validator_app; + } + + location /validatorapi/ { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Port $server_port; + proxy_redirect off; + proxy_set_header Connection ''; + proxy_http_version 1.1; + chunked_transfer_encoding off; + proxy_buffering off; + proxy_cache off; + + proxy_pass http://validator_service:4567/; + } + } +} diff --git a/lib/inferno/apps/cli/new/templates/config/nginx.conf b/lib/inferno/apps/cli/new/templates/config/nginx.conf new file mode 100644 index 000000000..af4b46141 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/config/nginx.conf @@ -0,0 +1,101 @@ +# this sets the user nginx will run as, +#and the number of worker processes +user nobody nogroup; +worker_processes 2; +#user www-data; +#worker_processes auto; + +# setup where nginx will log errors to +# and where the nginx process id resides +error_log /var/log/nginx/error.log; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; + # set to on if you have more than 1 worker_processes + accept_mutex on; +} + +http { + include /etc/nginx/mime.types; + + default_type application/octet-stream; + access_log /tmp/nginx.access.log combined; + + # use the kernel sendfile + # sendfile on; # this causes over-caching because modified timestamps lost in VM + # prepend http headers before sendfile() + tcp_nopush on; + + keepalive_timeout 600; + tcp_nodelay on; + + gzip on; + gzip_vary on; + gzip_min_length 500; + + gzip_disable "MSIE [1-6]\.(?!.*SV1)"; + gzip_types text/plain text/xml text/css + text/comma-separated-values + text/javascript application/x-javascript + application/atom+xml image/x-icon; + + # configure the virtual host + server { + # replace with your domain name + # server_name inferno-server; + + # port to listen for requests on + listen 80; + + # maximum accepted body size of client request + client_max_body_size 4G; + # the server will close connections after this time + keepalive_timeout 600; + + location / { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Port $server_port; + proxy_redirect off; + proxy_set_header Connection ''; + proxy_http_version 1.1; + chunked_transfer_encoding off; + proxy_buffering off; + proxy_cache off; + + proxy_pass http://inferno:4567; + } + + location /validator { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Port $server_port; + proxy_redirect off; + proxy_set_header Connection ''; + proxy_http_version 1.1; + chunked_transfer_encoding off; + proxy_buffering off; + proxy_cache off; + + proxy_pass http://fhir_validator_app; + } + + location /validatorapi/ { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Port $server_port; + proxy_redirect off; + proxy_set_header Connection ''; + proxy_http_version 1.1; + chunked_transfer_encoding off; + proxy_buffering off; + proxy_cache off; + + proxy_pass http://validator_service:4567/; + } + } +} diff --git a/lib/inferno/apps/cli/new/templates/config/puma.rb b/lib/inferno/apps/cli/new/templates/config/puma.rb new file mode 100644 index 000000000..f3026ab17 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/config/puma.rb @@ -0,0 +1,2 @@ +environment ENV.fetch('APP_ENV', 'development') +port ENV.fetch('INFERNO_PORT', 4567) diff --git a/lib/inferno/apps/cli/new/templates/data/.keep b/lib/inferno/apps/cli/new/templates/data/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/lib/inferno/apps/cli/new/templates/data/redis/.keep b/lib/inferno/apps/cli/new/templates/data/redis/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/lib/inferno/apps/cli/new/templates/docker-compose.background.yml b/lib/inferno/apps/cli/new/templates/docker-compose.background.yml new file mode 100644 index 000000000..f5021e9d6 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/docker-compose.background.yml @@ -0,0 +1,30 @@ +version: '3' +services: + validator_service: + image: infernocommunity/fhir-validator-service + # Update this path to match your directory structure + volumes: + - ./lib/inferno_template/igs:/home/igs + fhir_validator_app: + image: infernocommunity/fhir-validator-app + depends_on: + - validator_service + environment: + EXTERNAL_VALIDATOR_URL: http://localhost/validatorapi + VALIDATOR_BASE_PATH: /validator + nginx: + image: nginx + volumes: + - ./config/nginx.background.conf:/etc/nginx/nginx.conf + ports: + - "80:80" + command: [nginx, '-g', 'daemon off;'] + depends_on: + - fhir_validator_app + redis: + image: redis + ports: + - "6379:6379" + volumes: + - ./data/redis:/data + command: redis-server --appendonly yes diff --git a/lib/inferno/apps/cli/new/templates/docker-compose.yml b/lib/inferno/apps/cli/new/templates/docker-compose.yml new file mode 100644 index 000000000..c93760781 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/docker-compose.yml @@ -0,0 +1,35 @@ +version: '3' +services: + inferno: + build: + context: ./ + volumes: + - ./data:/opt/inferno/data + depends_on: + - validator_service + worker: + build: + context: ./ + volumes: + - ./data:/opt/inferno/data + command: bundle exec sidekiq -r ./worker.rb + depends_on: + - redis + validator_service: + extends: + file: docker-compose.background.yml + service: validator_service + fhir_validator_app: + extends: + file: docker-compose.background.yml + service: fhir_validator_app + nginx: + extends: + file: docker-compose.background.yml + service: nginx + volumes: + - ./config/nginx.conf:/etc/nginx/nginx.conf + redis: + extends: + file: docker-compose.background.yml + service: redis diff --git a/lib/inferno/apps/cli/new/templates/inferno_template.gemspec b/lib/inferno/apps/cli/new/templates/inferno_template.gemspec new file mode 100644 index 000000000..8e471ce99 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/inferno_template.gemspec @@ -0,0 +1,26 @@ +Gem::Specification.new do |spec| + spec.name = 'inferno_template' + spec.version = '0.0.1' + spec.authors = ['Inferno Team'] + spec.email = ['inferno@groups.mitre.org'] + spec.date = Time.now.utc.strftime('%Y-%m-%d') + spec.summary = 'Inferno Test Kit Template' + spec.description = 'Inferno Test Kit Template' + spec.homepage = 'https://github.com/inferno-framework/inferno-template' + spec.license = 'Apache-2.0' + spec.add_runtime_dependency 'inferno_core', '~> 0.4.4' + spec.add_development_dependency 'database_cleaner-sequel', '~> 1.8' + spec.add_development_dependency 'factory_bot', '~> 6.1' + spec.add_development_dependency 'rspec', '~> 3.10' + spec.add_development_dependency 'webmock', '~> 3.11' + spec.required_ruby_version = Gem::Requirement.new('>= 3.1.2') + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = 'https://github.com/inferno-framework/inferno-template' + spec.files = [ + Dir['lib/**/*.rb'], + Dir['lib/**/*.json'], + 'LICENSE' + ].flatten + + spec.require_paths = ['lib'] +end diff --git a/lib/inferno/apps/cli/new/templates/lib/inferno_template.rb b/lib/inferno/apps/cli/new/templates/lib/inferno_template.rb new file mode 100644 index 000000000..57f402a18 --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/lib/inferno_template.rb @@ -0,0 +1,53 @@ +require_relative 'inferno_template/patient_group' + +module InfernoTemplate + class Suite < Inferno::TestSuite + id :test_suite_template + title 'Inferno Test Suite Template' + description 'A basic test suite template for Inferno' + + # These inputs will be available to all tests in this suite + input :url, + title: 'FHIR Server Base Url' + + input :credentials, + title: 'OAuth Credentials', + type: :oauth_credentials, + optional: true + + # All FHIR requests in this suite will use this FHIR client + fhir_client do + url :url + oauth_credentials :credentials + end + + # All FHIR validation requsets will use this FHIR validator + validator do + url ENV.fetch('VALIDATOR_URL') + end + + # Tests and TestGroups can be defined inline + group do + id :capability_statement + title 'Capability Statement' + description 'Verify that the server has a CapabilityStatement' + + test do + id :capability_statement_read + title 'Read CapabilityStatement' + description 'Read CapabilityStatement from /metadata endpoint' + + run do + fhir_get_capability_statement + + assert_response_status(200) + assert_resource_type(:capability_statement) + end + end + end + + # Tests and TestGroups can be written in separate files and then included + # using their id + group from: :patient_group + end +end diff --git a/lib/inferno/apps/cli/new/templates/lib/inferno_template/igs/put_ig_package_dot_tgz_here b/lib/inferno/apps/cli/new/templates/lib/inferno_template/igs/put_ig_package_dot_tgz_here new file mode 100644 index 000000000..e69de29bb diff --git a/lib/inferno/apps/cli/new/templates/lib/inferno_template/patient_group.rb b/lib/inferno/apps/cli/new/templates/lib/inferno_template/patient_group.rb new file mode 100644 index 000000000..a1270fe9f --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/lib/inferno_template/patient_group.rb @@ -0,0 +1,44 @@ +module InfernoTemplate + class PatientGroup < Inferno::TestGroup + title 'Patient Tests' + description 'Verify that the server makes Patient resources available' + id :patient_group + + test do + title 'Server returns requested Patient resource from the Patient read interaction' + description %( + Verify that Patient resources can be read from the server. + ) + + input :patient_id, + title: 'Patient ID' + + # Named requests can be used by other tests + makes_request :patient + + run do + fhir_read(:patient, patient_id, name: :patient) + + assert_response_status(200) + assert_resource_type(:patient) + assert resource.id == patient_id, + "Requested resource with id #{patient_id}, received resource with id #{resource.id}" + end + end + + test do + title 'Patient resource is valid' + description %( + Verify that the Patient resource returned from the server is a valid FHIR resource. + ) + # This test will use the response from the :patient request in the + # previous test + uses_request :patient + + run do + assert_resource_type(:patient) + assert_valid_resource + end + end + end +end diff --git a/lib/inferno/apps/cli/new/templates/run.sh b/lib/inferno/apps/cli/new/templates/run.sh new file mode 100755 index 000000000..fde0a7eea --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/run.sh @@ -0,0 +1,3 @@ +#!/bin/sh +docker compose build +docker compose up diff --git a/lib/inferno/apps/cli/new/templates/setup.sh b/lib/inferno/apps/cli/new/templates/setup.sh new file mode 100755 index 000000000..6089f58da --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/setup.sh @@ -0,0 +1,4 @@ +#!/bin/sh +docker compose pull +docker compose build +docker compose run inferno bundle exec inferno migrate diff --git a/lib/inferno/apps/cli/new/templates/spec/inferno_template/patient_group_spec.rb b/lib/inferno/apps/cli/new/templates/spec/inferno_template/patient_group_spec.rb new file mode 100644 index 000000000..63c694c0f --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/spec/inferno_template/patient_group_spec.rb @@ -0,0 +1,105 @@ +RSpec.describe InfernoTemplate::PatientGroup do + let(:suite) { Inferno::Repositories::TestSuites.new.find('test_suite_template') } + let(:group) { suite.groups[1] } + let(:session_data_repo) { Inferno::Repositories::SessionData.new } + let(:test_session) { repo_create(:test_session, test_suite_id: 'test_suite_template') } + let(:url) { 'http://example.com/fhir' } + let(:error_outcome) { FHIR::OperationOutcome.new(issue: [{ severity: 'error' }]) } + + def run(runnable, inputs = {}) + test_run_params = { test_session_id: test_session.id }.merge(runnable.reference_hash) + test_run = Inferno::Repositories::TestRuns.new.create(test_run_params) + inputs.each do |name, value| + session_data_repo.save(test_session_id: test_session.id, name: name, value: value, type: 'text') + end + Inferno::TestRunner.new(test_session: test_session, test_run: test_run).run(runnable) + end + + describe 'read test' do + let(:test) { group.tests.first } + let(:patient_id) { 'abc123' } + + it 'passes if a Patient was received' do + resource = FHIR::Patient.new(id: patient_id) + stub_request(:get, "#{url}/Patient/#{patient_id}") + .to_return(status: 200, body: resource.to_json) + + result = run(test, url: url, patient_id: patient_id) + + expect(result.result).to eq('pass') + end + + it 'fails if a 200 is not received' do + resource = FHIR::Patient.new(id: patient_id) + stub_request(:get, "#{url}/Patient/#{patient_id}") + .to_return(status: 201, body: resource.to_json) + + result = run(test, url: url, patient_id: patient_id) + + expect(result.result).to eq('fail') + expect(result.result_message).to match(/200/) + end + + it 'fails if a Patient is not received' do + resource = FHIR::Condition.new(id: patient_id) + stub_request(:get, "#{url}/Patient/#{patient_id}") + .to_return(status: 200, body: resource.to_json) + + result = run(test, url: url, patient_id: patient_id) + + expect(result.result).to eq('fail') + expect(result.result_message).to match(/Patient/) + end + + it 'fails if the id received does not match the one requested' do + resource = FHIR::Patient.new(id: '456') + stub_request(:get, "#{url}/Patient/#{patient_id}") + .to_return(status: 200, body: resource.to_json) + + result = run(test, url: url, patient_id: patient_id) + + expect(result.result).to eq('fail') + expect(result.result_message).to match(/resource with id/) + end + end + + describe 'validation test' do + let(:test) { group.tests.last } + + it 'passes if the resource is valid' do + stub_request(:post, "#{ENV.fetch('VALIDATOR_URL')}/validate") + .with(query: hash_including({})) + .to_return(status: 200, body: FHIR::OperationOutcome.new.to_json) + + resource = FHIR::Patient.new + repo_create( + :request, + name: :patient, + test_session_id: test_session.id, + response_body: resource.to_json + ) + + result = run(test) + + expect(result.result).to eq('pass') + end + + it 'fails if the resource is not valid' do + stub_request(:post, "#{ENV.fetch('VALIDATOR_URL')}/validate") + .with(query: hash_including({})) + .to_return(status: 200, body: error_outcome.to_json) + + resource = FHIR::Patient.new + repo_create( + :request, + name: :patient, + test_session_id: test_session.id, + response_body: resource.to_json + ) + + result = run(test) + + expect(result.result).to eq('fail') + end + end +end diff --git a/lib/inferno/apps/cli/new/templates/spec/spec_helper.rb b/lib/inferno/apps/cli/new/templates/spec/spec_helper.rb new file mode 100644 index 000000000..f30b83fca --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/spec/spec_helper.rb @@ -0,0 +1,141 @@ +# Hide deprecation warnings +$VERBOSE = nil + +ENV['APP_ENV'] ||= 'test' + +require 'database_cleaner/sequel' +require 'pry' +require 'pry-byebug' + +require 'webmock/rspec' +WebMock.disable_net_connect! + +require 'factory_bot' + +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = 'spec/examples.txt' + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed + + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # This setting enables warnings. It's recommended, but in many cases may + # be too noisy due to issues in dependencies. + # config.warnings = false + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + # config.profile_examples = 10 + + config.before(:suite) do + DatabaseCleaner.strategy = :transaction + DatabaseCleaner.clean_with(:truncation) + end + + config.around do |example| + DatabaseCleaner.cleaning { example.run } + end + + config.include FactoryBot::Syntax::Methods + + config.before(:suite) do + FactoryBot.find_definitions + end +end + +require 'inferno/config/application' +require 'inferno/utils/migration' +Inferno::Utils::Migration.new.run + +require 'inferno' +Inferno::Application.finalize! + +require Inferno::SpecSupport::FACTORY_BOT_SUPPORT_PATH + +FactoryBot.definition_file_paths = [ + Inferno::SpecSupport::FACTORY_PATH +] + +RSpec::Matchers.define_negated_matcher :exclude, :include + +FHIR.logger = Inferno::Application['logger'] + +DatabaseCleaner[:sequel].strategy = :truncation +DatabaseCleaner[:sequel].db = Inferno::Application['db.connection'] diff --git a/lib/inferno/apps/cli/new/templates/worker.rb b/lib/inferno/apps/cli/new/templates/worker.rb new file mode 100644 index 000000000..d0183c35f --- /dev/null +++ b/lib/inferno/apps/cli/new/templates/worker.rb @@ -0,0 +1,3 @@ +require 'inferno' + +Inferno::Application.finalize! From 40e677b804ceac722d613db1d402cb0467a538b7 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Fri, 10 Nov 2023 14:23:47 -0500 Subject: [PATCH 06/50] append .erb --- .../{.dockerignore => .dockerignore.erb} | 0 ...{.env.development => .env.development.erb} | 0 .../apps/cli/new/templates/{.env => .env.erb} | 0 .../{.env.production => .env.production.erb} | 0 .../templates/{.env.test => .env.test.erb} | 0 .../templates/{.gitignore => .gitignore.erb} | 0 .../cli/new/templates/{.rspec => .rspec.erb} | 0 .../{.ruby-version => .ruby-version.erb} | 0 .../{.tool-versions => .tool-versions.erb} | 0 .../templates/{Dockerfile => Dockerfile.erb} | 0 .../new/templates/{Gemfile => Gemfile.erb} | 0 .../apps/cli/new/templates/Gemfile.lock | 278 ------------------ .../new/templates/{LICENSE => LICENSE.erb} | 0 .../new/templates/{Procfile => Procfile.erb} | 0 .../templates/{README.md => README.md.erb} | 4 +- .../new/templates/{Rakefile => Rakefile.erb} | 0 .../templates/{config.ru => config.ru.erb} | 0 .../config/{database.yml => database.yml.erb} | 0 ...kground.conf => nginx.background.conf.erb} | 0 .../config/{nginx.conf => nginx.conf.erb} | 0 .../templates/config/{puma.rb => puma.rb.erb} | 0 ....yml => docker-compose.background.yml.erb} | 0 ...ker-compose.yml => docker-compose.yml.erb} | 0 ...e.gemspec => inferno_template.gemspec.erb} | 0 ...no_template.rb => inferno_template.rb.erb} | 0 ...{patient_group.rb => patient_group.rb.erb} | 0 .../cli/new/templates/{run.sh => run.sh.erb} | 0 .../new/templates/{setup.sh => setup.sh.erb} | 0 ...roup_spec.rb => patient_group_spec.rb.erb} | 0 .../{spec_helper.rb => spec_helper.rb.erb} | 0 .../templates/{worker.rb => worker.rb.erb} | 0 31 files changed, 2 insertions(+), 280 deletions(-) rename lib/inferno/apps/cli/new/templates/{.dockerignore => .dockerignore.erb} (100%) rename lib/inferno/apps/cli/new/templates/{.env.development => .env.development.erb} (100%) rename lib/inferno/apps/cli/new/templates/{.env => .env.erb} (100%) rename lib/inferno/apps/cli/new/templates/{.env.production => .env.production.erb} (100%) rename lib/inferno/apps/cli/new/templates/{.env.test => .env.test.erb} (100%) rename lib/inferno/apps/cli/new/templates/{.gitignore => .gitignore.erb} (100%) rename lib/inferno/apps/cli/new/templates/{.rspec => .rspec.erb} (100%) rename lib/inferno/apps/cli/new/templates/{.ruby-version => .ruby-version.erb} (100%) rename lib/inferno/apps/cli/new/templates/{.tool-versions => .tool-versions.erb} (100%) rename lib/inferno/apps/cli/new/templates/{Dockerfile => Dockerfile.erb} (100%) rename lib/inferno/apps/cli/new/templates/{Gemfile => Gemfile.erb} (100%) delete mode 100644 lib/inferno/apps/cli/new/templates/Gemfile.lock rename lib/inferno/apps/cli/new/templates/{LICENSE => LICENSE.erb} (100%) rename lib/inferno/apps/cli/new/templates/{Procfile => Procfile.erb} (100%) rename lib/inferno/apps/cli/new/templates/{README.md => README.md.erb} (99%) rename lib/inferno/apps/cli/new/templates/{Rakefile => Rakefile.erb} (100%) rename lib/inferno/apps/cli/new/templates/{config.ru => config.ru.erb} (100%) rename lib/inferno/apps/cli/new/templates/config/{database.yml => database.yml.erb} (100%) rename lib/inferno/apps/cli/new/templates/config/{nginx.background.conf => nginx.background.conf.erb} (100%) rename lib/inferno/apps/cli/new/templates/config/{nginx.conf => nginx.conf.erb} (100%) rename lib/inferno/apps/cli/new/templates/config/{puma.rb => puma.rb.erb} (100%) rename lib/inferno/apps/cli/new/templates/{docker-compose.background.yml => docker-compose.background.yml.erb} (100%) rename lib/inferno/apps/cli/new/templates/{docker-compose.yml => docker-compose.yml.erb} (100%) rename lib/inferno/apps/cli/new/templates/{inferno_template.gemspec => inferno_template.gemspec.erb} (100%) rename lib/inferno/apps/cli/new/templates/lib/{inferno_template.rb => inferno_template.rb.erb} (100%) rename lib/inferno/apps/cli/new/templates/lib/inferno_template/{patient_group.rb => patient_group.rb.erb} (100%) rename lib/inferno/apps/cli/new/templates/{run.sh => run.sh.erb} (100%) rename lib/inferno/apps/cli/new/templates/{setup.sh => setup.sh.erb} (100%) rename lib/inferno/apps/cli/new/templates/spec/inferno_template/{patient_group_spec.rb => patient_group_spec.rb.erb} (100%) rename lib/inferno/apps/cli/new/templates/spec/{spec_helper.rb => spec_helper.rb.erb} (100%) rename lib/inferno/apps/cli/new/templates/{worker.rb => worker.rb.erb} (100%) diff --git a/lib/inferno/apps/cli/new/templates/.dockerignore b/lib/inferno/apps/cli/new/templates/.dockerignore.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/.dockerignore rename to lib/inferno/apps/cli/new/templates/.dockerignore.erb diff --git a/lib/inferno/apps/cli/new/templates/.env.development b/lib/inferno/apps/cli/new/templates/.env.development.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/.env.development rename to lib/inferno/apps/cli/new/templates/.env.development.erb diff --git a/lib/inferno/apps/cli/new/templates/.env b/lib/inferno/apps/cli/new/templates/.env.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/.env rename to lib/inferno/apps/cli/new/templates/.env.erb diff --git a/lib/inferno/apps/cli/new/templates/.env.production b/lib/inferno/apps/cli/new/templates/.env.production.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/.env.production rename to lib/inferno/apps/cli/new/templates/.env.production.erb diff --git a/lib/inferno/apps/cli/new/templates/.env.test b/lib/inferno/apps/cli/new/templates/.env.test.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/.env.test rename to lib/inferno/apps/cli/new/templates/.env.test.erb diff --git a/lib/inferno/apps/cli/new/templates/.gitignore b/lib/inferno/apps/cli/new/templates/.gitignore.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/.gitignore rename to lib/inferno/apps/cli/new/templates/.gitignore.erb diff --git a/lib/inferno/apps/cli/new/templates/.rspec b/lib/inferno/apps/cli/new/templates/.rspec.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/.rspec rename to lib/inferno/apps/cli/new/templates/.rspec.erb diff --git a/lib/inferno/apps/cli/new/templates/.ruby-version b/lib/inferno/apps/cli/new/templates/.ruby-version.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/.ruby-version rename to lib/inferno/apps/cli/new/templates/.ruby-version.erb diff --git a/lib/inferno/apps/cli/new/templates/.tool-versions b/lib/inferno/apps/cli/new/templates/.tool-versions.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/.tool-versions rename to lib/inferno/apps/cli/new/templates/.tool-versions.erb diff --git a/lib/inferno/apps/cli/new/templates/Dockerfile b/lib/inferno/apps/cli/new/templates/Dockerfile.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/Dockerfile rename to lib/inferno/apps/cli/new/templates/Dockerfile.erb diff --git a/lib/inferno/apps/cli/new/templates/Gemfile b/lib/inferno/apps/cli/new/templates/Gemfile.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/Gemfile rename to lib/inferno/apps/cli/new/templates/Gemfile.erb diff --git a/lib/inferno/apps/cli/new/templates/Gemfile.lock b/lib/inferno/apps/cli/new/templates/Gemfile.lock deleted file mode 100644 index dedb86273..000000000 --- a/lib/inferno/apps/cli/new/templates/Gemfile.lock +++ /dev/null @@ -1,278 +0,0 @@ -PATH - remote: . - specs: - inferno_template (0.0.1) - inferno_core (~> 0.4.4) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (6.1.7) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) - addressable (2.8.1) - public_suffix (>= 2.0.2, < 6.0) - bcp47 (0.3.3) - i18n - blueprinter (0.25.2) - byebug (11.1.3) - coderay (1.1.3) - concurrent-ruby (1.1.10) - connection_pool (2.3.0) - crack (0.4.5) - rexml - database_cleaner (1.99.0) - database_cleaner-sequel (1.99.0) - database_cleaner (~> 1.99.0) - sequel - date_time_precision (0.8.1) - debug (1.6.3) - irb (>= 1.3.6) - reline (>= 0.3.1) - diff-lcs (1.5.0) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) - 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) - 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) - 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) - 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.2) - faraday-em_http (~> 1.0) - faraday-em_synchrony (~> 1.0) - faraday-excon (~> 1.1) - faraday-httpclient (~> 1.0) - faraday-multipart (~> 1.0) - faraday-net_http (~> 1.0) - faraday-net_http_persistent (~> 1.0) - faraday-patron (~> 1.0) - faraday-rack (~> 1.0) - faraday-retry (~> 1.0) - ruby2_keywords (>= 0.0.4) - faraday-em_http (1.0.0) - faraday-em_synchrony (1.0.0) - faraday-excon (1.1.0) - faraday-httpclient (1.0.1) - faraday-multipart (1.0.4) - multipart-post (~> 2) - faraday-net_http (1.0.1) - faraday-net_http_persistent (1.2.0) - faraday-patron (1.0.0) - faraday-rack (1.0.0) - faraday-retry (1.0.3) - faraday_middleware (1.2.0) - faraday (~> 1.0) - fhir_client (5.0.3) - activesupport (>= 3) - addressable (>= 2.3) - fhir_dstu2_models (>= 1.1.1) - fhir_models (>= 4.2.1) - fhir_stu3_models (>= 3.1.1) - nokogiri (>= 1.10.4) - oauth2 (~> 1.1) - rack (>= 1.5) - rest-client (~> 2.0) - tilt (>= 1.1) - fhir_dstu2_models (1.1.1) - bcp47 (>= 0.3) - date_time_precision (>= 0.8) - mime-types (>= 3.0) - nokogiri (>= 1.11.4) - fhir_models (4.2.2) - bcp47 (>= 0.3) - date_time_precision (>= 0.8) - mime-types (>= 3.0) - nokogiri (>= 1.11.4) - fhir_stu3_models (3.1.1) - bcp47 (>= 0.3) - 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) - rack (~> 2.0) - hanami-router (2.0.0) - mustermann (~> 1.0) - mustermann-contrib (~> 1.0) - rack (~> 2.0) - hanami-utils (2.0.0) - concurrent-ruby (~> 1.0) - dry-transformer (~> 1.0, < 2) - hansi (0.2.1) - hashdiff (1.0.1) - http-accept (1.7.0) - http-cookie (1.0.5) - domain_name (~> 0.5) - i18n (1.12.0) - concurrent-ruby (~> 1.0) - ice_nine (0.11.2) - inferno_core (0.4.5) - activesupport (~> 6.1) - blueprinter (= 0.25.2) - dotenv (~> 2.7) - dry-configurable (= 0.13.0) - dry-container (= 0.9.0) - dry-core (= 0.8.1) - dry-system (= 0.20.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-router (= 2.0.0) - oj (= 3.11.0) - pry - pry-byebug - puma (~> 5.3) - rake (~> 13.0) - sequel (~> 5.42.0) - sidekiq (~> 6.5.6) - sqlite3 (~> 1.4) - thor (~> 1.2.1) - io-console (0.5.11) - irb (1.4.2) - reline (>= 0.3.0) - jwt (2.5.0) - method_source (1.0.0) - mime-types (3.4.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2022.0105) - mini_portile2 (2.8.0) - minitest (5.16.3) - multi_json (1.15.0) - multi_xml (0.6.0) - multipart-post (2.2.3) - mustermann (1.1.2) - ruby2_keywords (~> 0.0.1) - mustermann-contrib (1.1.2) - hansi (~> 0.2.0) - mustermann (= 1.1.2) - netrc (0.11.0) - nio4r (2.5.8) - nokogiri (1.13.9) - mini_portile2 (~> 2.8.0) - racc (~> 1.4) - nokogiri (1.13.9-arm64-darwin) - racc (~> 1.4) - nokogiri (1.13.9-x86_64-darwin) - racc (~> 1.4) - nokogiri (1.13.9-x86_64-linux) - racc (~> 1.4) - oauth2 (1.4.11) - faraday (>= 0.17.3, < 3.0) - jwt (>= 1.0, < 3.0) - multi_json (~> 1.3) - multi_xml (~> 0.5) - rack (>= 1.2, < 4) - oj (3.11.0) - pry (0.14.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.10.1) - byebug (~> 11.0) - pry (>= 0.13, < 0.15) - public_suffix (5.0.0) - puma (5.6.5) - nio4r (~> 2.0) - racc (1.6.0) - rack (2.2.4) - rake (13.0.6) - redis (4.8.0) - reline (0.3.1) - io-console (~> 0.5) - rest-client (2.1.0) - http-accept (>= 1.7.0, < 2.0) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) - rexml (3.2.5) - rspec (3.11.0) - rspec-core (~> 3.11.0) - rspec-expectations (~> 3.11.0) - rspec-mocks (~> 3.11.0) - rspec-core (3.11.0) - rspec-support (~> 3.11.0) - rspec-expectations (3.11.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-mocks (3.11.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-support (3.11.0) - ruby2_keywords (0.0.5) - sequel (5.42.0) - sidekiq (6.5.8) - connection_pool (>= 2.2.5, < 3) - rack (~> 2.0) - redis (>= 4.5.0, < 5) - sqlite3 (1.5.4) - mini_portile2 (~> 2.8.0) - sqlite3 (1.5.4-arm64-darwin) - sqlite3 (1.5.4-x86_64-darwin) - sqlite3 (1.5.4-x86_64-linux) - thor (1.2.1) - tilt (2.0.11) - tzinfo (2.0.5) - concurrent-ruby (~> 1.0) - unf (0.1.4) - unf_ext - unf_ext (0.0.8.2) - webmock (3.14.0) - addressable (>= 2.8.0) - crack (>= 0.3.2) - hashdiff (>= 0.4.0, < 2.0.0) - zeitwerk (2.6.6) - -PLATFORMS - arm64-darwin-21 - ruby - x86_64-darwin-19 - x86_64-darwin-20 - x86_64-linux - -DEPENDENCIES - database_cleaner-sequel (~> 1.8) - debug - factory_bot (~> 6.1) - inferno_template! - rspec (~> 3.10) - webmock (~> 3.11) - -BUNDLED WITH - 2.3.14 diff --git a/lib/inferno/apps/cli/new/templates/LICENSE b/lib/inferno/apps/cli/new/templates/LICENSE.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/LICENSE rename to lib/inferno/apps/cli/new/templates/LICENSE.erb diff --git a/lib/inferno/apps/cli/new/templates/Procfile b/lib/inferno/apps/cli/new/templates/Procfile.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/Procfile rename to lib/inferno/apps/cli/new/templates/Procfile.erb diff --git a/lib/inferno/apps/cli/new/templates/README.md b/lib/inferno/apps/cli/new/templates/README.md.erb similarity index 99% rename from lib/inferno/apps/cli/new/templates/README.md rename to lib/inferno/apps/cli/new/templates/README.md.erb index f9d125d0b..77ca0cf1e 100644 --- a/lib/inferno/apps/cli/new/templates/README.md +++ b/lib/inferno/apps/cli/new/templates/README.md.erb @@ -1,4 +1,4 @@ -# Inferno Template +# <%= human_name %> Inferno Test Kit This is a template repository for an [Inferno](https://github.com/inferno-community/inferno-core) test kit. @@ -18,7 +18,7 @@ This is a template repository for an `docker-compose.background.yml`. This will ensure that the validator has access to the resources needed to validate resources against your IG. - + All tests you write should go in the `lib` folder, which currently contains some example tests. Refer to the [Inferno documentation](https://inferno-framework.github.io/inferno-core/) for more diff --git a/lib/inferno/apps/cli/new/templates/Rakefile b/lib/inferno/apps/cli/new/templates/Rakefile.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/Rakefile rename to lib/inferno/apps/cli/new/templates/Rakefile.erb diff --git a/lib/inferno/apps/cli/new/templates/config.ru b/lib/inferno/apps/cli/new/templates/config.ru.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/config.ru rename to lib/inferno/apps/cli/new/templates/config.ru.erb diff --git a/lib/inferno/apps/cli/new/templates/config/database.yml b/lib/inferno/apps/cli/new/templates/config/database.yml.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/config/database.yml rename to lib/inferno/apps/cli/new/templates/config/database.yml.erb diff --git a/lib/inferno/apps/cli/new/templates/config/nginx.background.conf b/lib/inferno/apps/cli/new/templates/config/nginx.background.conf.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/config/nginx.background.conf rename to lib/inferno/apps/cli/new/templates/config/nginx.background.conf.erb diff --git a/lib/inferno/apps/cli/new/templates/config/nginx.conf b/lib/inferno/apps/cli/new/templates/config/nginx.conf.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/config/nginx.conf rename to lib/inferno/apps/cli/new/templates/config/nginx.conf.erb diff --git a/lib/inferno/apps/cli/new/templates/config/puma.rb b/lib/inferno/apps/cli/new/templates/config/puma.rb.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/config/puma.rb rename to lib/inferno/apps/cli/new/templates/config/puma.rb.erb diff --git a/lib/inferno/apps/cli/new/templates/docker-compose.background.yml b/lib/inferno/apps/cli/new/templates/docker-compose.background.yml.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/docker-compose.background.yml rename to lib/inferno/apps/cli/new/templates/docker-compose.background.yml.erb diff --git a/lib/inferno/apps/cli/new/templates/docker-compose.yml b/lib/inferno/apps/cli/new/templates/docker-compose.yml.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/docker-compose.yml rename to lib/inferno/apps/cli/new/templates/docker-compose.yml.erb diff --git a/lib/inferno/apps/cli/new/templates/inferno_template.gemspec b/lib/inferno/apps/cli/new/templates/inferno_template.gemspec.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/inferno_template.gemspec rename to lib/inferno/apps/cli/new/templates/inferno_template.gemspec.erb diff --git a/lib/inferno/apps/cli/new/templates/lib/inferno_template.rb b/lib/inferno/apps/cli/new/templates/lib/inferno_template.rb.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/lib/inferno_template.rb rename to lib/inferno/apps/cli/new/templates/lib/inferno_template.rb.erb diff --git a/lib/inferno/apps/cli/new/templates/lib/inferno_template/patient_group.rb b/lib/inferno/apps/cli/new/templates/lib/inferno_template/patient_group.rb.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/lib/inferno_template/patient_group.rb rename to lib/inferno/apps/cli/new/templates/lib/inferno_template/patient_group.rb.erb diff --git a/lib/inferno/apps/cli/new/templates/run.sh b/lib/inferno/apps/cli/new/templates/run.sh.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/run.sh rename to lib/inferno/apps/cli/new/templates/run.sh.erb diff --git a/lib/inferno/apps/cli/new/templates/setup.sh b/lib/inferno/apps/cli/new/templates/setup.sh.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/setup.sh rename to lib/inferno/apps/cli/new/templates/setup.sh.erb diff --git a/lib/inferno/apps/cli/new/templates/spec/inferno_template/patient_group_spec.rb b/lib/inferno/apps/cli/new/templates/spec/inferno_template/patient_group_spec.rb.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/spec/inferno_template/patient_group_spec.rb rename to lib/inferno/apps/cli/new/templates/spec/inferno_template/patient_group_spec.rb.erb diff --git a/lib/inferno/apps/cli/new/templates/spec/spec_helper.rb b/lib/inferno/apps/cli/new/templates/spec/spec_helper.rb.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/spec/spec_helper.rb rename to lib/inferno/apps/cli/new/templates/spec/spec_helper.rb.erb diff --git a/lib/inferno/apps/cli/new/templates/worker.rb b/lib/inferno/apps/cli/new/templates/worker.rb.erb similarity index 100% rename from lib/inferno/apps/cli/new/templates/worker.rb rename to lib/inferno/apps/cli/new/templates/worker.rb.erb From e988af639b4459ea1fc1d86606db3fce0a320342 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Fri, 10 Nov 2023 14:52:17 -0500 Subject: [PATCH 07/50] use .tt suffix because it is built into thor --- lib/inferno/apps/cli/new/new.rb | 51 ++++++++++--------- .../{Dockerfile.erb => Dockerfile.tt} | 0 .../new/templates/{Gemfile.erb => Gemfile.tt} | 0 .../new/templates/{LICENSE.erb => LICENSE.tt} | 0 .../templates/{Procfile.erb => Procfile.tt} | 0 .../templates/{README.md.erb => README.md.tt} | 0 .../templates/{Rakefile.erb => Rakefile.tt} | 0 .../templates/{config.ru.erb => config.ru.tt} | 0 ...l.erb => docker-compose.background.yml.tt} | 0 ...-compose.yml.erb => docker-compose.yml.tt} | 0 ...emspec.erb => inferno_template.gemspec.tt} | 0 .../new/templates/{run.sh.erb => run.sh.tt} | 0 .../templates/{setup.sh.erb => setup.sh.tt} | 0 .../templates/{worker.rb.erb => worker.rb.tt} | 0 14 files changed, 26 insertions(+), 25 deletions(-) rename lib/inferno/apps/cli/new/templates/{Dockerfile.erb => Dockerfile.tt} (100%) rename lib/inferno/apps/cli/new/templates/{Gemfile.erb => Gemfile.tt} (100%) rename lib/inferno/apps/cli/new/templates/{LICENSE.erb => LICENSE.tt} (100%) rename lib/inferno/apps/cli/new/templates/{Procfile.erb => Procfile.tt} (100%) rename lib/inferno/apps/cli/new/templates/{README.md.erb => README.md.tt} (100%) rename lib/inferno/apps/cli/new/templates/{Rakefile.erb => Rakefile.tt} (100%) rename lib/inferno/apps/cli/new/templates/{config.ru.erb => config.ru.tt} (100%) rename lib/inferno/apps/cli/new/templates/{docker-compose.background.yml.erb => docker-compose.background.yml.tt} (100%) rename lib/inferno/apps/cli/new/templates/{docker-compose.yml.erb => docker-compose.yml.tt} (100%) rename lib/inferno/apps/cli/new/templates/{inferno_template.gemspec.erb => inferno_template.gemspec.tt} (100%) rename lib/inferno/apps/cli/new/templates/{run.sh.erb => run.sh.tt} (100%) rename lib/inferno/apps/cli/new/templates/{setup.sh.erb => setup.sh.tt} (100%) rename lib/inferno/apps/cli/new/templates/{worker.rb.erb => worker.rb.tt} (100%) diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index e5b7ac22e..d0e802ca8 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -17,37 +17,38 @@ def self.source_root def run(name, implementation_guide = nil) @name = name - ## This defines the new inferno-template: - empty_directory(folder_name) - template( - + ## Template Generation: + # copies all files from ./templates/ folder + # performs ERB substitution on all .tt files and remove .tt suffix + # replaces all %foo% file names with foo() method call + directory('.', root_name) + end - private - # root folder name, i.e: inferno-template - def folder_name - @@inflector.dasherize(@name) - end + # root folder name, i.e: inferno-template + def root_name + @@inflector.dasherize(@name) + end - # lib folder name, i.e: inferno_template - def lib_name - @@inflector.underscore(@name) - end + # lib folder name, i.e: inferno_template + def lib_name + @@inflector.underscore(@name) + end - # file name with suffix extension, i.e: inferno_template.rb - def file_name(suffix = '.rb') - @@inflector.underscore(@name) + suffix - end + # file name with suffix extension, i.e: inferno_template.rb + def file_name(suffix = '.rb') + @@inflector.underscore(@name) + suffix + end - # module name, i.e: InfernoTemplate - def module_name - @@inflector.camelize(@name) - end + # module name, i.e: InfernoTemplate + def module_name + @@inflector.camelize(@name) + end - # English grammatical name, i.e: Inferno template - def human_name - @@inflector.humanize(@name) - end + # English grammatical name, i.e: Inferno template + def human_name + @@inflector.humanize(@name) + end end end end diff --git a/lib/inferno/apps/cli/new/templates/Dockerfile.erb b/lib/inferno/apps/cli/new/templates/Dockerfile.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/Dockerfile.erb rename to lib/inferno/apps/cli/new/templates/Dockerfile.tt diff --git a/lib/inferno/apps/cli/new/templates/Gemfile.erb b/lib/inferno/apps/cli/new/templates/Gemfile.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/Gemfile.erb rename to lib/inferno/apps/cli/new/templates/Gemfile.tt diff --git a/lib/inferno/apps/cli/new/templates/LICENSE.erb b/lib/inferno/apps/cli/new/templates/LICENSE.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/LICENSE.erb rename to lib/inferno/apps/cli/new/templates/LICENSE.tt diff --git a/lib/inferno/apps/cli/new/templates/Procfile.erb b/lib/inferno/apps/cli/new/templates/Procfile.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/Procfile.erb rename to lib/inferno/apps/cli/new/templates/Procfile.tt diff --git a/lib/inferno/apps/cli/new/templates/README.md.erb b/lib/inferno/apps/cli/new/templates/README.md.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/README.md.erb rename to lib/inferno/apps/cli/new/templates/README.md.tt diff --git a/lib/inferno/apps/cli/new/templates/Rakefile.erb b/lib/inferno/apps/cli/new/templates/Rakefile.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/Rakefile.erb rename to lib/inferno/apps/cli/new/templates/Rakefile.tt diff --git a/lib/inferno/apps/cli/new/templates/config.ru.erb b/lib/inferno/apps/cli/new/templates/config.ru.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/config.ru.erb rename to lib/inferno/apps/cli/new/templates/config.ru.tt diff --git a/lib/inferno/apps/cli/new/templates/docker-compose.background.yml.erb b/lib/inferno/apps/cli/new/templates/docker-compose.background.yml.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/docker-compose.background.yml.erb rename to lib/inferno/apps/cli/new/templates/docker-compose.background.yml.tt diff --git a/lib/inferno/apps/cli/new/templates/docker-compose.yml.erb b/lib/inferno/apps/cli/new/templates/docker-compose.yml.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/docker-compose.yml.erb rename to lib/inferno/apps/cli/new/templates/docker-compose.yml.tt diff --git a/lib/inferno/apps/cli/new/templates/inferno_template.gemspec.erb b/lib/inferno/apps/cli/new/templates/inferno_template.gemspec.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/inferno_template.gemspec.erb rename to lib/inferno/apps/cli/new/templates/inferno_template.gemspec.tt diff --git a/lib/inferno/apps/cli/new/templates/run.sh.erb b/lib/inferno/apps/cli/new/templates/run.sh.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/run.sh.erb rename to lib/inferno/apps/cli/new/templates/run.sh.tt diff --git a/lib/inferno/apps/cli/new/templates/setup.sh.erb b/lib/inferno/apps/cli/new/templates/setup.sh.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/setup.sh.erb rename to lib/inferno/apps/cli/new/templates/setup.sh.tt diff --git a/lib/inferno/apps/cli/new/templates/worker.rb.erb b/lib/inferno/apps/cli/new/templates/worker.rb.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/worker.rb.erb rename to lib/inferno/apps/cli/new/templates/worker.rb.tt From a504c5abf8c879fea042fbed213e221f384ec714 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Fri, 10 Nov 2023 15:38:00 -0500 Subject: [PATCH 08/50] implementing erb templates --- lib/inferno/apps/cli/new/new.rb | 21 ++++++++++------ ...plate.gemspec.tt => %lib_name%.gemspec.tt} | 16 ++++++------ .../{.dockerignore.erb => .dockerignore} | 0 .../apps/cli/new/templates/{.env.erb => .env} | 0 ...{.env.development.erb => .env.development} | 0 .../{.env.production.erb => .env.production} | 0 .../templates/{.env.test.erb => .env.test} | 0 .../templates/{.gitignore.erb => .gitignore} | 0 .../cli/new/templates/{.rspec.erb => .rspec} | 0 .../{.ruby-version.erb => .ruby-version} | 0 .../{.tool-versions.erb => .tool-versions} | 0 .../apps/cli/new/templates/README.md.tt | 25 +++++++++---------- .../docker-compose.background.yml.tt | 2 +- ...ferno_template.rb.erb => %lib_name%.rb.tt} | 10 ++++---- .../igs/put_ig_package_dot_tgz_here | 0 .../patient_group.rb.tt} | 2 +- .../patient_group_spec.rb.tt} | 2 +- .../{spec_helper.rb.erb => spec_helper.rb.tt} | 0 18 files changed, 41 insertions(+), 37 deletions(-) rename lib/inferno/apps/cli/new/templates/{inferno_template.gemspec.tt => %lib_name%.gemspec.tt} (58%) rename lib/inferno/apps/cli/new/templates/{.dockerignore.erb => .dockerignore} (100%) rename lib/inferno/apps/cli/new/templates/{.env.erb => .env} (100%) rename lib/inferno/apps/cli/new/templates/{.env.development.erb => .env.development} (100%) rename lib/inferno/apps/cli/new/templates/{.env.production.erb => .env.production} (100%) rename lib/inferno/apps/cli/new/templates/{.env.test.erb => .env.test} (100%) rename lib/inferno/apps/cli/new/templates/{.gitignore.erb => .gitignore} (100%) rename lib/inferno/apps/cli/new/templates/{.rspec.erb => .rspec} (100%) rename lib/inferno/apps/cli/new/templates/{.ruby-version.erb => .ruby-version} (100%) rename lib/inferno/apps/cli/new/templates/{.tool-versions.erb => .tool-versions} (100%) rename lib/inferno/apps/cli/new/templates/lib/{inferno_template.rb.erb => %lib_name%.rb.tt} (84%) rename lib/inferno/apps/cli/new/templates/lib/{inferno_template => %lib_name%}/igs/put_ig_package_dot_tgz_here (100%) rename lib/inferno/apps/cli/new/templates/lib/{inferno_template/patient_group.rb.erb => %lib_name%/patient_group.rb.tt} (97%) rename lib/inferno/apps/cli/new/templates/spec/{inferno_template/patient_group_spec.rb.erb => %lib_name%/patient_group_spec.rb.tt} (98%) rename lib/inferno/apps/cli/new/templates/spec/{spec_helper.rb.erb => spec_helper.rb.tt} (100%) diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index d0e802ca8..944feac3d 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -3,7 +3,7 @@ module Inferno module CLI - class New < Thor + class New include Thor::Actions @@inflector = Dry::Inflector.new do |inflections| @@ -19,7 +19,7 @@ def run(name, implementation_guide = nil) ## Template Generation: # copies all files from ./templates/ folder - # performs ERB substitution on all .tt files and remove .tt suffix + # performs ERB substitution on all .tt files and removes .tt suffix # replaces all %foo% file names with foo() method call directory('.', root_name) @@ -30,16 +30,11 @@ def root_name @@inflector.dasherize(@name) end - # lib folder name, i.e: inferno_template + # library name, i.e: inferno_template def lib_name @@inflector.underscore(@name) end - # file name with suffix extension, i.e: inferno_template.rb - def file_name(suffix = '.rb') - @@inflector.underscore(@name) + suffix - end - # module name, i.e: InfernoTemplate def module_name @@inflector.camelize(@name) @@ -49,6 +44,16 @@ def module_name def human_name @@inflector.humanize(@name) end + + # title case name, i.e: Inferno Template + def title_name + human_name.split(' ').map{ |s| s.capitalize }.join(' ') + end + + # suffix '_test_suite' in snake case, i.e: inferno_template_test_suite + def test_suite_id + "#{lib_name}_test_suite" + end end end end diff --git a/lib/inferno/apps/cli/new/templates/inferno_template.gemspec.tt b/lib/inferno/apps/cli/new/templates/%lib_name%.gemspec.tt similarity index 58% rename from lib/inferno/apps/cli/new/templates/inferno_template.gemspec.tt rename to lib/inferno/apps/cli/new/templates/%lib_name%.gemspec.tt index 8e471ce99..a5c16f4cf 100644 --- a/lib/inferno/apps/cli/new/templates/inferno_template.gemspec.tt +++ b/lib/inferno/apps/cli/new/templates/%lib_name%.gemspec.tt @@ -1,12 +1,12 @@ Gem::Specification.new do |spec| - spec.name = 'inferno_template' + spec.name = '<%= lib_name %>' spec.version = '0.0.1' - spec.authors = ['Inferno Team'] - spec.email = ['inferno@groups.mitre.org'] + # spec.authors = ['TODO'] + # spec.email = ['TODO'] spec.date = Time.now.utc.strftime('%Y-%m-%d') - spec.summary = 'Inferno Test Kit Template' - spec.description = 'Inferno Test Kit Template' - spec.homepage = 'https://github.com/inferno-framework/inferno-template' + spec.summary = '<%= title_name %> Test Kit' + spec.description = '<%= human_name %> Inferno test kit for FHIR' + # spec.homepage = 'TODO' spec.license = 'Apache-2.0' spec.add_runtime_dependency 'inferno_core', '~> 0.4.4' spec.add_development_dependency 'database_cleaner-sequel', '~> 1.8' @@ -14,8 +14,8 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rspec', '~> 3.10' spec.add_development_dependency 'webmock', '~> 3.11' spec.required_ruby_version = Gem::Requirement.new('>= 3.1.2') - spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = 'https://github.com/inferno-framework/inferno-template' + # spec.metadata['homepage_uri'] = spec.homepage + # spec.metadata['source_code_uri'] = 'TODO' spec.files = [ Dir['lib/**/*.rb'], Dir['lib/**/*.json'], diff --git a/lib/inferno/apps/cli/new/templates/.dockerignore.erb b/lib/inferno/apps/cli/new/templates/.dockerignore similarity index 100% rename from lib/inferno/apps/cli/new/templates/.dockerignore.erb rename to lib/inferno/apps/cli/new/templates/.dockerignore diff --git a/lib/inferno/apps/cli/new/templates/.env.erb b/lib/inferno/apps/cli/new/templates/.env similarity index 100% rename from lib/inferno/apps/cli/new/templates/.env.erb rename to lib/inferno/apps/cli/new/templates/.env diff --git a/lib/inferno/apps/cli/new/templates/.env.development.erb b/lib/inferno/apps/cli/new/templates/.env.development similarity index 100% rename from lib/inferno/apps/cli/new/templates/.env.development.erb rename to lib/inferno/apps/cli/new/templates/.env.development diff --git a/lib/inferno/apps/cli/new/templates/.env.production.erb b/lib/inferno/apps/cli/new/templates/.env.production similarity index 100% rename from lib/inferno/apps/cli/new/templates/.env.production.erb rename to lib/inferno/apps/cli/new/templates/.env.production diff --git a/lib/inferno/apps/cli/new/templates/.env.test.erb b/lib/inferno/apps/cli/new/templates/.env.test similarity index 100% rename from lib/inferno/apps/cli/new/templates/.env.test.erb rename to lib/inferno/apps/cli/new/templates/.env.test diff --git a/lib/inferno/apps/cli/new/templates/.gitignore.erb b/lib/inferno/apps/cli/new/templates/.gitignore similarity index 100% rename from lib/inferno/apps/cli/new/templates/.gitignore.erb rename to lib/inferno/apps/cli/new/templates/.gitignore diff --git a/lib/inferno/apps/cli/new/templates/.rspec.erb b/lib/inferno/apps/cli/new/templates/.rspec similarity index 100% rename from lib/inferno/apps/cli/new/templates/.rspec.erb rename to lib/inferno/apps/cli/new/templates/.rspec diff --git a/lib/inferno/apps/cli/new/templates/.ruby-version.erb b/lib/inferno/apps/cli/new/templates/.ruby-version similarity index 100% rename from lib/inferno/apps/cli/new/templates/.ruby-version.erb rename to lib/inferno/apps/cli/new/templates/.ruby-version diff --git a/lib/inferno/apps/cli/new/templates/.tool-versions.erb b/lib/inferno/apps/cli/new/templates/.tool-versions similarity index 100% rename from lib/inferno/apps/cli/new/templates/.tool-versions.erb rename to lib/inferno/apps/cli/new/templates/.tool-versions diff --git a/lib/inferno/apps/cli/new/templates/README.md.tt b/lib/inferno/apps/cli/new/templates/README.md.tt index 77ca0cf1e..93c1bb6f1 100644 --- a/lib/inferno/apps/cli/new/templates/README.md.tt +++ b/lib/inferno/apps/cli/new/templates/README.md.tt @@ -1,7 +1,7 @@ -# <%= human_name %> Inferno Test Kit +# <%= title_name %> Test Kit -This is a template repository for an -[Inferno](https://github.com/inferno-community/inferno-core) test kit. +<%= human_name %> [Inferno](https://github.com/inferno-community/inferno-core) test kit +for FHIR testing. ## Documentation - [Inferno documentation](https://inferno-framework.github.io/inferno-core/) @@ -14,8 +14,7 @@ This is a template repository for an - Run `setup.sh` in this repo to pull the needed docker images and set up the database. - Put the `package.tgz` for the IG you're writing tests for in - `lib/your_test_kit_name/igs` and update this path in - `docker-compose.background.yml`. + `lib/<%= lib_name %>/igs`. This will ensure that the validator has access to the resources needed to validate resources against your IG. @@ -65,8 +64,8 @@ a powerful interactive console to explore and experiment with your tests with `inferno console`: ```ruby ᐅ bundle exec inferno console -[1] pry(main)> suite = InfernoTemplate::Suite -=> InfernoTemplate::Suite +[1] pry(main)> suite = <%= module_name %>::Suite +=> <%= module_name %>::Suite [2] pry(main)> suite.groups => [#, #] [3] pry(main)> suite.groups.map(&:title) @@ -84,7 +83,7 @@ behavior: interactive console. ```ruby -module InfernoTemplate +module <%= module_name %> class PatientGroup < Inferno::TestGroup ... test do @@ -109,7 +108,7 @@ end ᐅ bundle exec rdbg -A DEBUGGER (client): Connected. PID:22112, $0:sidekiq 6.5.7 [0 of 10 busy] -[18, 27] in ~/code/inferno-template/lib/inferno_template/patient_group.rb +[18, 27] in ~/code/<%= root_name %>/lib/<%= lib_name %>/patient_group.rb 18| 19| run do 20| fhir_read(:patient, patient_id, name: :patient) @@ -121,7 +120,7 @@ DEBUGGER (client): Connected. PID:22112, $0:sidekiq 6.5.7 [0 of 10 busy] 26| assert_resource_type(:patient) 27| assert resource.id == patient_id, (ruby:remote) self.id -"test_suite_template-patient_group-Test01" +"<%= test_suite_id %>-patient_group-Test01" (ruby:remote) self.title "Server returns requested Patient resource from the Patient read interaction" (rdbg:remote) inputs @@ -158,8 +157,8 @@ like a standard ruby gem (ruby libraries are called gems). - Fill in the information in the `gemspec` file in the root of this repository. The name of this file should match the `spec.name` within the file. This will be the name of the gem you create. For example, if your file is - `my_test_kit.gemspec` and its `spec.name` is `'my_test_kit'`, then others will - be able to install your gem with `gem install my_test_kit`. There are + `<%= lib_name %>.gemspec` and its `spec.name` is `'<%= lib_name %>'`, then others will + be able to install your gem with `gem install <%= lib_name %>`. There are [recommended naming conventions for gems](https://guides.rubygems.org/name-your-gem/). - Your tests must be in `lib` @@ -182,7 +181,7 @@ like a standard ruby gem (ruby libraries are called gems). - https://github.com/inferno-community/shc-vaccination-test-kit ## License -Copyright 2022 The MITRE Corporation +Copyright <%= Time.now.year %> TODO Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the diff --git a/lib/inferno/apps/cli/new/templates/docker-compose.background.yml.tt b/lib/inferno/apps/cli/new/templates/docker-compose.background.yml.tt index f5021e9d6..9300cdf2e 100644 --- a/lib/inferno/apps/cli/new/templates/docker-compose.background.yml.tt +++ b/lib/inferno/apps/cli/new/templates/docker-compose.background.yml.tt @@ -4,7 +4,7 @@ services: image: infernocommunity/fhir-validator-service # Update this path to match your directory structure volumes: - - ./lib/inferno_template/igs:/home/igs + - ./lib/<%= lib_name %>/igs:/home/igs fhir_validator_app: image: infernocommunity/fhir-validator-app depends_on: diff --git a/lib/inferno/apps/cli/new/templates/lib/inferno_template.rb.erb b/lib/inferno/apps/cli/new/templates/lib/%lib_name%.rb.tt similarity index 84% rename from lib/inferno/apps/cli/new/templates/lib/inferno_template.rb.erb rename to lib/inferno/apps/cli/new/templates/lib/%lib_name%.rb.tt index 57f402a18..e2a40de7f 100644 --- a/lib/inferno/apps/cli/new/templates/lib/inferno_template.rb.erb +++ b/lib/inferno/apps/cli/new/templates/lib/%lib_name%.rb.tt @@ -1,10 +1,10 @@ -require_relative 'inferno_template/patient_group' +require_relative '<%= lib_name %>/patient_group' -module InfernoTemplate +module <%= module_name %> class Suite < Inferno::TestSuite - id :test_suite_template - title 'Inferno Test Suite Template' - description 'A basic test suite template for Inferno' + id :<%= test_suite_id %> + title '<%= title_name %> Test Suite' + description 'Inferno <%= human_name.downcase %> test suite for FHIR testing' # These inputs will be available to all tests in this suite input :url, diff --git a/lib/inferno/apps/cli/new/templates/lib/inferno_template/igs/put_ig_package_dot_tgz_here b/lib/inferno/apps/cli/new/templates/lib/%lib_name%/igs/put_ig_package_dot_tgz_here similarity index 100% rename from lib/inferno/apps/cli/new/templates/lib/inferno_template/igs/put_ig_package_dot_tgz_here rename to lib/inferno/apps/cli/new/templates/lib/%lib_name%/igs/put_ig_package_dot_tgz_here diff --git a/lib/inferno/apps/cli/new/templates/lib/inferno_template/patient_group.rb.erb b/lib/inferno/apps/cli/new/templates/lib/%lib_name%/patient_group.rb.tt similarity index 97% rename from lib/inferno/apps/cli/new/templates/lib/inferno_template/patient_group.rb.erb rename to lib/inferno/apps/cli/new/templates/lib/%lib_name%/patient_group.rb.tt index a1270fe9f..3ad62debe 100644 --- a/lib/inferno/apps/cli/new/templates/lib/inferno_template/patient_group.rb.erb +++ b/lib/inferno/apps/cli/new/templates/lib/%lib_name%/patient_group.rb.tt @@ -1,4 +1,4 @@ -module InfernoTemplate +module <%= module_name %> class PatientGroup < Inferno::TestGroup title 'Patient Tests' description 'Verify that the server makes Patient resources available' diff --git a/lib/inferno/apps/cli/new/templates/spec/inferno_template/patient_group_spec.rb.erb b/lib/inferno/apps/cli/new/templates/spec/%lib_name%/patient_group_spec.rb.tt similarity index 98% rename from lib/inferno/apps/cli/new/templates/spec/inferno_template/patient_group_spec.rb.erb rename to lib/inferno/apps/cli/new/templates/spec/%lib_name%/patient_group_spec.rb.tt index 63c694c0f..5d9452f74 100644 --- a/lib/inferno/apps/cli/new/templates/spec/inferno_template/patient_group_spec.rb.erb +++ b/lib/inferno/apps/cli/new/templates/spec/%lib_name%/patient_group_spec.rb.tt @@ -1,4 +1,4 @@ -RSpec.describe InfernoTemplate::PatientGroup do +RSpec.describe <%= module_name %>::PatientGroup do let(:suite) { Inferno::Repositories::TestSuites.new.find('test_suite_template') } let(:group) { suite.groups[1] } let(:session_data_repo) { Inferno::Repositories::SessionData.new } diff --git a/lib/inferno/apps/cli/new/templates/spec/spec_helper.rb.erb b/lib/inferno/apps/cli/new/templates/spec/spec_helper.rb.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/spec/spec_helper.rb.erb rename to lib/inferno/apps/cli/new/templates/spec/spec_helper.rb.tt From cb5411df745380316b2efbdfbc96af3bac8c3399 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Mon, 13 Nov 2023 10:58:37 -0500 Subject: [PATCH 09/50] debugging --- lib/inferno/apps/cli/main.rb | 6 +++--- lib/inferno/apps/cli/new/new.rb | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/inferno/apps/cli/main.rb b/lib/inferno/apps/cli/main.rb index 891f03d54..1878d4475 100644 --- a/lib/inferno/apps/cli/main.rb +++ b/lib/inferno/apps/cli/main.rb @@ -52,14 +52,14 @@ def suites subcommand 'suite', Suite map 'new' => :new_app - desc 'new TEST_KIT_NAME', 'Generate a new Inferno test kit' + desc 'new TEST_KIT_NAME [-i IG_URL]', 'Generate a new Inferno test kit' option :implementation_guide, default: nil, type: :string, aliases: '-i', - desc: "URL to an implementation guide to load" + desc: 'URL to an implementation guide to load' def new_app(name) - New.new.run(name, options[:implementation_guide]) + New.new().run(name, options[:implementation_guide]) end end end diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index 944feac3d..61ba657b4 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -14,6 +14,10 @@ def self.source_root File.join(__dir__, 'templates') end + def initialize(_args = [], _options = {}, _config = {}) + # required by Thor::Actions + end + def run(name, implementation_guide = nil) @name = name @@ -21,8 +25,14 @@ def run(name, implementation_guide = nil) # copies all files from ./templates/ folder # performs ERB substitution on all .tt files and removes .tt suffix # replaces all %foo% file names with foo() method call - directory('.', root_name) - + directory('.', root_name, { mode: :preserve, recursive: true }) + + case implementation_guide + when /^https?/, /^localhost/, /^\d+\.\d+\.\d+\.\d+/ + say 'todo fetch url', color: :blue + else + say "If you want to test against a FHIR implementation guide, please copy its package.tgz file into #{File.join(root_name, 'lib', lib_name, 'igs')}", color: :yellow + end end # root folder name, i.e: inferno-template @@ -47,7 +57,7 @@ def human_name # title case name, i.e: Inferno Template def title_name - human_name.split(' ').map{ |s| s.capitalize }.join(' ') + human_name.split.map{ |s| s.capitalize }.join(' ') end # suffix '_test_suite' in snake case, i.e: inferno_template_test_suite From 36aa8e99c226eda3d131c4841e39236c47e5a16f Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Mon, 13 Nov 2023 11:59:21 -0500 Subject: [PATCH 10/50] debug generator loading --- lib/inferno/apps/cli/main.rb | 11 +---------- lib/inferno/apps/cli/new/new.rb | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/inferno/apps/cli/main.rb b/lib/inferno/apps/cli/main.rb index 1878d4475..625eea2c2 100644 --- a/lib/inferno/apps/cli/main.rb +++ b/lib/inferno/apps/cli/main.rb @@ -51,16 +51,7 @@ def suites desc 'suite SUBCOMMAND ...ARGS', 'Perform suite-based operations' subcommand 'suite', Suite - map 'new' => :new_app - desc 'new TEST_KIT_NAME [-i IG_URL]', 'Generate a new Inferno test kit' - option :implementation_guide, - default: nil, - type: :string, - aliases: '-i', - desc: 'URL to an implementation guide to load' - def new_app(name) - New.new().run(name, options[:implementation_guide]) - end + register(New, 'new', 'new TEST_KIT_NAME [-i IG_URL]', 'create an Inferno test kit') end end end diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index 61ba657b4..63cdf8526 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -3,9 +3,17 @@ module Inferno module CLI - class New + class New < Thor::Group include Thor::Actions + desc <<~HELP + Generate a new Inferno test kit for FHIR + HELP + + argument :name, type: :string, required: true, desc: 'name for new Inferno project' + + class_option :implementation_guide, aliases: '-i', default: nil, banner: 'IG_URL', desc: 'URL to a FHIR Implementation Guide or path to a package.tgz' + @@inflector = Dry::Inflector.new do |inflections| inflections.acronym 'FHIR' end @@ -14,12 +22,9 @@ def self.source_root File.join(__dir__, 'templates') end - def initialize(_args = [], _options = {}, _config = {}) - # required by Thor::Actions - end - - def run(name, implementation_guide = nil) + def create_app @name = name + @ig = options['implementation-guide'] ## Template Generation: # copies all files from ./templates/ folder @@ -27,7 +32,7 @@ def run(name, implementation_guide = nil) # replaces all %foo% file names with foo() method call directory('.', root_name, { mode: :preserve, recursive: true }) - case implementation_guide + case @ig when /^https?/, /^localhost/, /^\d+\.\d+\.\d+\.\d+/ say 'todo fetch url', color: :blue else From b6f41d2b64fee7fea64ee6be33d7a709a75a8794 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Mon, 13 Nov 2023 16:57:57 -0500 Subject: [PATCH 11/50] implementing IG loading --- lib/inferno/apps/cli/new/new.rb | 39 ++++++++++++++++--- .../docker-compose.background.yml.tt | 2 +- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index 63cdf8526..d7ae38339 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -1,4 +1,6 @@ require 'dry/inflector' +require 'faraday' +require 'fileutils' require 'thor' module Inferno @@ -24,7 +26,7 @@ def self.source_root def create_app @name = name - @ig = options['implementation-guide'] + @ig_url = options['implementation_guide'] ## Template Generation: # copies all files from ./templates/ folder @@ -32,12 +34,29 @@ def create_app # replaces all %foo% file names with foo() method call directory('.', root_name, { mode: :preserve, recursive: true }) - case @ig - when /^https?/, /^localhost/, /^\d+\.\d+\.\d+\.\d+/ - say 'todo fetch url', color: :blue + case @ig_url + when /^https?:\/\// + + response = Faraday.get(@ig_url) + if response.status == 200 + create_file(ig_file, response.body) + else + say "Failed to load #{@ig_url}", :red + say "Please add the implementation guide package.tgz file into #{ig_path}", :red + end + when /^file:/ + @ig_url.rchomp! 'file:'.reverse # TODO test + begin + FileUtils.cp(@ig_url, ig_file) + rescue + say "Failed to load #{@ig_url}", :red + say "Please add the implementation guide package.tgz file into #{ig_path}", :red + end else - say "If you want to test against a FHIR implementation guide, please copy its package.tgz file into #{File.join(root_name, 'lib', lib_name, 'igs')}", color: :yellow + say "If you want to test against an implementation guide, add its package.tgz file into #{ig_path}" end + + say "Successfully created #{root_name} test kit!", :green end # root folder name, i.e: inferno-template @@ -69,6 +88,16 @@ def title_name def test_suite_id "#{lib_name}_test_suite" end + + # path to where package.tgz should reside, i.e: lib/inferno_template/igs + def ig_path + File.join('lib', lib_name, 'igs') + end + + # path to package.tgz including file, i.e: lib/inferno_template/igs/package.tgz + def ig_file + File.join( ig_path, 'package.tgz' ) + end end end end diff --git a/lib/inferno/apps/cli/new/templates/docker-compose.background.yml.tt b/lib/inferno/apps/cli/new/templates/docker-compose.background.yml.tt index 9300cdf2e..423f723e3 100644 --- a/lib/inferno/apps/cli/new/templates/docker-compose.background.yml.tt +++ b/lib/inferno/apps/cli/new/templates/docker-compose.background.yml.tt @@ -4,7 +4,7 @@ services: image: infernocommunity/fhir-validator-service # Update this path to match your directory structure volumes: - - ./lib/<%= lib_name %>/igs:/home/igs + - ./<%= ig_path %>:/home/igs fhir_validator_app: image: infernocommunity/fhir-validator-app depends_on: From 5e2831d36385360ae72a24401036ae90affe86fa Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Tue, 14 Nov 2023 13:54:03 -0500 Subject: [PATCH 12/50] debugging --- lib/inferno/apps/cli/new/new.rb | 65 +++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index d7ae38339..472804ee2 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -9,15 +9,30 @@ class New < Thor::Group include Thor::Actions desc <<~HELP - Generate a new Inferno test kit for FHIR - HELP + Generate a new Inferno test kit for FHIR software testing - argument :name, type: :string, required: true, desc: 'name for new Inferno project' + https://github.com/inferno-framework + HELP - class_option :implementation_guide, aliases: '-i', default: nil, banner: 'IG_URL', desc: 'URL to a FHIR Implementation Guide or path to a package.tgz' + argument :name, + type: :string, + required: true, + desc: 'name for new Inferno project' + class_option :implementation_guide, + type: :string, + aliases: '-i', + default: nil, + banner: 'IG_URL', + desc: 'URL to a FHIR Implementation Guide or path to a package.tgz' + class_option :author, + type: :string, + aliases: '-a', + default: fetch_user(), + repeatable: true, + desc: 'Author names for *.gemspec file; you can specify this more than once' @@inflector = Dry::Inflector.new do |inflections| - inflections.acronym 'FHIR' + inflections.acronym 'FHIR', 'IG' end def self.source_root @@ -26,7 +41,8 @@ def self.source_root def create_app @name = name - @ig_url = options['implementation_guide'] + @ig_uri = options['implementation_guide'] + @authors = options['author'] ## Template Generation: # copies all files from ./templates/ folder @@ -34,29 +50,30 @@ def create_app # replaces all %foo% file names with foo() method call directory('.', root_name, { mode: :preserve, recursive: true }) - case @ig_url + case @ig_uri when /^https?:\/\// - - response = Faraday.get(@ig_url) - if response.status == 200 + @ig_uri = @ig_uri.gsub(/[^\/]*\.html\s*$/, 'package.tgz') + @ig_uri = File.join(@ig_uri, 'package.tgz') unless @ig_uri.ends_with? 'package.tgz' + + response = Faraday.get(@ig_uri) + if response.status == 200 # TODO validate file because an incorrect package.tgz will break inferno create_file(ig_file, response.body) else - say "Failed to load #{@ig_url}", :red + say "Failed to load #{@ig_uri}", :red say "Please add the implementation guide package.tgz file into #{ig_path}", :red end - when /^file:/ - @ig_url.rchomp! 'file:'.reverse # TODO test + when ->(ig_uri) { ig_uri.nil? } + say "If you want to test for an implementation guide, add its package.tgz file into #{ig_path}" + else begin - FileUtils.cp(@ig_url, ig_file) + FileUtils.cp(@ig_uri, ig_file) rescue - say "Failed to load #{@ig_url}", :red + say "Failed to load #{@ig_uri}", :red say "Please add the implementation guide package.tgz file into #{ig_path}", :red end - else - say "If you want to test against an implementation guide, add its package.tgz file into #{ig_path}" end - say "Successfully created #{root_name} test kit!", :green + say "Created #{root_name} test kit!", :green end # root folder name, i.e: inferno-template @@ -96,7 +113,17 @@ def ig_path # path to package.tgz including file, i.e: lib/inferno_template/igs/package.tgz def ig_file - File.join( ig_path, 'package.tgz' ) + File.join(ig_path, 'package.tgz') + end + + def ig_load_failed_error + say "Failed to load #{@ig_uri}", :red + say "Please add the implementation guide package.tgz file into #{ig_path}", :red + end + + # returns system username or 'TODO' in an array + def fetch_user() + [ ENV['USER'] || ENV['USERNAME'] || 'TODO' ] end end end From 4c1f7be00523cee1b04ff82be8fe39ce25ff24f7 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Tue, 14 Nov 2023 14:30:14 -0500 Subject: [PATCH 13/50] debugging --- lib/inferno/apps/cli/new/new.rb | 24 ++++++++++++------- .../cli/new/templates/%lib_name%.gemspec.tt | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index 472804ee2..37eb911a7 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -14,6 +14,10 @@ class New < Thor::Group https://github.com/inferno-framework HELP + def self.source_root + File.join(__dir__, 'templates') + end + argument :name, type: :string, required: true, @@ -27,7 +31,7 @@ class New < Thor::Group class_option :author, type: :string, aliases: '-a', - default: fetch_user(), + default: [], repeatable: true, desc: 'Author names for *.gemspec file; you can specify this more than once' @@ -35,14 +39,11 @@ class New < Thor::Group inflections.acronym 'FHIR', 'IG' end - def self.source_root - File.join(__dir__, 'templates') - end - def create_app @name = name @ig_uri = options['implementation_guide'] @authors = options['author'] + @authors << fetch_user() if @authors.empty? ## Template Generation: # copies all files from ./templates/ folder @@ -73,7 +74,7 @@ def create_app end end - say "Created #{root_name} test kit!", :green + say "Created #{root_name} Inferno test kit!", :green end # root folder name, i.e: inferno-template @@ -106,6 +107,8 @@ def test_suite_id "#{lib_name}_test_suite" end + private + # path to where package.tgz should reside, i.e: lib/inferno_template/igs def ig_path File.join('lib', lib_name, 'igs') @@ -116,15 +119,20 @@ def ig_file File.join(ig_path, 'package.tgz') end + #private + def ig_load_failed_error say "Failed to load #{@ig_uri}", :red say "Please add the implementation guide package.tgz file into #{ig_path}", :red end - # returns system username or 'TODO' in an array def fetch_user() - [ ENV['USER'] || ENV['USERNAME'] || 'TODO' ] + ENV['USER'] || ENV['USERNAME'] || 'TODO' end + + + + end end end diff --git a/lib/inferno/apps/cli/new/templates/%lib_name%.gemspec.tt b/lib/inferno/apps/cli/new/templates/%lib_name%.gemspec.tt index a5c16f4cf..86e68d8b1 100644 --- a/lib/inferno/apps/cli/new/templates/%lib_name%.gemspec.tt +++ b/lib/inferno/apps/cli/new/templates/%lib_name%.gemspec.tt @@ -1,7 +1,7 @@ Gem::Specification.new do |spec| spec.name = '<%= lib_name %>' spec.version = '0.0.1' - # spec.authors = ['TODO'] + spec.authors = <%= @authors %> # spec.email = ['TODO'] spec.date = Time.now.utc.strftime('%Y-%m-%d') spec.summary = '<%= title_name %> Test Kit' From cf384d7a8627575c5c0fa4ca6b7fec3c5bf8d70c Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Tue, 14 Nov 2023 15:53:58 -0500 Subject: [PATCH 14/50] debugging --- lib/inferno/apps/cli/main.rb | 2 +- lib/inferno/apps/cli/new/new.rb | 46 +++++++++++++++++---------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/inferno/apps/cli/main.rb b/lib/inferno/apps/cli/main.rb index 625eea2c2..89e254f69 100644 --- a/lib/inferno/apps/cli/main.rb +++ b/lib/inferno/apps/cli/main.rb @@ -51,7 +51,7 @@ def suites desc 'suite SUBCOMMAND ...ARGS', 'Perform suite-based operations' subcommand 'suite', Suite - register(New, 'new', 'new TEST_KIT_NAME [-i IG_URL]', 'create an Inferno test kit') + register(New, 'new', 'new TEST_KIT_NAME [-i IG_URL]', 'Create an Inferno test kit') end end end diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index 37eb911a7..142db4f2e 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -11,9 +11,13 @@ class New < Thor::Group desc <<~HELP Generate a new Inferno test kit for FHIR software testing - https://github.com/inferno-framework + https://inferno-framework.github.io/index.html HELP + def self.banner + 'inferno new TEST_KIT_NAME [-i IG_URL]' + end + def self.source_root File.join(__dir__, 'templates') end @@ -33,7 +37,9 @@ def self.source_root aliases: '-a', default: [], repeatable: true, - desc: 'Author names for *.gemspec file; you can specify this more than once' + desc: "Author names for gemspec file; you may use '-a' multiple times" + + add_runtime_options! # adds --force, --pretend, --quiet, --skip @@inflector = Dry::Inflector.new do |inflections| inflections.acronym 'FHIR', 'IG' @@ -49,7 +55,7 @@ def create_app # copies all files from ./templates/ folder # performs ERB substitution on all .tt files and removes .tt suffix # replaces all %foo% file names with foo() method call - directory('.', root_name, { mode: :preserve, recursive: true }) + directory('.', root_name, { mode: :preserve, recursive: true, verbose: !options['quiet'] }) case @ig_uri when /^https?:\/\// @@ -57,26 +63,26 @@ def create_app @ig_uri = File.join(@ig_uri, 'package.tgz') unless @ig_uri.ends_with? 'package.tgz' response = Faraday.get(@ig_uri) - if response.status == 200 # TODO validate file because an incorrect package.tgz will break inferno + if response.status == 200 create_file(ig_file, response.body) else - say "Failed to load #{@ig_uri}", :red - say "Please add the implementation guide package.tgz file into #{ig_path}", :red + ig_load_error end when ->(ig_uri) { ig_uri.nil? } - say "If you want to test for an implementation guide, add its package.tgz file into #{ig_path}" + say_unless_quiet "If you want to test for an implementation guide, add its package.tgz file into #{ig_path}" else begin FileUtils.cp(@ig_uri, ig_file) rescue - say "Failed to load #{@ig_uri}", :red - say "Please add the implementation guide package.tgz file into #{ig_path}", :red + ig_load_error end end - say "Created #{root_name} Inferno test kit!", :green + say_unless_quiet "Created #{root_name} Inferno test kit!", :green end + private + # root folder name, i.e: inferno-template def root_name @@inflector.dasherize(@name) @@ -107,32 +113,28 @@ def test_suite_id "#{lib_name}_test_suite" end - private - # path to where package.tgz should reside, i.e: lib/inferno_template/igs def ig_path File.join('lib', lib_name, 'igs') end - # path to package.tgz including file, i.e: lib/inferno_template/igs/package.tgz + # full path to package.tgz, i.e: inferno-template/lib/inferno_template/igs/package.tgz def ig_file - File.join(ig_path, 'package.tgz') + File.join(root_name, ig_path, 'package.tgz') end - #private - - def ig_load_failed_error - say "Failed to load #{@ig_uri}", :red - say "Please add the implementation guide package.tgz file into #{ig_path}", :red + def ig_load_error + say_error "Failed to load #{@ig_uri}", :red + say_error "Please add the implementation guide package.tgz file into #{ig_path}", :red end def fetch_user() ENV['USER'] || ENV['USERNAME'] || 'TODO' end - - - + def say_unless_quiet(*args) + say(*args) unless options['quiet'] + end end end end From e375731d1cebb1e8a4bc2c5acb0b28cfe685ec10 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Tue, 14 Nov 2023 15:57:58 -0500 Subject: [PATCH 15/50] debugging --- lib/inferno/apps/cli/new/new.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index 142db4f2e..b5da5ed24 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -72,7 +72,7 @@ def create_app say_unless_quiet "If you want to test for an implementation guide, add its package.tgz file into #{ig_path}" else begin - FileUtils.cp(@ig_uri, ig_file) + FileUtils.cp(@ig_uri, ig_file) unless options['pretend'] rescue ig_load_error end From 65e38423bebd7d4914517a6b93ae117fc322b96a Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Tue, 14 Nov 2023 16:19:58 -0500 Subject: [PATCH 16/50] debugging --- lib/inferno/apps/cli/new/templates/{run.sh.tt => run.sh} | 0 lib/inferno/apps/cli/new/templates/{setup.sh.tt => setup.sh} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename lib/inferno/apps/cli/new/templates/{run.sh.tt => run.sh} (100%) rename lib/inferno/apps/cli/new/templates/{setup.sh.tt => setup.sh} (100%) diff --git a/lib/inferno/apps/cli/new/templates/run.sh.tt b/lib/inferno/apps/cli/new/templates/run.sh similarity index 100% rename from lib/inferno/apps/cli/new/templates/run.sh.tt rename to lib/inferno/apps/cli/new/templates/run.sh diff --git a/lib/inferno/apps/cli/new/templates/setup.sh.tt b/lib/inferno/apps/cli/new/templates/setup.sh similarity index 100% rename from lib/inferno/apps/cli/new/templates/setup.sh.tt rename to lib/inferno/apps/cli/new/templates/setup.sh From 9cc9fc1a0e7a201d81d2d3c51c30fab535675899 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Tue, 14 Nov 2023 21:52:05 -0500 Subject: [PATCH 17/50] debugging --- .../new/templates/config/{database.yml.erb => database.yml.tt} | 0 .../{nginx.background.conf.erb => nginx.background.conf.tt} | 0 .../cli/new/templates/config/{nginx.conf.erb => nginx.conf.tt} | 0 .../apps/cli/new/templates/config/{puma.rb.erb => puma.rb.tt} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename lib/inferno/apps/cli/new/templates/config/{database.yml.erb => database.yml.tt} (100%) rename lib/inferno/apps/cli/new/templates/config/{nginx.background.conf.erb => nginx.background.conf.tt} (100%) rename lib/inferno/apps/cli/new/templates/config/{nginx.conf.erb => nginx.conf.tt} (100%) rename lib/inferno/apps/cli/new/templates/config/{puma.rb.erb => puma.rb.tt} (100%) diff --git a/lib/inferno/apps/cli/new/templates/config/database.yml.erb b/lib/inferno/apps/cli/new/templates/config/database.yml.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/config/database.yml.erb rename to lib/inferno/apps/cli/new/templates/config/database.yml.tt diff --git a/lib/inferno/apps/cli/new/templates/config/nginx.background.conf.erb b/lib/inferno/apps/cli/new/templates/config/nginx.background.conf.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/config/nginx.background.conf.erb rename to lib/inferno/apps/cli/new/templates/config/nginx.background.conf.tt diff --git a/lib/inferno/apps/cli/new/templates/config/nginx.conf.erb b/lib/inferno/apps/cli/new/templates/config/nginx.conf.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/config/nginx.conf.erb rename to lib/inferno/apps/cli/new/templates/config/nginx.conf.tt diff --git a/lib/inferno/apps/cli/new/templates/config/puma.rb.erb b/lib/inferno/apps/cli/new/templates/config/puma.rb.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/config/puma.rb.erb rename to lib/inferno/apps/cli/new/templates/config/puma.rb.tt From 2e91394961bc793cad3a82d12e5ca77cf3bde8b7 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 15 Nov 2023 11:30:04 -0500 Subject: [PATCH 18/50] debugging --- .../new/templates/spec/%lib_name%/patient_group_spec.rb.tt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/inferno/apps/cli/new/templates/spec/%lib_name%/patient_group_spec.rb.tt b/lib/inferno/apps/cli/new/templates/spec/%lib_name%/patient_group_spec.rb.tt index 5d9452f74..408f2b7b6 100644 --- a/lib/inferno/apps/cli/new/templates/spec/%lib_name%/patient_group_spec.rb.tt +++ b/lib/inferno/apps/cli/new/templates/spec/%lib_name%/patient_group_spec.rb.tt @@ -1,8 +1,8 @@ RSpec.describe <%= module_name %>::PatientGroup do - let(:suite) { Inferno::Repositories::TestSuites.new.find('test_suite_template') } + let(:suite) { Inferno::Repositories::TestSuites.new.find('<%= test_suite_id %>') } let(:group) { suite.groups[1] } let(:session_data_repo) { Inferno::Repositories::SessionData.new } - let(:test_session) { repo_create(:test_session, test_suite_id: 'test_suite_template') } + let(:test_session) { repo_create(:test_session, test_suite_id: '<%= test_suite_id %>') } let(:url) { 'http://example.com/fhir' } let(:error_outcome) { FHIR::OperationOutcome.new(issue: [{ severity: 'error' }]) } From 341981e63f8b37a414b9877c8b13da8e80f5a32e Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 15 Nov 2023 14:52:42 -0500 Subject: [PATCH 19/50] create new_spec file --- spec/inferno/apps/cli/new_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 spec/inferno/apps/cli/new_spec.rb diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb new file mode 100644 index 000000000..64c60f46a --- /dev/null +++ b/spec/inferno/apps/cli/new_spec.rb @@ -0,0 +1,14 @@ +require 'rspec' +require 'fileutils' +require 'inferno/apps/cli/new/new' +# require_relative '../../../../lib/inferno/apps/cli/new/new' + +RSpec.describe Inferno::CLI::New do + it "works" do + Dir.mktmpdir do |tmpdir| + FileUtils.chdir(tmpdir) do + expect { Inferno::CLI::New.start(["inferno_new_spec"]) }.not_to raise_error + end + end + end +end From cfe5638d755c8d593de0719fb3b21a5a39f47e52 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Fri, 17 Nov 2023 15:25:43 -0500 Subject: [PATCH 20/50] rspec testing for new generator WIP --- lib/inferno/apps/cli/new/new.rb | 3 +- spec/fixtures/small_package.tgz | Bin 0 -> 4085 bytes spec/inferno/apps/cli/new_spec.rb | 59 ++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 spec/fixtures/small_package.tgz diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index b5da5ed24..604f7536b 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -72,7 +72,7 @@ def create_app say_unless_quiet "If you want to test for an implementation guide, add its package.tgz file into #{ig_path}" else begin - FileUtils.cp(@ig_uri, ig_file) unless options['pretend'] + FileUtils.cp(@ig_uri, ig_file) unless options['pretend'] # TODO proper dry-run implementation rescue ig_load_error end @@ -126,6 +126,7 @@ def ig_file def ig_load_error say_error "Failed to load #{@ig_uri}", :red say_error "Please add the implementation guide package.tgz file into #{ig_path}", :red + raise StandardError.new("Failed to load #{@ig_uri}") end def fetch_user() diff --git a/spec/fixtures/small_package.tgz b/spec/fixtures/small_package.tgz new file mode 100644 index 0000000000000000000000000000000000000000..881a81440420afbab622cfb3973a12a4ac73fb7e GIT binary patch literal 4085 zcmZuzXD}R&w-wQ%_qNy{LGM~=rN?dc9O85H#DWD z>ld8nG32|Oh;}bQed1XdmSr9DdypQV)3Hlvmh&X!>#K5Pl|=a0P@JCqHR`^@A(y&Q zvAR|-i!~QhD;051Z|{PCQBUA1D%^%*<8UNp<|2DjPpZaj$z9q|-v}GDvWQYMYclom zp7R`YWuL9ps4=rvX$ij1qE6!y_}S!o)+S5}^pbK{GJ~WcZL8YcZ?pyAj)4hj#N??oZYGi~) zJ*)snHT-n8Xor-MQ_YlbaclWwI{LhF2u$cegYDb2h9cWKze*?y?)P~%-b}OSEbKfB z2u^wOv~|qsg-}wxR&rl0n3N%q3mxck7~EB6e;eXvY~sVXBhATkAmjLnpc7D03q!Ackf6z86JHp!=d#D4uVAGQlLzSlu# zh<4P`-^?F&Yrd+#dr7gNtV9Dq3EjuH7xS~}Q+&dCZ~|KpnISmitQ`A(K`saW@k^Vb zc?A1yf+Gn(WCz&WXRjFs{>QU)r5=p&B!)J7wnzSvN4V8B|HngH+dh* zMGUzVe>!#pfk5+g^=5zraV&i2vY*qD{Fzl2-4OMg@gHvAd}y8GdV3gA`|0m0wXZ?%M5jTaW{NA zqmB&{j+JQpE$6L}(^24w(bi|qnACuagO#1(NQxC;()9(=+4Xe_Pyxcd&?TVonQ3_~ z+Uv{V83~iQJ8tkDsvU&_rB6t=n^P1y#~(sUGl3l zXF_ZLzBXD!uCDpFTUO^M(z=QSkJ^t@ZnSn>x(g5JwFk?zSdpIxSZdnIDwyK#tpnFN zj!6!ETV%7H_{L0x!BW`T$N^{4aL+iO_B*k{2cori6PvpI0g$wneY8j;f1{xpt1BOO z$^IirXnZ6#jN{Oyx~UgS6gC`*Iom0tTX$9#f&0R4c_=`Sxys6+2-tDPq0)SMaoCQ3 zxi`98rTy)jeIlO$@cF@ID~Uh zjq{Y7uaWOjBM5SrORB02W9vaE`sn(>1GUtS(Ce=%*HNgEPaJ}8Km*(yFLGjjiiACB zRCNkXG9XyJ-+&|;sON91aCMY;Pmr~g&KN5>t!eUxznMS7cSY&U5i%oXYRRv}i-s7c z(hyF1`MKofL3{KRjj{_b2YgFKVw)<_BoSp9aiNBSk7B>(?&z^CMxjaQb}LKx?&nkJ z$;yZ;Dtw6d6_{4Cv3z44%E$>(HVz8!@Z=qW4_{AnSstdh7KuS(;~i zRUTj@KdS>V7}qGQIZ>Z%R`fIX9OyC;(w$#9BPz>{TAQ3nBs$|EgXhk4@mLvq=siE#Q^(-nrX0vuhMAZKyMwD+ z%HzGGW=vdoSt^(Q7?|lguo>Q zuuB~xI5lDM#cyhO#h~;-?^(lq_PrXPI#9)4ja!YdvdOfOHC|Qu2Lzs>oS;|I0TIfb zuB`^~22mMM<5j3Xu!CRM)c3I~WxQj^uH7T`oD0TD)b)7Bu{*;HPoeEpHgN$(mxd3e z0-;s%mni0w!RPf!^VF$o(6=E;REM1obnrxo#=UVK=LzJwIu?J?5q%5t27e>-$a(sO zn8x=BsW-n^^o^{x1@nO@Q?dl<750=o9Gvdv$d32xwT3F&JA8Y+(MZLF!hHJ$O8cqA zzSXKAja~zwTRd>{bwK(!Sv33P)z{>-Fsx5!=l0) z6ng`umT-*~FIqbNst4k?$}Jc0+mH`@!_w|!KiIM{QK z%lcQy+8^&TTDHwV3B?;UzdsYiq(HV+pWpGhxIQX>CLit3o(8GeQ!DQim$iO%a~e>= zeHWn?nJp)c=Qm{i+Vvd{J})C2jvLQPeTSPr#yz>S|AMoh*Y?=Dj9|z4{LS!n9K#W< zem+tfTJlj8?+r*@SIhK_Va%a=PxuMfvL+~El2%I!q%rL}d%+?c7gULnveKw5T61S9 z34xWm#Oz?-Wz$q|gYu+9jc+t1f~(t!pQoKwU#HrU*8N9R5N-GbtyBbqY|Ev3gk)tq zRBxMG;a3&7JuhFgk64@1qpaDtwVE59J%2owH+zg*U-8L8?C<=y%|8Y)<62VtZGYX@ zAnY<*(0>6%4QRD@*PrG;fPT#%F=RW34KVb7R7Vz{2i)LhM{HY!oBtAb|94iv4e~#> zJlhp`j&Wd;Z}mF&_e|0+PF~r0*|6d4oAT<$B<~`c8s2)C)p&btUE*qraCg@^L4qVK zcA}X8W{=WDF8g3R)KPj)jzTNBKLdYQhEQ3H+MYx9+}rpi27U_cDRangD)LY=$r?b&XLt~hOtdVl(+m0He# zs0+f~#z?$z%WrZb@MqtLHS5E!a^J?mc@FkakB}IM@yRerojq@+qzAUXmVdZ{eyLdE z2QjX1U9T-`&0pu4jrDdtci|%EL(r0=P$*3^Xe3YVa<5?6N3Tmtd>Q z+Hn^i!J%tEF}Svk3*0_(04ZyMg(akpIA+nE51`5k1<-g` z+|XL?R?>-Wgo+?rNf`mv#j|!>RFlm@%#&9TG&zFkCI-u=z`GGs;N|aAnkete_RUGu zG_+5~vt{!dcG#wyj_3p*u3r}%w#`vqbjyeBBoe-K_tMMVxydAUr7xXa#$3t^qc-EuqYmgr@fORg)!kN}J%M^e!mK7-`_KJzp(~A5#g_fsMA|q&w zOq~idolL8+%v#CtPaWQKLM>tb=HsPwl{&K;-+mz&RUiVWh+2Z4pC0Xg80$BOP!@W7 zfmTBllu14^wZx^#FRo%eB7e24iB7Hyk`_hOAJFMy+H)`KGqLNZ93hfPe5&jgWJ#eJ zoT~=*8wH5NDi-PdhD~3fi^LJAmNIvP*zL$?(#Q2vZ2Cn6!*-b%+#E`ncY24Mt;|}* zN$uokLvcY2+y%%16y_GO(|4hMHBt@*O<4*+VOI%bcX829Ie?!;nW1tr<&8oz+Xg=i zc*CKtM|}Bb@Jw#6jjrXgrW`G~b(re>SHsHYyN(YR6GJgb95KE3zu>If&nDw^f#H|OkNsml zX=m{2=Se=FD*IcwmPfo0!rf(zgRSq}OqchsxDcaz)FUT_KA@0>GY22CebB$3o8Fx8 zyPutpm=6p>_BpeOXa{_V0*M0SVc;cI$VE`#oDaP7D@)jr^TI)if{Uf|33SUYlMQz^ z<~zJb4G&e`W}f@JvBDRxul~x!FRXOf!u=RfC^nqptMzWfUWPsE=4SA`mC7zGrF-Fu zqmH-0&U&fy?B}DkFhnPJt;}g1nHyFW3M#pT<^qdV1#!uRySN_BJLwzyyURqL%ZmTI zk>v9y5Jg3s?pwrhPGKEn<6;5isFBHR?QqvE)aUs|zFH{arttq^8NsZ8oww_Iyz%O# Ub7k7o=q=od%(?~M79QSz0ZT(K7ytkO literal 0 HcmV?d00001 diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 64c60f46a..8e2317de4 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -1,14 +1,67 @@ require 'rspec' require 'fileutils' require 'inferno/apps/cli/new/new' -# require_relative '../../../../lib/inferno/apps/cli/new/new' + RSpec.describe Inferno::CLI::New do - it "works" do + +# def run_generator(*args) +# Inferno::CLI::New.start(args) +# end + + around(:each) do |test| Dir.mktmpdir do |tmpdir| FileUtils.chdir(tmpdir) do - expect { Inferno::CLI::New.start(["inferno_new_spec"]) }.not_to raise_error + test.run end end end + + + it 'works' do + expect { Inferno::CLI::New.start(['spec_1', '--quiet']) }.not_to raise_error + + expect(Dir).to exist('spec-1') + expect(File).to exist('spec-1/Gemfile') + expect(File).to exist('spec-1/spec_1.gemspec') + end + + + shared_examples 'working inferno project' do |name, lib_name| + it 'has root directory' do + expect(Dir).to exist(name) + end + + it 'has Gemfile' do + expect(File).to exist("#{name}/Gemfile") + end + + it 'has gemspec' do + expect(File).to exist("#{name}/#{lib_name}.gemspec") + end + end + + context 'TODO' do + +# +# it 'with an http implementation guide should create an Inferno project' do +# expect { Inferno::CLI::New.start(['spec_2', '--implementation-guide', 'http://build.fhir.org/ig/HL7/US-Core/']) }.not_to raise_error +# +# expect { File.directory?('spec-2') }.to be true +# expect { File.exist?('spec-2/Gemfile') }.to be true +# expect { File.exist?('spec-2/spec_2.gemspec') }.to be true +# end +# +# it 'with an absolute path to an implementation guide should create an Inferno project' do +# absolute_path_to_ig = File.expand_path('../../../../fixtures/small_package.tgz', __FILE__) +# +# expect { Inferno::CLI::New.start(['spec_3', '--implementation-guide', absolute_path_to_ig, '--quiet']) }.not_to raise_error +# +# expect { File.directory?('spec-3') }.to be true +# expect { File.exist?('spec-3/Gemfile') }.to be true +# expect { File.exist?('spec-3/spec_1.gemspec') }.to be true +# end +# + end + end From 3ab2f69289e6c690277a129ba7242e98665ac366 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Tue, 21 Nov 2023 15:28:07 -0500 Subject: [PATCH 21/50] factorize rspec for inferno new --- spec/inferno/apps/cli/new_spec.rb | 81 +++++++++++++++---------------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 8e2317de4..09f3782ff 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -5,10 +5,9 @@ RSpec.describe Inferno::CLI::New do -# def run_generator(*args) -# Inferno::CLI::New.start(args) -# end - + ABSOLUTE_PATH_TO_IG = File.expand_path(__FILE__, '../../../fixtures/small_package.tgz') + + # Wrap all 'it' examples in a temp dir around(:each) do |test| Dir.mktmpdir do |tmpdir| FileUtils.chdir(tmpdir) do @@ -17,51 +16,47 @@ end end + # NOTE: WebMock blocks real HTTP requests for some reason: https://stackoverflow.com/a/22976546 + # Re-enabling it for testing online IG pull + WebMock.allow_net_connect! + + # test various `inferno new ...` + [ + %w(spec-1 --quiet), + %w(spec-1 --implementation-guide https://build.fhir.org/ig/HL7/US-Core/ --quiet), + %w(spec-1 --implementation-guide https://build.fhir.org/ig/HL7/US-Core/index.html --quiet), + %w(spec-1 --implementation-guide https://build.fhir.org/ig/HL7/US-Core/package.tgz --quiet), + %W(spec-1 --implementation-guide #{ABSOLUTE_PATH_TO_IG} --quiet), + %w(spec-1 --author ABC --author DEF --quiet) + ].each do |cli_args| + it "generates Inferno project with #{cli_args}" do + expect { Inferno::CLI::New.start(cli_args) }.not_to raise_error + + expect(Dir).to exist('spec-1') + expect(File).to exist('spec-1/Gemfile') + expect(File).to exist('spec-1/spec_1.gemspec') + expect(File).to exist('spec-1/lib/spec_1.rb') + + if cli_args.include? '--implementation-guide' + expect(File).to exist('spec-1/lib/spec_1/igs/package.tgz') + end - it 'works' do - expect { Inferno::CLI::New.start(['spec_1', '--quiet']) }.not_to raise_error - - expect(Dir).to exist('spec-1') - expect(File).to exist('spec-1/Gemfile') - expect(File).to exist('spec-1/spec_1.gemspec') - end - - - shared_examples 'working inferno project' do |name, lib_name| - it 'has root directory' do - expect(Dir).to exist(name) + if cli_args.include? '--author' + expect(File.read('spec-1/spec_1.gemspec')).to match(/authors\s*=.*ABC.*DEF/) + end end + end - it 'has Gemfile' do - expect(File).to exist("#{name}/Gemfile") - end + # test `inferno new ... --pretend` + it 'does not create Inferno project with ["spec-1", "--pretend", "--quiet"]' do + expect { Inferno::CLI::New.start(%w(spec-1 --pretend --quiet)) }.not_to raise_error - it 'has gemspec' do - expect(File).to exist("#{name}/#{lib_name}.gemspec") - end + expect(Dir).not_to exist('spec-1') end - context 'TODO' do - -# -# it 'with an http implementation guide should create an Inferno project' do -# expect { Inferno::CLI::New.start(['spec_2', '--implementation-guide', 'http://build.fhir.org/ig/HL7/US-Core/']) }.not_to raise_error -# -# expect { File.directory?('spec-2') }.to be true -# expect { File.exist?('spec-2/Gemfile') }.to be true -# expect { File.exist?('spec-2/spec_2.gemspec') }.to be true -# end -# -# it 'with an absolute path to an implementation guide should create an Inferno project' do -# absolute_path_to_ig = File.expand_path('../../../../fixtures/small_package.tgz', __FILE__) -# -# expect { Inferno::CLI::New.start(['spec_3', '--implementation-guide', absolute_path_to_ig, '--quiet']) }.not_to raise_error -# -# expect { File.directory?('spec-3') }.to be true -# expect { File.exist?('spec-3/Gemfile') }.to be true -# expect { File.exist?('spec-3/spec_1.gemspec') }.to be true -# end -# + # test `inferno new ... --skip` and `inferno new ... --force` + it 'asdf' do + # TODO end end From 7c894e08112197ba09f7be45298d62a2f8ed98ca Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 22 Nov 2023 11:53:42 -0500 Subject: [PATCH 22/50] replace FileUtils.copy_file with Thor::Actions#get to support --pretend --- lib/inferno/apps/cli/new/new.rb | 22 +++++++--------------- spec/inferno/apps/cli/new_spec.rb | 2 +- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index 604f7536b..7834589e2 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -1,6 +1,4 @@ require 'dry/inflector' -require 'faraday' -require 'fileutils' require 'thor' module Inferno @@ -57,28 +55,22 @@ def create_app # replaces all %foo% file names with foo() method call directory('.', root_name, { mode: :preserve, recursive: true, verbose: !options['quiet'] }) - case @ig_uri - when /^https?:\/\// + if @ig_uri @ig_uri = @ig_uri.gsub(/[^\/]*\.html\s*$/, 'package.tgz') @ig_uri = File.join(@ig_uri, 'package.tgz') unless @ig_uri.ends_with? 'package.tgz' - response = Faraday.get(@ig_uri) - if response.status == 200 - create_file(ig_file, response.body) - else - ig_load_error - end - when ->(ig_uri) { ig_uri.nil? } - say_unless_quiet "If you want to test for an implementation guide, add its package.tgz file into #{ig_path}" - else begin - FileUtils.cp(@ig_uri, ig_file) unless options['pretend'] # TODO proper dry-run implementation - rescue + get(@ig_uri, ig_file, verbose: !options['quiet']) + rescue Exception => err + say_unless_quiet err.message, :red ig_load_error + else + say_unless_quiet "Loaded implementation guide #{@ig_uri}", :green end end say_unless_quiet "Created #{root_name} Inferno test kit!", :green + say_unless_quiet 'This was a dry run; re-run without `--pretend` to actually create project', :yellow if options['pretend'] end private diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 09f3782ff..388c5fa8d 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Inferno::CLI::New do - ABSOLUTE_PATH_TO_IG = File.expand_path(__FILE__, '../../../fixtures/small_package.tgz') + ABSOLUTE_PATH_TO_IG = File.expand_path('../../../../fixtures/small_package.tgz', __FILE__) # Wrap all 'it' examples in a temp dir around(:each) do |test| From fb18c1f73ae4cc1f54635f6e34613b243ae93b87 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 22 Nov 2023 12:12:37 -0500 Subject: [PATCH 23/50] add and fix name normalization tests --- lib/inferno/apps/cli/new/new.rb | 4 +-- spec/inferno/apps/cli/new_spec.rb | 46 ++++++++++++++----------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index 7834589e2..8e66ef3d7 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -40,7 +40,7 @@ def self.source_root add_runtime_options! # adds --force, --pretend, --quiet, --skip @@inflector = Dry::Inflector.new do |inflections| - inflections.acronym 'FHIR', 'IG' + inflections.acronym 'FHIR' end def create_app @@ -77,7 +77,7 @@ def create_app # root folder name, i.e: inferno-template def root_name - @@inflector.dasherize(@name) + @@inflector.dasherize(@@inflector.underscore(@name)) end # library name, i.e: inferno_template diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 388c5fa8d..4fc34a592 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -1,5 +1,4 @@ require 'rspec' -require 'fileutils' require 'inferno/apps/cli/new/new' @@ -11,52 +10,49 @@ around(:each) do |test| Dir.mktmpdir do |tmpdir| FileUtils.chdir(tmpdir) do + WebMock.allow_net_connect! test.run + WebMock.disable_net_connect! end end end - # NOTE: WebMock blocks real HTTP requests for some reason: https://stackoverflow.com/a/22976546 - # Re-enabling it for testing online IG pull - WebMock.allow_net_connect! - # test various `inferno new ...` + # test various `inferno new ...` options [ - %w(spec-1 --quiet), - %w(spec-1 --implementation-guide https://build.fhir.org/ig/HL7/US-Core/ --quiet), - %w(spec-1 --implementation-guide https://build.fhir.org/ig/HL7/US-Core/index.html --quiet), - %w(spec-1 --implementation-guide https://build.fhir.org/ig/HL7/US-Core/package.tgz --quiet), - %W(spec-1 --implementation-guide #{ABSOLUTE_PATH_TO_IG} --quiet), - %w(spec-1 --author ABC --author DEF --quiet) + %w(test-fhir-app --quiet), + %w(test_fhir_app --quiet), + %w(TestFHIRApp --quiet), + %w(TestFhirApp --quiet), + %w(test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/ --quiet), + %w(test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/index.html --quiet), + %w(test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/package.tgz --quiet), + %W(test-fhir-app --implementation-guide #{ABSOLUTE_PATH_TO_IG} --quiet), + %w(test-fhir-app --author ABC --author DEF --quiet) ].each do |cli_args| it "generates Inferno project with #{cli_args}" do expect { Inferno::CLI::New.start(cli_args) }.not_to raise_error - expect(Dir).to exist('spec-1') - expect(File).to exist('spec-1/Gemfile') - expect(File).to exist('spec-1/spec_1.gemspec') - expect(File).to exist('spec-1/lib/spec_1.rb') + expect(Dir).to exist('test-fhir-app') + expect(File).to exist('test-fhir-app/Gemfile') + expect(File).to exist('test-fhir-app/test_fhir_app.gemspec') + expect(File).to exist('test-fhir-app/lib/test_fhir_app.rb') if cli_args.include? '--implementation-guide' - expect(File).to exist('spec-1/lib/spec_1/igs/package.tgz') + expect(File).to exist('test-fhir-app/lib/test_fhir_app/igs/package.tgz') end if cli_args.include? '--author' - expect(File.read('spec-1/spec_1.gemspec')).to match(/authors\s*=.*ABC.*DEF/) + expect(File.read('test-fhir-app/test_fhir_app.gemspec')).to match(/authors\s*=.*ABC.*DEF/) end end end # test `inferno new ... --pretend` - it 'does not create Inferno project with ["spec-1", "--pretend", "--quiet"]' do - expect { Inferno::CLI::New.start(%w(spec-1 --pretend --quiet)) }.not_to raise_error + it 'does not generate Inferno project with ["test-fhir-app", "--pretend", "--quiet"]' do + expect { Inferno::CLI::New.start(%w(test-fhir-app --pretend --quiet)) }.not_to raise_error - expect(Dir).not_to exist('spec-1') - end - - # test `inferno new ... --skip` and `inferno new ... --force` - it 'asdf' do - # TODO + expect(Dir).not_to exist('test-fhir-app') end end From 179a7fb04a40246853d8ce88affbb4d9f5b9dcfd Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 22 Nov 2023 12:56:20 -0500 Subject: [PATCH 24/50] update help description --- lib/inferno/apps/cli/main.rb | 2 +- lib/inferno/apps/cli/new/new.rb | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/inferno/apps/cli/main.rb b/lib/inferno/apps/cli/main.rb index 89e254f69..d2530e41c 100644 --- a/lib/inferno/apps/cli/main.rb +++ b/lib/inferno/apps/cli/main.rb @@ -51,7 +51,7 @@ def suites desc 'suite SUBCOMMAND ...ARGS', 'Perform suite-based operations' subcommand 'suite', Suite - register(New, 'new', 'new TEST_KIT_NAME [-i IG_URL]', 'Create an Inferno test kit') + register(New, 'new', 'new TEST_KIT_NAME [-i IG_URL]', 'Run `inferno new --help` for full help') end end end diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index 8e66ef3d7..7a9370c42 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -9,6 +9,17 @@ class New < Thor::Group desc <<~HELP Generate a new Inferno test kit for FHIR software testing + Examples: + + `inferno new test_fhir_app` + => generates an Inferno app + + `inferno new test_us_core -i https://build.fhir.org/ig/HL7/US-Core/` + => generates Inferno app and loads US Core implementation guide + + `inferno new test_my_ig -i /absolute/path/to/ig/package.tgz -a Name` + => generates Inferno app, loads a local implementation guide, and specifies Name as author + https://inferno-framework.github.io/index.html HELP @@ -29,7 +40,7 @@ def self.source_root aliases: '-i', default: nil, banner: 'IG_URL', - desc: 'URL to a FHIR Implementation Guide or path to a package.tgz' + desc: 'URL to an implementation guide or absolute path to a package.tgz' class_option :author, type: :string, aliases: '-a', From da8ff3c313fc5adb66af8c36bcc276c2401c66a4 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 22 Nov 2023 13:41:23 -0500 Subject: [PATCH 25/50] debugging --- lib/inferno/apps/cli/new/new.rb | 23 ++++++----- .../cli/new/templates/lib/%lib_name%.rb.tt | 2 +- .../{put_ig_package_dot_tgz_here => .keep} | 0 spec/inferno/apps/cli/new_spec.rb | 39 ++++++++++--------- 4 files changed, 34 insertions(+), 30 deletions(-) rename lib/inferno/apps/cli/new/templates/lib/%lib_name%/igs/{put_ig_package_dot_tgz_here => .keep} (100%) diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index 7a9370c42..dac8360ef 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -58,7 +58,7 @@ def create_app @name = name @ig_uri = options['implementation_guide'] @authors = options['author'] - @authors << fetch_user() if @authors.empty? + @authors << fetch_user if @authors.empty? ## Template Generation: # copies all files from ./templates/ folder @@ -67,13 +67,13 @@ def create_app directory('.', root_name, { mode: :preserve, recursive: true, verbose: !options['quiet'] }) if @ig_uri - @ig_uri = @ig_uri.gsub(/[^\/]*\.html\s*$/, 'package.tgz') + @ig_uri = @ig_uri.gsub(%r{[^/]*\.html\s*$}, 'package.tgz') @ig_uri = File.join(@ig_uri, 'package.tgz') unless @ig_uri.ends_with? 'package.tgz' begin get(@ig_uri, ig_file, verbose: !options['quiet']) - rescue Exception => err - say_unless_quiet err.message, :red + rescue StandardError => e + say_unless_quiet e.message, :red ig_load_error else say_unless_quiet "Loaded implementation guide #{@ig_uri}", :green @@ -81,7 +81,10 @@ def create_app end say_unless_quiet "Created #{root_name} Inferno test kit!", :green - say_unless_quiet 'This was a dry run; re-run without `--pretend` to actually create project', :yellow if options['pretend'] + if options['pretend'] + say_unless_quiet 'This was a dry run; re-run without `--pretend` to actually create project', + :yellow + end end private @@ -103,12 +106,12 @@ def module_name # English grammatical name, i.e: Inferno template def human_name - @@inflector.humanize(@name) + @@inflector.humanize(@@inflector.camelize(@name)) end # title case name, i.e: Inferno Template def title_name - human_name.split.map{ |s| s.capitalize }.join(' ') + human_name.split.map { |s| s.capitalize }.join(' ') end # suffix '_test_suite' in snake case, i.e: inferno_template_test_suite @@ -128,11 +131,11 @@ def ig_file def ig_load_error say_error "Failed to load #{@ig_uri}", :red - say_error "Please add the implementation guide package.tgz file into #{ig_path}", :red - raise StandardError.new("Failed to load #{@ig_uri}") + say_error "Please add the implementation guide package.tgz file into #{ig_path}", :red + raise StandardError, "Failed to load #{@ig_uri}" end - def fetch_user() + def fetch_user ENV['USER'] || ENV['USERNAME'] || 'TODO' end diff --git a/lib/inferno/apps/cli/new/templates/lib/%lib_name%.rb.tt b/lib/inferno/apps/cli/new/templates/lib/%lib_name%.rb.tt index e2a40de7f..869b4a2f9 100644 --- a/lib/inferno/apps/cli/new/templates/lib/%lib_name%.rb.tt +++ b/lib/inferno/apps/cli/new/templates/lib/%lib_name%.rb.tt @@ -4,7 +4,7 @@ module <%= module_name %> class Suite < Inferno::TestSuite id :<%= test_suite_id %> title '<%= title_name %> Test Suite' - description 'Inferno <%= human_name.downcase %> test suite for FHIR testing' + description 'Inferno <%= human_name.downcase %> test suite for FHIR' # These inputs will be available to all tests in this suite input :url, diff --git a/lib/inferno/apps/cli/new/templates/lib/%lib_name%/igs/put_ig_package_dot_tgz_here b/lib/inferno/apps/cli/new/templates/lib/%lib_name%/igs/.keep similarity index 100% rename from lib/inferno/apps/cli/new/templates/lib/%lib_name%/igs/put_ig_package_dot_tgz_here rename to lib/inferno/apps/cli/new/templates/lib/%lib_name%/igs/.keep diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 4fc34a592..2b27de56e 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -1,13 +1,12 @@ require 'rspec' require 'inferno/apps/cli/new/new' +ABSOLUTE_PATH_TO_IG = File.expand_path('../../../fixtures/small_package.tgz', __dir__) RSpec.describe Inferno::CLI::New do - ABSOLUTE_PATH_TO_IG = File.expand_path('../../../../fixtures/small_package.tgz', __FILE__) - # Wrap all 'it' examples in a temp dir - around(:each) do |test| + around do |test| Dir.mktmpdir do |tmpdir| FileUtils.chdir(tmpdir) do WebMock.allow_net_connect! @@ -17,27 +16,30 @@ end end - # test various `inferno new ...` options [ - %w(test-fhir-app --quiet), - %w(test_fhir_app --quiet), - %w(TestFHIRApp --quiet), - %w(TestFhirApp --quiet), - %w(test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/ --quiet), - %w(test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/index.html --quiet), - %w(test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/package.tgz --quiet), - %W(test-fhir-app --implementation-guide #{ABSOLUTE_PATH_TO_IG} --quiet), - %w(test-fhir-app --author ABC --author DEF --quiet) + %w[test-fhir-app --quiet], + %w[test_fhir_app --quiet], + %w[TestFHIRApp --quiet], + %w[TestFhirApp --quiet], + %w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/ --quiet], + %w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/index.html --quiet], + %w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/package.tgz --quiet], + %W[test-fhir-app --implementation-guide #{ABSOLUTE_PATH_TO_IG} --quiet], + %w[test-fhir-app --author ABC --author DEF --quiet] ].each do |cli_args| - it "generates Inferno project with #{cli_args}" do - expect { Inferno::CLI::New.start(cli_args) }.not_to raise_error + it "runs inferno new #{cli_args.join(' ')}" do + expect { Inferno::CLI::New.start(cli_args) }.to_not raise_error expect(Dir).to exist('test-fhir-app') expect(File).to exist('test-fhir-app/Gemfile') expect(File).to exist('test-fhir-app/test_fhir_app.gemspec') expect(File).to exist('test-fhir-app/lib/test_fhir_app.rb') - + expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to include('module TestFHIRApp') + expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to include('id :test_fhir_app_test_suite') + expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to include("title 'Test FHIR App test suite'") + expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to match(/description.+Test FHIR app/) + if cli_args.include? '--implementation-guide' expect(File).to exist('test-fhir-app/lib/test_fhir_app/igs/package.tgz') end @@ -50,9 +52,8 @@ # test `inferno new ... --pretend` it 'does not generate Inferno project with ["test-fhir-app", "--pretend", "--quiet"]' do - expect { Inferno::CLI::New.start(%w(test-fhir-app --pretend --quiet)) }.not_to raise_error + expect { Inferno::CLI::New.start(%w[test-fhir-app --pretend --quiet]) }.to_not raise_error - expect(Dir).not_to exist('test-fhir-app') + expect(Dir).to_not exist('test-fhir-app') end - end From 147068a21cf8bf08a18b862dfef604e7ddb66cd7 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 22 Nov 2023 13:55:12 -0500 Subject: [PATCH 26/50] yank acronyms --- lib/inferno/apps/cli/new/new.rb | 13 +++++-------- spec/inferno/apps/cli/new_spec.rb | 9 ++++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index dac8360ef..940684aa2 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -50,15 +50,12 @@ def self.source_root add_runtime_options! # adds --force, --pretend, --quiet, --skip - @@inflector = Dry::Inflector.new do |inflections| - inflections.acronym 'FHIR' - end - def create_app @name = name @ig_uri = options['implementation_guide'] @authors = options['author'] @authors << fetch_user if @authors.empty? + @inflector = Dry::Inflector.new ## Template Generation: # copies all files from ./templates/ folder @@ -91,22 +88,22 @@ def create_app # root folder name, i.e: inferno-template def root_name - @@inflector.dasherize(@@inflector.underscore(@name)) + @inflector.dasherize(@inflector.underscore(@name)) end # library name, i.e: inferno_template def lib_name - @@inflector.underscore(@name) + @inflector.underscore(@name) end # module name, i.e: InfernoTemplate def module_name - @@inflector.camelize(@name) + @inflector.camelize(@name) end # English grammatical name, i.e: Inferno template def human_name - @@inflector.humanize(@@inflector.camelize(@name)) + @inflector.humanize(@inflector.underscore(@name)) end # title case name, i.e: Inferno Template diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 2b27de56e..96110e2d5 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -20,7 +20,6 @@ [ %w[test-fhir-app --quiet], %w[test_fhir_app --quiet], - %w[TestFHIRApp --quiet], %w[TestFhirApp --quiet], %w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/ --quiet], %w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/index.html --quiet], @@ -35,10 +34,10 @@ expect(File).to exist('test-fhir-app/Gemfile') expect(File).to exist('test-fhir-app/test_fhir_app.gemspec') expect(File).to exist('test-fhir-app/lib/test_fhir_app.rb') - expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to include('module TestFHIRApp') + expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to include('module TestFhirApp') expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to include('id :test_fhir_app_test_suite') - expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to include("title 'Test FHIR App test suite'") - expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to match(/description.+Test FHIR app/) + expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to include("title 'Test Fhir App Test Suite'") + expect(File.read('test-fhir-app/README.md')).to match(/^Test fhir app/) if cli_args.include? '--implementation-guide' expect(File).to exist('test-fhir-app/lib/test_fhir_app/igs/package.tgz') @@ -51,7 +50,7 @@ end # test `inferno new ... --pretend` - it 'does not generate Inferno project with ["test-fhir-app", "--pretend", "--quiet"]' do + it 'runs inferno new test-fhir-app --pretend --quiet' do expect { Inferno::CLI::New.start(%w[test-fhir-app --pretend --quiet]) }.to_not raise_error expect(Dir).to_not exist('test-fhir-app') From a8055bc2d9cccda5507289d96ff36e6cd7542b2e Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 22 Nov 2023 14:01:15 -0500 Subject: [PATCH 27/50] remove --pretend test, rely on Thor::Action --- spec/inferno/apps/cli/new_spec.rb | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 96110e2d5..0be47e59d 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -18,15 +18,17 @@ # test various `inferno new ...` options [ - %w[test-fhir-app --quiet], - %w[test_fhir_app --quiet], - %w[TestFhirApp --quiet], - %w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/ --quiet], - %w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/index.html --quiet], - %w[test-fhir-app --implementation-guide https://build.fhir.org/ig/HL7/US-Core/package.tgz --quiet], - %W[test-fhir-app --implementation-guide #{ABSOLUTE_PATH_TO_IG} --quiet], - %w[test-fhir-app --author ABC --author DEF --quiet] + %w[test-fhir-app], + %w[test_fhir_app], + %w[TestFhirApp], + %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 #{ABSOLUTE_PATH_TO_IG}], + %w[test-fhir-app --author ABC --author DEF] ].each do |cli_args| + cli_args.append('--quiet') + it "runs inferno new #{cli_args.join(' ')}" do expect { Inferno::CLI::New.start(cli_args) }.to_not raise_error @@ -48,11 +50,4 @@ end end end - - # test `inferno new ... --pretend` - it 'runs inferno new test-fhir-app --pretend --quiet' do - expect { Inferno::CLI::New.start(%w[test-fhir-app --pretend --quiet]) }.to_not raise_error - - expect(Dir).to_not exist('test-fhir-app') - end end From df9d97cfa99159ad5881da50a7197542320e91d0 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 22 Nov 2023 14:51:41 -0500 Subject: [PATCH 28/50] doing rubocop and cleaning --- lib/inferno/apps/cli/new/new.rb | 22 ++++++++----------- .../lib/%lib_name%/patient_group.rb.tt | 2 +- spec/inferno/apps/cli/new_spec.rb | 5 ++--- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new/new.rb index 940684aa2..e78715f78 100644 --- a/lib/inferno/apps/cli/new/new.rb +++ b/lib/inferno/apps/cli/new/new.rb @@ -70,18 +70,20 @@ def create_app begin get(@ig_uri, ig_file, verbose: !options['quiet']) rescue StandardError => e - say_unless_quiet e.message, :red - ig_load_error + say_error e.message, :red + say_error "Failed to load #{@ig_uri}", :red + say_error "Please add the implementation guide package.tgz file into #{ig_path}", :red else say_unless_quiet "Loaded implementation guide #{@ig_uri}", :green end end say_unless_quiet "Created #{root_name} Inferno test kit!", :green - if options['pretend'] - say_unless_quiet 'This was a dry run; re-run without `--pretend` to actually create project', - :yellow - end + + return unless options['pretend'] + + say_unless_quiet 'This was a dry run; re-run without `--pretend` to actually create project', + :yellow end private @@ -108,7 +110,7 @@ def human_name # title case name, i.e: Inferno Template def title_name - human_name.split.map { |s| s.capitalize }.join(' ') + human_name.split.map(&:capitalize).join(' ') end # suffix '_test_suite' in snake case, i.e: inferno_template_test_suite @@ -126,12 +128,6 @@ def ig_file File.join(root_name, ig_path, 'package.tgz') end - def ig_load_error - say_error "Failed to load #{@ig_uri}", :red - say_error "Please add the implementation guide package.tgz file into #{ig_path}", :red - raise StandardError, "Failed to load #{@ig_uri}" - end - def fetch_user ENV['USER'] || ENV['USERNAME'] || 'TODO' end diff --git a/lib/inferno/apps/cli/new/templates/lib/%lib_name%/patient_group.rb.tt b/lib/inferno/apps/cli/new/templates/lib/%lib_name%/patient_group.rb.tt index 3ad62debe..b51736f89 100644 --- a/lib/inferno/apps/cli/new/templates/lib/%lib_name%/patient_group.rb.tt +++ b/lib/inferno/apps/cli/new/templates/lib/%lib_name%/patient_group.rb.tt @@ -1,6 +1,6 @@ module <%= module_name %> class PatientGroup < Inferno::TestGroup - title 'Patient Tests' + title 'Patient Tests' description 'Verify that the server makes Patient resources available' id :patient_group diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 0be47e59d..8e4ed044e 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -3,8 +3,7 @@ ABSOLUTE_PATH_TO_IG = File.expand_path('../../../fixtures/small_package.tgz', __dir__) -RSpec.describe Inferno::CLI::New do - +RSpec.describe Inferno::CLI::New do # rubocop:disable RSpec/FilePath # Wrap all 'it' examples in a temp dir around do |test| Dir.mktmpdir do |tmpdir| @@ -30,7 +29,7 @@ cli_args.append('--quiet') it "runs inferno new #{cli_args.join(' ')}" do - expect { Inferno::CLI::New.start(cli_args) }.to_not raise_error + expect { described_class.start(cli_args) }.to_not raise_error expect(Dir).to exist('test-fhir-app') expect(File).to exist('test-fhir-app/Gemfile') From 0942980218e9fc43ec1d2ebf289358a6f4c5b6c1 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 29 Nov 2023 16:51:06 -0500 Subject: [PATCH 29/50] remove new/ dir --- lib/inferno/apps/cli/main.rb | 3 ++- lib/inferno/apps/cli/{new => }/new.rb | 0 lib/inferno/apps/cli/{new => }/templates/%lib_name%.gemspec.tt | 0 lib/inferno/apps/cli/{new => }/templates/.dockerignore | 0 lib/inferno/apps/cli/{new => }/templates/.env | 0 lib/inferno/apps/cli/{new => }/templates/.env.development | 0 lib/inferno/apps/cli/{new => }/templates/.env.production | 0 lib/inferno/apps/cli/{new => }/templates/.env.test | 0 lib/inferno/apps/cli/{new => }/templates/.gitignore | 0 lib/inferno/apps/cli/{new => }/templates/.rspec | 0 lib/inferno/apps/cli/{new => }/templates/.ruby-version | 0 lib/inferno/apps/cli/{new => }/templates/.tool-versions | 0 lib/inferno/apps/cli/{new => }/templates/Dockerfile.tt | 0 lib/inferno/apps/cli/{new => }/templates/Gemfile.tt | 0 lib/inferno/apps/cli/{new => }/templates/LICENSE.tt | 0 lib/inferno/apps/cli/{new => }/templates/Procfile.tt | 0 lib/inferno/apps/cli/{new => }/templates/README.md.tt | 0 lib/inferno/apps/cli/{new => }/templates/Rakefile.tt | 0 lib/inferno/apps/cli/{new => }/templates/config.ru.tt | 0 .../apps/cli/{new => }/templates/config/database.yml.tt | 0 .../cli/{new => }/templates/config/nginx.background.conf.tt | 0 lib/inferno/apps/cli/{new => }/templates/config/nginx.conf.tt | 0 lib/inferno/apps/cli/{new => }/templates/config/puma.rb.tt | 0 lib/inferno/apps/cli/{new => }/templates/data/.keep | 0 lib/inferno/apps/cli/{new => }/templates/data/redis/.keep | 0 .../cli/{new => }/templates/docker-compose.background.yml.tt | 0 lib/inferno/apps/cli/{new => }/templates/docker-compose.yml.tt | 0 lib/inferno/apps/cli/{new => }/templates/lib/%lib_name%.rb.tt | 0 .../apps/cli/{new => }/templates/lib/%lib_name%/igs/.keep | 0 .../cli/{new => }/templates/lib/%lib_name%/patient_group.rb.tt | 0 lib/inferno/apps/cli/{new => }/templates/run.sh | 0 lib/inferno/apps/cli/{new => }/templates/setup.sh | 0 .../templates/spec/%lib_name%/patient_group_spec.rb.tt | 0 .../apps/cli/{new => }/templates/spec/spec_helper.rb.tt | 0 lib/inferno/apps/cli/{new => }/templates/worker.rb.tt | 0 spec/inferno/apps/cli/new_spec.rb | 2 +- 36 files changed, 3 insertions(+), 2 deletions(-) rename lib/inferno/apps/cli/{new => }/new.rb (100%) rename lib/inferno/apps/cli/{new => }/templates/%lib_name%.gemspec.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/.dockerignore (100%) rename lib/inferno/apps/cli/{new => }/templates/.env (100%) rename lib/inferno/apps/cli/{new => }/templates/.env.development (100%) rename lib/inferno/apps/cli/{new => }/templates/.env.production (100%) rename lib/inferno/apps/cli/{new => }/templates/.env.test (100%) rename lib/inferno/apps/cli/{new => }/templates/.gitignore (100%) rename lib/inferno/apps/cli/{new => }/templates/.rspec (100%) rename lib/inferno/apps/cli/{new => }/templates/.ruby-version (100%) rename lib/inferno/apps/cli/{new => }/templates/.tool-versions (100%) rename lib/inferno/apps/cli/{new => }/templates/Dockerfile.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/Gemfile.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/LICENSE.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/Procfile.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/README.md.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/Rakefile.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/config.ru.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/config/database.yml.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/config/nginx.background.conf.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/config/nginx.conf.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/config/puma.rb.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/data/.keep (100%) rename lib/inferno/apps/cli/{new => }/templates/data/redis/.keep (100%) rename lib/inferno/apps/cli/{new => }/templates/docker-compose.background.yml.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/docker-compose.yml.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/lib/%lib_name%.rb.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/lib/%lib_name%/igs/.keep (100%) rename lib/inferno/apps/cli/{new => }/templates/lib/%lib_name%/patient_group.rb.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/run.sh (100%) rename lib/inferno/apps/cli/{new => }/templates/setup.sh (100%) rename lib/inferno/apps/cli/{new => }/templates/spec/%lib_name%/patient_group_spec.rb.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/spec/spec_helper.rb.tt (100%) rename lib/inferno/apps/cli/{new => }/templates/worker.rb.tt (100%) diff --git a/lib/inferno/apps/cli/main.rb b/lib/inferno/apps/cli/main.rb index d2530e41c..498f2769b 100644 --- a/lib/inferno/apps/cli/main.rb +++ b/lib/inferno/apps/cli/main.rb @@ -3,7 +3,7 @@ require_relative 'services' require_relative 'suite' require_relative 'suites' -require_relative 'new/new' +require_relative 'new' module Inferno module CLI @@ -52,6 +52,7 @@ 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 diff --git a/lib/inferno/apps/cli/new/new.rb b/lib/inferno/apps/cli/new.rb similarity index 100% rename from lib/inferno/apps/cli/new/new.rb rename to lib/inferno/apps/cli/new.rb diff --git a/lib/inferno/apps/cli/new/templates/%lib_name%.gemspec.tt b/lib/inferno/apps/cli/templates/%lib_name%.gemspec.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/%lib_name%.gemspec.tt rename to lib/inferno/apps/cli/templates/%lib_name%.gemspec.tt diff --git a/lib/inferno/apps/cli/new/templates/.dockerignore b/lib/inferno/apps/cli/templates/.dockerignore similarity index 100% rename from lib/inferno/apps/cli/new/templates/.dockerignore rename to lib/inferno/apps/cli/templates/.dockerignore diff --git a/lib/inferno/apps/cli/new/templates/.env b/lib/inferno/apps/cli/templates/.env similarity index 100% rename from lib/inferno/apps/cli/new/templates/.env rename to lib/inferno/apps/cli/templates/.env diff --git a/lib/inferno/apps/cli/new/templates/.env.development b/lib/inferno/apps/cli/templates/.env.development similarity index 100% rename from lib/inferno/apps/cli/new/templates/.env.development rename to lib/inferno/apps/cli/templates/.env.development diff --git a/lib/inferno/apps/cli/new/templates/.env.production b/lib/inferno/apps/cli/templates/.env.production similarity index 100% rename from lib/inferno/apps/cli/new/templates/.env.production rename to lib/inferno/apps/cli/templates/.env.production diff --git a/lib/inferno/apps/cli/new/templates/.env.test b/lib/inferno/apps/cli/templates/.env.test similarity index 100% rename from lib/inferno/apps/cli/new/templates/.env.test rename to lib/inferno/apps/cli/templates/.env.test diff --git a/lib/inferno/apps/cli/new/templates/.gitignore b/lib/inferno/apps/cli/templates/.gitignore similarity index 100% rename from lib/inferno/apps/cli/new/templates/.gitignore rename to lib/inferno/apps/cli/templates/.gitignore diff --git a/lib/inferno/apps/cli/new/templates/.rspec b/lib/inferno/apps/cli/templates/.rspec similarity index 100% rename from lib/inferno/apps/cli/new/templates/.rspec rename to lib/inferno/apps/cli/templates/.rspec diff --git a/lib/inferno/apps/cli/new/templates/.ruby-version b/lib/inferno/apps/cli/templates/.ruby-version similarity index 100% rename from lib/inferno/apps/cli/new/templates/.ruby-version rename to lib/inferno/apps/cli/templates/.ruby-version diff --git a/lib/inferno/apps/cli/new/templates/.tool-versions b/lib/inferno/apps/cli/templates/.tool-versions similarity index 100% rename from lib/inferno/apps/cli/new/templates/.tool-versions rename to lib/inferno/apps/cli/templates/.tool-versions diff --git a/lib/inferno/apps/cli/new/templates/Dockerfile.tt b/lib/inferno/apps/cli/templates/Dockerfile.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/Dockerfile.tt rename to lib/inferno/apps/cli/templates/Dockerfile.tt diff --git a/lib/inferno/apps/cli/new/templates/Gemfile.tt b/lib/inferno/apps/cli/templates/Gemfile.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/Gemfile.tt rename to lib/inferno/apps/cli/templates/Gemfile.tt diff --git a/lib/inferno/apps/cli/new/templates/LICENSE.tt b/lib/inferno/apps/cli/templates/LICENSE.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/LICENSE.tt rename to lib/inferno/apps/cli/templates/LICENSE.tt diff --git a/lib/inferno/apps/cli/new/templates/Procfile.tt b/lib/inferno/apps/cli/templates/Procfile.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/Procfile.tt rename to lib/inferno/apps/cli/templates/Procfile.tt diff --git a/lib/inferno/apps/cli/new/templates/README.md.tt b/lib/inferno/apps/cli/templates/README.md.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/README.md.tt rename to lib/inferno/apps/cli/templates/README.md.tt diff --git a/lib/inferno/apps/cli/new/templates/Rakefile.tt b/lib/inferno/apps/cli/templates/Rakefile.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/Rakefile.tt rename to lib/inferno/apps/cli/templates/Rakefile.tt diff --git a/lib/inferno/apps/cli/new/templates/config.ru.tt b/lib/inferno/apps/cli/templates/config.ru.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/config.ru.tt rename to lib/inferno/apps/cli/templates/config.ru.tt diff --git a/lib/inferno/apps/cli/new/templates/config/database.yml.tt b/lib/inferno/apps/cli/templates/config/database.yml.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/config/database.yml.tt rename to lib/inferno/apps/cli/templates/config/database.yml.tt diff --git a/lib/inferno/apps/cli/new/templates/config/nginx.background.conf.tt b/lib/inferno/apps/cli/templates/config/nginx.background.conf.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/config/nginx.background.conf.tt rename to lib/inferno/apps/cli/templates/config/nginx.background.conf.tt diff --git a/lib/inferno/apps/cli/new/templates/config/nginx.conf.tt b/lib/inferno/apps/cli/templates/config/nginx.conf.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/config/nginx.conf.tt rename to lib/inferno/apps/cli/templates/config/nginx.conf.tt diff --git a/lib/inferno/apps/cli/new/templates/config/puma.rb.tt b/lib/inferno/apps/cli/templates/config/puma.rb.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/config/puma.rb.tt rename to lib/inferno/apps/cli/templates/config/puma.rb.tt diff --git a/lib/inferno/apps/cli/new/templates/data/.keep b/lib/inferno/apps/cli/templates/data/.keep similarity index 100% rename from lib/inferno/apps/cli/new/templates/data/.keep rename to lib/inferno/apps/cli/templates/data/.keep diff --git a/lib/inferno/apps/cli/new/templates/data/redis/.keep b/lib/inferno/apps/cli/templates/data/redis/.keep similarity index 100% rename from lib/inferno/apps/cli/new/templates/data/redis/.keep rename to lib/inferno/apps/cli/templates/data/redis/.keep diff --git a/lib/inferno/apps/cli/new/templates/docker-compose.background.yml.tt b/lib/inferno/apps/cli/templates/docker-compose.background.yml.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/docker-compose.background.yml.tt rename to lib/inferno/apps/cli/templates/docker-compose.background.yml.tt diff --git a/lib/inferno/apps/cli/new/templates/docker-compose.yml.tt b/lib/inferno/apps/cli/templates/docker-compose.yml.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/docker-compose.yml.tt rename to lib/inferno/apps/cli/templates/docker-compose.yml.tt diff --git a/lib/inferno/apps/cli/new/templates/lib/%lib_name%.rb.tt b/lib/inferno/apps/cli/templates/lib/%lib_name%.rb.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/lib/%lib_name%.rb.tt rename to lib/inferno/apps/cli/templates/lib/%lib_name%.rb.tt diff --git a/lib/inferno/apps/cli/new/templates/lib/%lib_name%/igs/.keep b/lib/inferno/apps/cli/templates/lib/%lib_name%/igs/.keep similarity index 100% rename from lib/inferno/apps/cli/new/templates/lib/%lib_name%/igs/.keep rename to lib/inferno/apps/cli/templates/lib/%lib_name%/igs/.keep diff --git a/lib/inferno/apps/cli/new/templates/lib/%lib_name%/patient_group.rb.tt b/lib/inferno/apps/cli/templates/lib/%lib_name%/patient_group.rb.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/lib/%lib_name%/patient_group.rb.tt rename to lib/inferno/apps/cli/templates/lib/%lib_name%/patient_group.rb.tt diff --git a/lib/inferno/apps/cli/new/templates/run.sh b/lib/inferno/apps/cli/templates/run.sh similarity index 100% rename from lib/inferno/apps/cli/new/templates/run.sh rename to lib/inferno/apps/cli/templates/run.sh diff --git a/lib/inferno/apps/cli/new/templates/setup.sh b/lib/inferno/apps/cli/templates/setup.sh similarity index 100% rename from lib/inferno/apps/cli/new/templates/setup.sh rename to lib/inferno/apps/cli/templates/setup.sh diff --git a/lib/inferno/apps/cli/new/templates/spec/%lib_name%/patient_group_spec.rb.tt b/lib/inferno/apps/cli/templates/spec/%lib_name%/patient_group_spec.rb.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/spec/%lib_name%/patient_group_spec.rb.tt rename to lib/inferno/apps/cli/templates/spec/%lib_name%/patient_group_spec.rb.tt diff --git a/lib/inferno/apps/cli/new/templates/spec/spec_helper.rb.tt b/lib/inferno/apps/cli/templates/spec/spec_helper.rb.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/spec/spec_helper.rb.tt rename to lib/inferno/apps/cli/templates/spec/spec_helper.rb.tt diff --git a/lib/inferno/apps/cli/new/templates/worker.rb.tt b/lib/inferno/apps/cli/templates/worker.rb.tt similarity index 100% rename from lib/inferno/apps/cli/new/templates/worker.rb.tt rename to lib/inferno/apps/cli/templates/worker.rb.tt diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 8e4ed044e..0b5887292 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -1,5 +1,5 @@ require 'rspec' -require 'inferno/apps/cli/new/new' +require 'inferno/apps/cli/new' ABSOLUTE_PATH_TO_IG = File.expand_path('../../../fixtures/small_package.tgz', __dir__) From 69ff29c16ca2bcc1dbb8b775bd06dfa157350553 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 29 Nov 2023 17:09:10 -0500 Subject: [PATCH 30/50] factorize naming into Utils::NamedThorActions --- lib/inferno/apps/cli/new.rb | 37 ++----------------- ...%.gemspec.tt => %library_name%.gemspec.tt} | 2 +- lib/inferno/apps/cli/templates/README.md.tt | 8 ++-- ...{%lib_name%.rb.tt => %library_name%.rb.tt} | 2 +- .../{%lib_name% => %library_name%}/igs/.keep | 0 .../patient_group.rb.tt | 0 lib/inferno/utils/named_thor_actions.rb | 35 ++++++++++++++++++ 7 files changed, 45 insertions(+), 39 deletions(-) rename lib/inferno/apps/cli/templates/{%lib_name%.gemspec.tt => %library_name%.gemspec.tt} (95%) rename lib/inferno/apps/cli/templates/lib/{%lib_name%.rb.tt => %library_name%.rb.tt} (96%) rename lib/inferno/apps/cli/templates/lib/{%lib_name% => %library_name%}/igs/.keep (100%) rename lib/inferno/apps/cli/templates/lib/{%lib_name% => %library_name%}/patient_group.rb.tt (100%) create mode 100644 lib/inferno/utils/named_thor_actions.rb diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index e78715f78..606ee2a01 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -1,10 +1,11 @@ -require 'dry/inflector' require 'thor' +require_relative '../../utils/named_thor_actions.rb' module Inferno module CLI class New < Thor::Group include Thor::Actions + include Inferno::Utils::NamedThorActions desc <<~HELP Generate a new Inferno test kit for FHIR software testing @@ -55,7 +56,7 @@ def create_app @ig_uri = options['implementation_guide'] @authors = options['author'] @authors << fetch_user if @authors.empty? - @inflector = Dry::Inflector.new + # @inflector = Dry::Inflector.new ## Template Generation: # copies all files from ./templates/ folder @@ -88,39 +89,9 @@ def create_app private - # root folder name, i.e: inferno-template - def root_name - @inflector.dasherize(@inflector.underscore(@name)) - end - - # library name, i.e: inferno_template - def lib_name - @inflector.underscore(@name) - end - - # module name, i.e: InfernoTemplate - def module_name - @inflector.camelize(@name) - end - - # English grammatical name, i.e: Inferno template - def human_name - @inflector.humanize(@inflector.underscore(@name)) - end - - # title case name, i.e: Inferno Template - def title_name - human_name.split.map(&:capitalize).join(' ') - end - - # suffix '_test_suite' in snake case, i.e: inferno_template_test_suite - def test_suite_id - "#{lib_name}_test_suite" - end - # path to where package.tgz should reside, i.e: lib/inferno_template/igs def ig_path - File.join('lib', lib_name, 'igs') + File.join('lib', library_name, 'igs') end # full path to package.tgz, i.e: inferno-template/lib/inferno_template/igs/package.tgz diff --git a/lib/inferno/apps/cli/templates/%lib_name%.gemspec.tt b/lib/inferno/apps/cli/templates/%library_name%.gemspec.tt similarity index 95% rename from lib/inferno/apps/cli/templates/%lib_name%.gemspec.tt rename to lib/inferno/apps/cli/templates/%library_name%.gemspec.tt index 86e68d8b1..82dfa4920 100644 --- a/lib/inferno/apps/cli/templates/%lib_name%.gemspec.tt +++ b/lib/inferno/apps/cli/templates/%library_name%.gemspec.tt @@ -1,5 +1,5 @@ Gem::Specification.new do |spec| - spec.name = '<%= lib_name %>' + spec.name = '<%= library_name %>' spec.version = '0.0.1' spec.authors = <%= @authors %> # spec.email = ['TODO'] diff --git a/lib/inferno/apps/cli/templates/README.md.tt b/lib/inferno/apps/cli/templates/README.md.tt index 93c1bb6f1..f3bd44edf 100644 --- a/lib/inferno/apps/cli/templates/README.md.tt +++ b/lib/inferno/apps/cli/templates/README.md.tt @@ -14,7 +14,7 @@ for FHIR testing. - Run `setup.sh` in this repo to pull the needed docker images and set up the database. - Put the `package.tgz` for the IG you're writing tests for in - `lib/<%= lib_name %>/igs`. + `lib/<%= library_name %>/igs`. This will ensure that the validator has access to the resources needed to validate resources against your IG. @@ -108,7 +108,7 @@ end ᐅ bundle exec rdbg -A DEBUGGER (client): Connected. PID:22112, $0:sidekiq 6.5.7 [0 of 10 busy] -[18, 27] in ~/code/<%= root_name %>/lib/<%= lib_name %>/patient_group.rb +[18, 27] in ~/code/<%= root_name %>/lib/<%= library_name %>/patient_group.rb 18| 19| run do 20| fhir_read(:patient, patient_id, name: :patient) @@ -157,8 +157,8 @@ like a standard ruby gem (ruby libraries are called gems). - Fill in the information in the `gemspec` file in the root of this repository. The name of this file should match the `spec.name` within the file. This will be the name of the gem you create. For example, if your file is - `<%= lib_name %>.gemspec` and its `spec.name` is `'<%= lib_name %>'`, then others will - be able to install your gem with `gem install <%= lib_name %>`. There are + `<%= library_name %>.gemspec` and its `spec.name` is `'<%= library_name %>'`, then others will + be able to install your gem with `gem install <%= library_name %>`. There are [recommended naming conventions for gems](https://guides.rubygems.org/name-your-gem/). - Your tests must be in `lib` diff --git a/lib/inferno/apps/cli/templates/lib/%lib_name%.rb.tt b/lib/inferno/apps/cli/templates/lib/%library_name%.rb.tt similarity index 96% rename from lib/inferno/apps/cli/templates/lib/%lib_name%.rb.tt rename to lib/inferno/apps/cli/templates/lib/%library_name%.rb.tt index 869b4a2f9..7e4fc0e02 100644 --- a/lib/inferno/apps/cli/templates/lib/%lib_name%.rb.tt +++ b/lib/inferno/apps/cli/templates/lib/%library_name%.rb.tt @@ -1,4 +1,4 @@ -require_relative '<%= lib_name %>/patient_group' +require_relative '<%= library_name %>/patient_group' module <%= module_name %> class Suite < Inferno::TestSuite diff --git a/lib/inferno/apps/cli/templates/lib/%lib_name%/igs/.keep b/lib/inferno/apps/cli/templates/lib/%library_name%/igs/.keep similarity index 100% rename from lib/inferno/apps/cli/templates/lib/%lib_name%/igs/.keep rename to lib/inferno/apps/cli/templates/lib/%library_name%/igs/.keep diff --git a/lib/inferno/apps/cli/templates/lib/%lib_name%/patient_group.rb.tt b/lib/inferno/apps/cli/templates/lib/%library_name%/patient_group.rb.tt similarity index 100% rename from lib/inferno/apps/cli/templates/lib/%lib_name%/patient_group.rb.tt rename to lib/inferno/apps/cli/templates/lib/%library_name%/patient_group.rb.tt diff --git a/lib/inferno/utils/named_thor_actions.rb b/lib/inferno/utils/named_thor_actions.rb new file mode 100644 index 000000000..07f22f8e9 --- /dev/null +++ b/lib/inferno/utils/named_thor_actions.rb @@ -0,0 +1,35 @@ +require 'dry/inflector' + +module Inferno + module Utils + module NamedThorActions + + INFLECTOR = Dry::Inflector.new + + def root_name + INFLECTOR.dasherize(INFLECTOR.underscore(name)) + end + + def library_name + INFLECTOR.underscore(name) + end + + def module_name + INFLECTOR.camelize(name) + end + + def human_name + INFLECTOR.humanize(INFLECTOR.underscore(name)) + end + + def title_name + human_name.split.map(&:capitalize).join(' ') + end + + def test_suite_id + "#{library_name}_test_suite" + end + + end + end +end From 37c63b35fe05a423b7f467255815522f09840512 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 29 Nov 2023 18:25:48 -0500 Subject: [PATCH 31/50] create utils test --- spec/inferno/utils/named_thor_actions_spec.rb | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 spec/inferno/utils/named_thor_actions_spec.rb diff --git a/spec/inferno/utils/named_thor_actions_spec.rb b/spec/inferno/utils/named_thor_actions_spec.rb new file mode 100644 index 000000000..c05bed84d --- /dev/null +++ b/spec/inferno/utils/named_thor_actions_spec.rb @@ -0,0 +1,44 @@ +require_relative '../../../lib/inferno/utils/named_thor_actions' + +RSpec.describe Inferno::Utils::NamedThorActions do + let(:dummy_class) do + Class.new do + include Inferno::Utils::NamedThorActions + attr_accessor :name + end + end + + %w[test_fhir_app test-fhir-app TestFhirApp testFhir_app].each do |name| + context "given name #{name}" do + let(:dummy) do + dummy_instance = dummy_class.new + dummy_instance.name = name + dummy_instance + end + + it 'returns root name in kebab case' do + expect(dummy.root_name).to eq('test-fhir-app') + end + + it 'returns library name in snake case' do + expect(dummy.library_name).to eq('test_fhir_app') + end + + it 'returns module name in pascal case' do + expect(dummy.module_name).to eq('TestFhirApp') + end + + it 'returns human name in sentence case' do + expect(dummy.human_name).to eq('Test fhir app') + end + + it 'returns title name in title case' do + expect(dummy.title_name).to eq('Test Fhir App') + end + + it 'returns proper test suite id' do + expect(dummy.test_suite_id).to eq('test_fhir_app_test_suite') + end + end + end +end From e6971cf41718f1f9ba749ce8b64b86876598a422 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 29 Nov 2023 18:51:05 -0500 Subject: [PATCH 32/50] clean comments and instance variables --- lib/inferno/apps/cli/new.rb | 39 +++++++++---------- .../cli/templates/%library_name%.gemspec.tt | 2 +- spec/inferno/apps/cli/new_spec.rb | 6 --- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index 606ee2a01..0c10e48e1 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -49,33 +49,22 @@ def self.source_root repeatable: true, desc: "Author names for gemspec file; you may use '-a' multiple times" - add_runtime_options! # adds --force, --pretend, --quiet, --skip + add_runtime_options! def create_app - @name = name - @ig_uri = options['implementation_guide'] - @authors = options['author'] - @authors << fetch_user if @authors.empty? - # @inflector = Dry::Inflector.new - - ## Template Generation: - # copies all files from ./templates/ folder - # performs ERB substitution on all .tt files and removes .tt suffix - # replaces all %foo% file names with foo() method call - directory('.', root_name, { mode: :preserve, recursive: true, verbose: !options['quiet'] }) + normalized_ig_uri = options['implementation_guide'] - if @ig_uri - @ig_uri = @ig_uri.gsub(%r{[^/]*\.html\s*$}, 'package.tgz') - @ig_uri = File.join(@ig_uri, 'package.tgz') unless @ig_uri.ends_with? 'package.tgz' + directory('.', root_name, { mode: :preserve, recursive: true, verbose: !options['quiet'] }) + if normalized_ig_uri begin - get(@ig_uri, ig_file, verbose: !options['quiet']) + get(normalized_ig_uri, ig_file, verbose: !options['quiet']) rescue StandardError => e say_error e.message, :red - say_error "Failed to load #{@ig_uri}", :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 #{@ig_uri}", :green + say_unless_quiet "Loaded implementation guide #{normalized_ig_uri}", :green end end @@ -88,18 +77,26 @@ def create_app end private + 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' + end - # path to where package.tgz should reside, i.e: lib/inferno_template/igs def ig_path File.join('lib', library_name, 'igs') end - # full path to package.tgz, i.e: inferno-template/lib/inferno_template/igs/package.tgz def ig_file File.join(root_name, ig_path, 'package.tgz') end - def fetch_user + def authors + options['author'].empty? ? options['author'].append(default_author) : options['author'] + end + + def default_author ENV['USER'] || ENV['USERNAME'] || 'TODO' end diff --git a/lib/inferno/apps/cli/templates/%library_name%.gemspec.tt b/lib/inferno/apps/cli/templates/%library_name%.gemspec.tt index 82dfa4920..e712d90ce 100644 --- a/lib/inferno/apps/cli/templates/%library_name%.gemspec.tt +++ b/lib/inferno/apps/cli/templates/%library_name%.gemspec.tt @@ -1,7 +1,7 @@ Gem::Specification.new do |spec| spec.name = '<%= library_name %>' spec.version = '0.0.1' - spec.authors = <%= @authors %> + spec.authors = <%= authors %> # spec.email = ['TODO'] spec.date = Time.now.utc.strftime('%Y-%m-%d') spec.summary = '<%= title_name %> Test Kit' diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 0b5887292..c2c1f44b9 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -18,8 +18,6 @@ # test various `inferno new ...` options [ %w[test-fhir-app], - %w[test_fhir_app], - %w[TestFhirApp], %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], @@ -35,10 +33,6 @@ expect(File).to exist('test-fhir-app/Gemfile') expect(File).to exist('test-fhir-app/test_fhir_app.gemspec') expect(File).to exist('test-fhir-app/lib/test_fhir_app.rb') - expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to include('module TestFhirApp') - expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to include('id :test_fhir_app_test_suite') - expect(File.read('test-fhir-app/lib/test_fhir_app.rb')).to include("title 'Test Fhir App Test Suite'") - expect(File.read('test-fhir-app/README.md')).to match(/^Test fhir app/) if cli_args.include? '--implementation-guide' expect(File).to exist('test-fhir-app/lib/test_fhir_app/igs/package.tgz') From c41d8745bc8857336d855ccbd26834cae354afe1 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Thu, 30 Nov 2023 13:46:59 -0500 Subject: [PATCH 33/50] fix ig loading and disable web connect in testing --- lib/inferno/apps/cli/main.rb | 1 - lib/inferno/apps/cli/new.rb | 35 ++++++++++--------- lib/inferno/utils/named_thor_actions.rb | 2 -- spec/inferno/apps/cli/new_spec.rb | 15 ++++---- spec/inferno/utils/named_thor_actions_spec.rb | 2 +- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/lib/inferno/apps/cli/main.rb b/lib/inferno/apps/cli/main.rb index 498f2769b..48b913fa7 100644 --- a/lib/inferno/apps/cli/main.rb +++ b/lib/inferno/apps/cli/main.rb @@ -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 diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index 0c10e48e1..974e2b4b8 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -1,5 +1,5 @@ require 'thor' -require_relative '../../utils/named_thor_actions.rb' +require_relative '../../utils/named_thor_actions' module Inferno module CLI @@ -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'] @@ -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 diff --git a/lib/inferno/utils/named_thor_actions.rb b/lib/inferno/utils/named_thor_actions.rb index 07f22f8e9..3fc55fba3 100644 --- a/lib/inferno/utils/named_thor_actions.rb +++ b/lib/inferno/utils/named_thor_actions.rb @@ -3,7 +3,6 @@ module Inferno module Utils module NamedThorActions - INFLECTOR = Dry::Inflector.new def root_name @@ -29,7 +28,6 @@ def title_name def test_suite_id "#{library_name}_test_suite" end - end end end diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index c2c1f44b9..2a54971f0 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -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| diff --git a/spec/inferno/utils/named_thor_actions_spec.rb b/spec/inferno/utils/named_thor_actions_spec.rb index c05bed84d..5d4d8cfca 100644 --- a/spec/inferno/utils/named_thor_actions_spec.rb +++ b/spec/inferno/utils/named_thor_actions_spec.rb @@ -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 From c7ba319c6b36475f3fb505e4a62d06b6e30a8577 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Thu, 30 Nov 2023 14:29:47 -0500 Subject: [PATCH 34/50] yank ig loading code --- Gemfile.lock | 2 -- inferno_core.gemspec | 1 - lib/inferno/apps/cli/main.rb | 2 +- lib/inferno/apps/cli/new.rb | 43 +++---------------------------- spec/inferno/apps/cli/new_spec.rb | 15 +++-------- 5 files changed, 7 insertions(+), 56 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 85bc92d99..5d7b0c328 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,7 +22,6 @@ PATH pry-byebug puma (~> 5.6.7) rake (~> 13.0) - rubyzip (= 2.3.2) sequel (~> 5.42.0) sidekiq (~> 6.5.6) sqlite3 (~> 1.4) @@ -270,7 +269,6 @@ GEM rubocop (~> 1.0) ruby-progressbar (1.11.0) ruby2_keywords (0.0.5) - rubyzip (2.3.2) sequel (5.42.0) sidekiq (6.5.12) connection_pool (>= 2.2.5, < 3) diff --git a/inferno_core.gemspec b/inferno_core.gemspec index ada391471..4aef9f055 100644 --- a/inferno_core.gemspec +++ b/inferno_core.gemspec @@ -31,7 +31,6 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'pry-byebug' spec.add_runtime_dependency 'puma', '~> 5.6.7' spec.add_runtime_dependency 'rake', '~> 13.0' - spec.add_runtime_dependency 'rubyzip', '2.3.2' spec.add_runtime_dependency 'sequel', '~> 5.42.0' spec.add_runtime_dependency 'sidekiq', '~> 6.5.6' spec.add_runtime_dependency 'sqlite3', '~> 1.4' diff --git a/lib/inferno/apps/cli/main.rb b/lib/inferno/apps/cli/main.rb index 48b913fa7..ff2a45aea 100644 --- a/lib/inferno/apps/cli/main.rb +++ b/lib/inferno/apps/cli/main.rb @@ -51,7 +51,7 @@ def suites desc 'suite SUBCOMMAND ...ARGS', 'Perform suite-based operations' subcommand 'suite', Suite - register(New, 'new', 'new TEST_KIT_NAME [-i IG_URL]', 'Run `inferno new --help` for full help') + register(New, 'new', 'new TEST_KIT_NAME', 'Run `inferno new --help` for full help') end end end diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index 974e2b4b8..230598d80 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -15,17 +15,14 @@ class New < Thor::Group `inferno new test_fhir_app` => generates an Inferno app - `inferno new test_us_core -i https://build.fhir.org/ig/HL7/US-Core/` - => generates Inferno app and loads US Core implementation guide - - `inferno new test_my_ig -i /absolute/path/to/ig/package.tgz -a Name` - => generates Inferno app, loads a local implementation guide, and specifies Name as author + `inferno new test_my_ig -a MyName` + => generates Inferno app and specifies MyName as gemspec author https://inferno-framework.github.io/index.html HELP def self.banner - 'inferno new TEST_KIT_NAME [-i IG_URL]' + 'inferno new TEST_KIT_NAME' end def self.source_root @@ -36,12 +33,6 @@ def self.source_root type: :string, required: true, desc: 'name for new Inferno project' - class_option :implementation_guide, - type: :string, - aliases: '-i', - default: nil, - banner: 'IG_URL', - desc: 'URL to an implementation guide or absolute path to a package.tgz' class_option :author, type: :string, aliases: '-a', @@ -53,7 +44,6 @@ def self.source_root def create_app directory('.', root_name, { mode: :preserve, recursive: true, verbose: !options['quiet'] }) - load_ig say_unless_quiet "Created #{root_name} Inferno test kit!", :green return unless options['pretend'] @@ -64,37 +54,10 @@ def create_app 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 File.join('lib', library_name, 'igs') end - def ig_file - File.join(root_name, ig_path, 'package.tgz') - end - def authors options['author'].empty? ? options['author'].append(default_author) : options['author'] end diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 2a54971f0..678ecf167 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -4,11 +4,6 @@ ABSOLUTE_PATH_TO_IG = File.expand_path('../../../fixtures/small_package.tgz', __dir__) RSpec.describe Inferno::CLI::New do # rubocop:disable RSpec/FilePath - 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 @@ -19,10 +14,6 @@ [ %w[test-fhir-app], - %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| cli_args.append('--quiet') @@ -35,11 +26,11 @@ expect(File).to exist('test-fhir-app/test_fhir_app.gemspec') expect(File).to exist('test-fhir-app/lib/test_fhir_app.rb') - if cli_args.include? '--implementation-guide' - expect(File).to exist('test-fhir-app/lib/test_fhir_app/igs/package.tgz') + if cli_args.include? '--author' + expect(File.read('test-fhir-app/test_fhir_app.gemspec')).to match(/authors\s*=.*ABC/) end - if cli_args.include? '--author' + if cli_args.count('--author') == 2 expect(File.read('test-fhir-app/test_fhir_app.gemspec')).to match(/authors\s*=.*ABC.*DEF/) end end From bdeb594881e250f64b488a9bbed9536b2b0fd23b Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Thu, 30 Nov 2023 14:39:31 -0500 Subject: [PATCH 35/50] add inferno new -a test --- spec/inferno/apps/cli/new_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 678ecf167..83f5807c8 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -14,6 +14,7 @@ [ %w[test-fhir-app], + %w[test-fhir-app --author ABC], %w[test-fhir-app --author ABC --author DEF] ].each do |cli_args| cli_args.append('--quiet') From 8cb51e10443ece7d90158c64306875a85ac58603 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Thu, 30 Nov 2023 16:13:31 -0500 Subject: [PATCH 36/50] remove github clone template line from README and bump ci --- lib/inferno/apps/cli/templates/README.md.tt | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/inferno/apps/cli/templates/README.md.tt b/lib/inferno/apps/cli/templates/README.md.tt index f3bd44edf..90066f66e 100644 --- a/lib/inferno/apps/cli/templates/README.md.tt +++ b/lib/inferno/apps/cli/templates/README.md.tt @@ -10,7 +10,6 @@ for FHIR testing. ## Instructions for Developing tests -- Clone this repo/Click "Use this template" on github. - Run `setup.sh` in this repo to pull the needed docker images and set up the database. - Put the `package.tgz` for the IG you're writing tests for in From 364ceafb1a06c91100d4c7c4ef601fed3ffbd66a Mon Sep 17 00:00:00 2001 From: Alyssa Wang Date: Fri, 1 Dec 2023 11:56:52 -0500 Subject: [PATCH 37/50] allow null progress bar in test --- .../TestRunProgressBar/__tests__/TestRunProgressBar.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/components/TestSuite/TestRunProgressBar/__tests__/TestRunProgressBar.test.tsx b/client/src/components/TestSuite/TestRunProgressBar/__tests__/TestRunProgressBar.test.tsx index 87805d16b..53989b39c 100644 --- a/client/src/components/TestSuite/TestRunProgressBar/__tests__/TestRunProgressBar.test.tsx +++ b/client/src/components/TestSuite/TestRunProgressBar/__tests__/TestRunProgressBar.test.tsx @@ -61,7 +61,7 @@ describe('The TestRunProgressBar Component', () => { expect(testRunCancelled).toEqual(true); setTimeout(() => { - const progressBarElement = screen.getByTestId('progress-bar'); + const progressBarElement = screen.queryByTestId('progress-bar'); expect(progressBarElement).toBeNull(); }, 500); }); From e9236d68d5a121afce6d24891e36db9bf71bed9a Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Fri, 22 Dec 2023 13:24:05 -0500 Subject: [PATCH 38/50] address PR review --- .../cli/templates/%library_name%.gemspec.tt | 2 +- lib/inferno/apps/cli/templates/README.md.tt | 168 +----------------- .../igs/put_ig_package_dot_tgz_here | 0 .../patient_group_spec.rb.tt | 0 4 files changed, 6 insertions(+), 164 deletions(-) create mode 100644 lib/inferno/apps/cli/templates/lib/%library_name%/igs/put_ig_package_dot_tgz_here rename lib/inferno/apps/cli/templates/spec/{%lib_name% => %library_name%}/patient_group_spec.rb.tt (100%) diff --git a/lib/inferno/apps/cli/templates/%library_name%.gemspec.tt b/lib/inferno/apps/cli/templates/%library_name%.gemspec.tt index e712d90ce..853e4e5f6 100644 --- a/lib/inferno/apps/cli/templates/%library_name%.gemspec.tt +++ b/lib/inferno/apps/cli/templates/%library_name%.gemspec.tt @@ -8,7 +8,7 @@ Gem::Specification.new do |spec| spec.description = '<%= human_name %> Inferno test kit for FHIR' # spec.homepage = 'TODO' spec.license = 'Apache-2.0' - spec.add_runtime_dependency 'inferno_core', '~> 0.4.4' + spec.add_runtime_dependency 'inferno_core', '~> <%= Inferno::VERSION %>' spec.add_development_dependency 'database_cleaner-sequel', '~> 1.8' spec.add_development_dependency 'factory_bot', '~> 6.1' spec.add_development_dependency 'rspec', '~> 3.10' diff --git a/lib/inferno/apps/cli/templates/README.md.tt b/lib/inferno/apps/cli/templates/README.md.tt index 90066f66e..0b284379c 100644 --- a/lib/inferno/apps/cli/templates/README.md.tt +++ b/lib/inferno/apps/cli/templates/README.md.tt @@ -10,169 +10,11 @@ for FHIR testing. ## Instructions for Developing tests -- Run `setup.sh` in this repo to pull the needed docker images and set up the - database. -- Put the `package.tgz` for the IG you're writing tests for in - `lib/<%= library_name %>/igs`. - This will ensure that the validator has access to the resources needed to - validate resources against your IG. - -All tests you write should go in the `lib` folder, which currently contains some -example tests. Refer to the [Inferno -documentation](https://inferno-framework.github.io/inferno-core/) for more -information about the specifics of writing tests. - -### Development with Docker vs Docker + ruby -Tests can be developed with or without a local ruby installation using docker. -However, it takes much longer to build/start/stop docker than to start/stop -native ruby processes. Inferno needs to be restarted whenever tests change, so -you will be starting and stopping it often during test development. For this -reason, it is highly recommended that you install ruby and do not rely solely on -docker for development if possible. - -### Development with Docker only -- Run `run.sh` to build your tests and run inferno. You will need to stop and - re-run this whenever you make changes to your tests. -- Navigate to `http://localhost` to access Inferno, where your test suite will - be available. To access the HL7® FHIR® resource validator, navigate to - `http://localhost/validator`. - -### Development with ruby -It is highly recommended that you install ruby via a [ruby version -manager](https://www.ruby-lang.org/en/documentation/installation/#managers). When you - -- Run `bundle install` to install dependencies. -- Run `bundle exec inferno migrate` to set up the database. -- Run `gem install foreman` to install foreman, which will be used to run the - Inferno web and worker processes. -- Run `bundle exec inferno services start` to start the background services. By - default, these include nginx, redis, the FHIR validator service, and the FHIR - validator UI. Background services can be added/removed/edited in - `docker-compose.background.yml`. -- Run `inferno start` to start Inferno. You will need to stop and re-run this - whenever you make changes to your tests. -- Navigate to `http://localhost:4567` to access Inferno, where your test suite will - be available. To access the FHIR resource validator, navigate to - `http://localhost/validator`. -- When you are done, run `bundle exec inferno services stop` to stop the - background services. - -#### Interactive consoles -A local ruby installation also allows you to use [pry](https://pry.github.io/), -a powerful interactive console to explore and experiment with your tests with -`inferno console`: -```ruby -ᐅ bundle exec inferno console -[1] pry(main)> suite = <%= module_name %>::Suite -=> <%= module_name %>::Suite -[2] pry(main)> suite.groups -=> [#, #] -[3] pry(main)> suite.groups.map(&:title) -=> ["Capability Statement", "Patient Tests"] -[4] pry(main)> suite.groups.first.tests.map(&:title) -=> ["Read CapabilityStatement"] -``` - -It is also possible to set a breakpoint using the [debug -gem](https://github.com/ruby/debug) within a test's `run` block to debug test -behavior: -- Add `require 'debug/open_nonstop'` and `debugger` to set the breakpoint. -- Run your tests until the breakpoint is reached. -- In a separate terminal window, run `bundle exec rdbg -A` to access the - interactive console. - -```ruby -module <%= module_name %> - class PatientGroup < Inferno::TestGroup - ... - test do - ... - run do - fhir_read(:patient, patient_id, name: :patient) - - require 'debug/open_nonstop' - debugger - - assert_response_status(200) - assert_resource_type(:patient) - assert resource.id == patient_id, - "Requested resource with id #{patient_id}, received resource with id #{resource.id}" - end - end - end -end -``` - -```ruby -ᐅ bundle exec rdbg -A -DEBUGGER (client): Connected. PID:22112, $0:sidekiq 6.5.7 [0 of 10 busy] - -[18, 27] in ~/code/<%= root_name %>/lib/<%= library_name %>/patient_group.rb - 18| - 19| run do - 20| fhir_read(:patient, patient_id, name: :patient) - 21| - 22| require 'debug/open_nonstop' -=> 23| debugger - 24| - 25| assert_response_status(200) - 26| assert_resource_type(:patient) - 27| assert resource.id == patient_id, -(ruby:remote) self.id -"<%= test_suite_id %>-patient_group-Test01" -(ruby:remote) self.title -"Server returns requested Patient resource from the Patient read interaction" -(rdbg:remote) inputs -[:patient_id, :url, :credentials] -(ruby:remote) patient_id -"85" -(rdbg:remote) url -"https://inferno.healthit.gov/reference-server/r4" -(rdbg:remote) ls request # outline command -Inferno::Entities::Request#methods: - created_at created_at= direction direction= headers headers= id id= index index= name name= - query_parameters request request_body request_body= request_header request_headers resource response response_body response_body= response_header response_headers - result_id result_id= status status= test_session_id test_session_id= to_hash updated_at updated_at= url url= verb - verb= -instance variables: @created_at @direction @headers @id @index @name @request_body @response_body @result_id @status @test_session_id @updated_at @url @verb -(ruby:remote) request.status -200 -(ruby:remote) request.response_body -"{\n \"resourceType\": \"Patient\" ... }" -(rdbg:remote) ? # help command - -### Control flow - -* `s[tep]` - * Step in. Resume the program until next breakable point. -... -``` - -## Distributing tests - -In order to make your test suite available to others, it needs to be organized -like a standard ruby gem (ruby libraries are called gems). - -- Fill in the information in the `gemspec` file in the root of this repository. - The name of this file should match the `spec.name` within the file. This will - be the name of the gem you create. For example, if your file is - `<%= library_name %>.gemspec` and its `spec.name` is `'<%= library_name %>'`, then others will - be able to install your gem with `gem install <%= library_name %>`. There are - [recommended naming conventions for - gems](https://guides.rubygems.org/name-your-gem/). -- Your tests must be in `lib` -- `lib` should contain only one file. All other files should be in a - subdirectory. The file in lib be what people use to import your gem after they - have installed it. For example, if your test kit contains a file - `lib/my_test_suite.rb`, then after installing your test kit gem, I could - include your test suite with `require 'my_test_suite'`. -- **Optional:** Once your gemspec file has been updated, you can publish your - gem on [rubygems, the official ruby gem repository](https://rubygems.org/). If - you don't publish your gem on rubygems, users will still be able to install it - if it is located in a public git repository. To publish your gem on rubygems, - you will first need to [make an account on - rubygems](https://guides.rubygems.org/publishing/#publishing-to-rubygemsorg) - and then run `gem build *.gemspec` and `gem push *.gem`. +To get started writing tests, click "Use this template" on +github or use the Ruby-based command: `gem install inferno_core && inferno new my-test-kit`. +Refer to the Inferno documentation for information about [setting up your development +environment and running +Inferno](https://inferno-framework.github.io/inferno-core/getting-started.html#getting-started-for-inferno-test-writers). ## Example Inferno test kits diff --git a/lib/inferno/apps/cli/templates/lib/%library_name%/igs/put_ig_package_dot_tgz_here b/lib/inferno/apps/cli/templates/lib/%library_name%/igs/put_ig_package_dot_tgz_here new file mode 100644 index 000000000..e69de29bb diff --git a/lib/inferno/apps/cli/templates/spec/%lib_name%/patient_group_spec.rb.tt b/lib/inferno/apps/cli/templates/spec/%library_name%/patient_group_spec.rb.tt similarity index 100% rename from lib/inferno/apps/cli/templates/spec/%lib_name%/patient_group_spec.rb.tt rename to lib/inferno/apps/cli/templates/spec/%library_name%/patient_group_spec.rb.tt From d2ea6d10c2b8346ea695c6c655c9773e1fa38687 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Fri, 22 Dec 2023 13:24:56 -0500 Subject: [PATCH 39/50] add PR suggesstion to lib/inferno/apps/cli/new.rb Co-authored-by: Stephen MacVicar --- lib/inferno/apps/cli/new.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index 230598d80..444cda9a1 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -59,7 +59,7 @@ def ig_path end def authors - options['author'].empty? ? options['author'].append(default_author) : options['author'] + options['author'].presence || [default_author] end def default_author From af8ec1c7e3c00a816ee64cdf5600273650fc60df Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Fri, 22 Dec 2023 14:08:01 -0500 Subject: [PATCH 40/50] add Gemfile.lock to new template --- .../apps/cli/templates/Gemfile.lock.tt | 288 ++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 lib/inferno/apps/cli/templates/Gemfile.lock.tt diff --git a/lib/inferno/apps/cli/templates/Gemfile.lock.tt b/lib/inferno/apps/cli/templates/Gemfile.lock.tt new file mode 100644 index 000000000..67fefbf96 --- /dev/null +++ b/lib/inferno/apps/cli/templates/Gemfile.lock.tt @@ -0,0 +1,288 @@ +PATH + remote: . + specs: + <%= library_name %> (0.0.1) + inferno_core (~> <%= Inferno::VERSION %>) + +GEM + remote: https://rubygems.org/ + specs: + activesupport (6.1.7.6) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + addressable (2.8.6) + public_suffix (>= 2.0.2, < 6.0) + base62-rb (0.3.1) + bcp47 (0.3.3) + i18n + blueprinter (0.25.2) + byebug (11.1.3) + coderay (1.1.3) + concurrent-ruby (1.2.2) + connection_pool (2.4.1) + crack (0.4.5) + rexml + database_cleaner (1.99.0) + database_cleaner-sequel (1.99.0) + database_cleaner (~> 1.99.0) + sequel + date_time_precision (0.8.1) + debug (1.9.1) + irb (~> 1.10) + reline (>= 0.3.8) + diff-lcs (1.5.0) + domain_name (0.6.20231109) + 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) + 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) + 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) + 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.4.2) + activesupport (>= 5.0.0) + faraday (1.10.3) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.0) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + faraday-retry (~> 1.0) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-httpclient (1.0.1) + faraday-multipart (1.0.4) + multipart-post (~> 2) + faraday-net_http (1.0.1) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday-retry (1.0.3) + faraday_middleware (1.2.0) + faraday (~> 1.0) + fhir_client (5.0.3) + activesupport (>= 3) + addressable (>= 2.3) + fhir_dstu2_models (>= 1.1.1) + fhir_models (>= 4.2.1) + fhir_stu3_models (>= 3.1.1) + nokogiri (>= 1.10.4) + oauth2 (~> 1.1) + rack (>= 1.5) + rest-client (~> 2.0) + tilt (>= 1.1) + fhir_dstu2_models (1.1.1) + bcp47 (>= 0.3) + date_time_precision (>= 0.8) + mime-types (>= 3.0) + nokogiri (>= 1.11.4) + fhir_models (4.2.2) + bcp47 (>= 0.3) + date_time_precision (>= 0.8) + mime-types (>= 3.0) + nokogiri (>= 1.11.4) + fhir_stu3_models (3.1.1) + bcp47 (>= 0.3) + 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) + rack (~> 2.0) + hanami-router (2.0.0) + mustermann (~> 1.0) + mustermann-contrib (~> 1.0) + rack (~> 2.0) + hanami-utils (2.0.0) + concurrent-ruby (~> 1.0) + dry-transformer (~> 1.0, < 2) + hansi (0.2.1) + hashdiff (1.1.0) + http-accept (1.7.0) + http-cookie (1.0.5) + domain_name (~> 0.5) + i18n (1.14.1) + concurrent-ruby (~> 1.0) + ice_nine (0.11.2) + inferno_core (0.4.25) + activesupport (~> 6.1.7.5) + 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-system (= 0.20.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-router (= 2.0.0) + oj (= 3.11.0) + pry + pry-byebug + puma (~> 5.6.7) + rake (~> 13.0) + sequel (~> 5.42.0) + sidekiq (~> 6.5.6) + sqlite3 (~> 1.4) + thor (~> 1.2.1) + tty-markdown (~> 0.7.1) + io-console (0.7.1) + irb (1.11.0) + rdoc + reline (>= 0.3.8) + jwt (2.7.1) + kramdown (2.4.0) + rexml + method_source (1.0.0) + mime-types (3.5.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2023.1205) + minitest (5.20.0) + multi_json (1.15.0) + multi_xml (0.6.0) + multipart-post (2.3.0) + mustermann (1.1.2) + ruby2_keywords (~> 0.0.1) + mustermann-contrib (1.1.2) + hansi (~> 0.2.0) + mustermann (= 1.1.2) + netrc (0.11.0) + nio4r (2.7.0) + nokogiri (1.15.5-arm64-darwin) + racc (~> 1.4) + oauth2 (1.4.11) + faraday (>= 0.17.3, < 3.0) + jwt (>= 1.0, < 3.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 4) + oj (3.11.0) + pastel (0.8.0) + tty-color (~> 0.5) + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.10.1) + byebug (~> 11.0) + pry (>= 0.13, < 0.15) + psych (5.1.2) + stringio + public_suffix (5.0.4) + puma (5.6.7) + nio4r (~> 2.0) + racc (1.7.3) + rack (2.2.8) + rake (13.1.0) + rdoc (6.6.2) + psych (>= 4.0.0) + redis (4.8.1) + reline (0.4.1) + io-console (~> 0.5) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) + rexml (3.2.6) + rouge (4.2.0) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.6) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.1) + ruby2_keywords (0.0.5) + sequel (5.42.0) + sidekiq (6.5.12) + connection_pool (>= 2.2.5, < 3) + rack (~> 2.0) + redis (>= 4.5.0, < 5) + sqlite3 (1.6.9-arm64-darwin) + stringio (3.1.0) + strings (0.2.1) + strings-ansi (~> 0.2) + unicode-display_width (>= 1.5, < 3.0) + unicode_utils (~> 1.4) + strings-ansi (0.2.0) + thor (1.2.2) + tilt (2.3.0) + tty-color (0.6.0) + tty-markdown (0.7.2) + kramdown (>= 1.16.2, < 3.0) + pastel (~> 0.8) + rouge (>= 3.14, < 5.0) + strings (~> 0.2.0) + tty-color (~> 0.5) + tty-screen (~> 0.8) + tty-screen (0.8.2) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) + unicode_utils (1.4.0) + webmock (3.19.1) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + zeitwerk (2.6.12) + +PLATFORMS + arm64-darwin-22 + +DEPENDENCIES + database_cleaner-sequel (~> 1.8) + debug + factory_bot (~> 6.1) + <%= library_name %>! + rspec (~> 3.10) + webmock (~> 3.11) + +BUNDLED WITH + 2.3.23 From 11e4db9c2b1b31f204db9dfe7bb0e6e2c6b67c57 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 3 Jan 2024 15:28:53 -0500 Subject: [PATCH 41/50] remove Gemfile.lock.tt and add bundle install step in inferno new --- lib/inferno/apps/cli/new.rb | 19 +- .../apps/cli/templates/Gemfile.lock.tt | 288 ------------------ spec/inferno/apps/cli/new_spec.rb | 1 + 3 files changed, 19 insertions(+), 289 deletions(-) delete mode 100644 lib/inferno/apps/cli/templates/Gemfile.lock.tt diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index 444cda9a1..93525971b 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -39,15 +39,22 @@ def self.source_root default: [], repeatable: true, desc: "Author names for gemspec file; you may use '-a' multiple times" + class_option :skip_bundle, + type: :boolean, + aliases: '-b', + default: false, + desc: "Do not run bundle install" add_runtime_options! def create_app directory('.', root_name, { mode: :preserve, recursive: true, verbose: !options['quiet'] }) + + bundle_install + say_unless_quiet "Created #{root_name} Inferno test kit!", :green return unless options['pretend'] - say_unless_quiet 'This was a dry run; re-run without `--pretend` to actually create project', :yellow end @@ -66,6 +73,16 @@ def default_author ENV['USER'] || ENV['USERNAME'] || 'TODO' end + def bundle_install + return if options['skip_bundle'] + + inside(root_name) do + Bundler.with_unbundled_env do + run 'bundle install', verbose: !options['quiet'], capture: !!options['quiet'] + end + end + end + def say_unless_quiet(*args) say(*args) unless options['quiet'] end diff --git a/lib/inferno/apps/cli/templates/Gemfile.lock.tt b/lib/inferno/apps/cli/templates/Gemfile.lock.tt deleted file mode 100644 index 67fefbf96..000000000 --- a/lib/inferno/apps/cli/templates/Gemfile.lock.tt +++ /dev/null @@ -1,288 +0,0 @@ -PATH - remote: . - specs: - <%= library_name %> (0.0.1) - inferno_core (~> <%= Inferno::VERSION %>) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (6.1.7.6) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) - addressable (2.8.6) - public_suffix (>= 2.0.2, < 6.0) - base62-rb (0.3.1) - bcp47 (0.3.3) - i18n - blueprinter (0.25.2) - byebug (11.1.3) - coderay (1.1.3) - concurrent-ruby (1.2.2) - connection_pool (2.4.1) - crack (0.4.5) - rexml - database_cleaner (1.99.0) - database_cleaner-sequel (1.99.0) - database_cleaner (~> 1.99.0) - sequel - date_time_precision (0.8.1) - debug (1.9.1) - irb (~> 1.10) - reline (>= 0.3.8) - diff-lcs (1.5.0) - domain_name (0.6.20231109) - 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) - 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) - 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) - 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.4.2) - activesupport (>= 5.0.0) - faraday (1.10.3) - faraday-em_http (~> 1.0) - faraday-em_synchrony (~> 1.0) - faraday-excon (~> 1.1) - faraday-httpclient (~> 1.0) - faraday-multipart (~> 1.0) - faraday-net_http (~> 1.0) - faraday-net_http_persistent (~> 1.0) - faraday-patron (~> 1.0) - faraday-rack (~> 1.0) - faraday-retry (~> 1.0) - ruby2_keywords (>= 0.0.4) - faraday-em_http (1.0.0) - faraday-em_synchrony (1.0.0) - faraday-excon (1.1.0) - faraday-httpclient (1.0.1) - faraday-multipart (1.0.4) - multipart-post (~> 2) - faraday-net_http (1.0.1) - faraday-net_http_persistent (1.2.0) - faraday-patron (1.0.0) - faraday-rack (1.0.0) - faraday-retry (1.0.3) - faraday_middleware (1.2.0) - faraday (~> 1.0) - fhir_client (5.0.3) - activesupport (>= 3) - addressable (>= 2.3) - fhir_dstu2_models (>= 1.1.1) - fhir_models (>= 4.2.1) - fhir_stu3_models (>= 3.1.1) - nokogiri (>= 1.10.4) - oauth2 (~> 1.1) - rack (>= 1.5) - rest-client (~> 2.0) - tilt (>= 1.1) - fhir_dstu2_models (1.1.1) - bcp47 (>= 0.3) - date_time_precision (>= 0.8) - mime-types (>= 3.0) - nokogiri (>= 1.11.4) - fhir_models (4.2.2) - bcp47 (>= 0.3) - date_time_precision (>= 0.8) - mime-types (>= 3.0) - nokogiri (>= 1.11.4) - fhir_stu3_models (3.1.1) - bcp47 (>= 0.3) - 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) - rack (~> 2.0) - hanami-router (2.0.0) - mustermann (~> 1.0) - mustermann-contrib (~> 1.0) - rack (~> 2.0) - hanami-utils (2.0.0) - concurrent-ruby (~> 1.0) - dry-transformer (~> 1.0, < 2) - hansi (0.2.1) - hashdiff (1.1.0) - http-accept (1.7.0) - http-cookie (1.0.5) - domain_name (~> 0.5) - i18n (1.14.1) - concurrent-ruby (~> 1.0) - ice_nine (0.11.2) - inferno_core (0.4.25) - activesupport (~> 6.1.7.5) - 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-system (= 0.20.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-router (= 2.0.0) - oj (= 3.11.0) - pry - pry-byebug - puma (~> 5.6.7) - rake (~> 13.0) - sequel (~> 5.42.0) - sidekiq (~> 6.5.6) - sqlite3 (~> 1.4) - thor (~> 1.2.1) - tty-markdown (~> 0.7.1) - io-console (0.7.1) - irb (1.11.0) - rdoc - reline (>= 0.3.8) - jwt (2.7.1) - kramdown (2.4.0) - rexml - method_source (1.0.0) - mime-types (3.5.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2023.1205) - minitest (5.20.0) - multi_json (1.15.0) - multi_xml (0.6.0) - multipart-post (2.3.0) - mustermann (1.1.2) - ruby2_keywords (~> 0.0.1) - mustermann-contrib (1.1.2) - hansi (~> 0.2.0) - mustermann (= 1.1.2) - netrc (0.11.0) - nio4r (2.7.0) - nokogiri (1.15.5-arm64-darwin) - racc (~> 1.4) - oauth2 (1.4.11) - faraday (>= 0.17.3, < 3.0) - jwt (>= 1.0, < 3.0) - multi_json (~> 1.3) - multi_xml (~> 0.5) - rack (>= 1.2, < 4) - oj (3.11.0) - pastel (0.8.0) - tty-color (~> 0.5) - pry (0.14.2) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.10.1) - byebug (~> 11.0) - pry (>= 0.13, < 0.15) - psych (5.1.2) - stringio - public_suffix (5.0.4) - puma (5.6.7) - nio4r (~> 2.0) - racc (1.7.3) - rack (2.2.8) - rake (13.1.0) - rdoc (6.6.2) - psych (>= 4.0.0) - redis (4.8.1) - reline (0.4.1) - io-console (~> 0.5) - rest-client (2.1.0) - http-accept (>= 1.7.0, < 2.0) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) - rexml (3.2.6) - rouge (4.2.0) - rspec (3.12.0) - rspec-core (~> 3.12.0) - rspec-expectations (~> 3.12.0) - rspec-mocks (~> 3.12.0) - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-support (3.12.1) - ruby2_keywords (0.0.5) - sequel (5.42.0) - sidekiq (6.5.12) - connection_pool (>= 2.2.5, < 3) - rack (~> 2.0) - redis (>= 4.5.0, < 5) - sqlite3 (1.6.9-arm64-darwin) - stringio (3.1.0) - strings (0.2.1) - strings-ansi (~> 0.2) - unicode-display_width (>= 1.5, < 3.0) - unicode_utils (~> 1.4) - strings-ansi (0.2.0) - thor (1.2.2) - tilt (2.3.0) - tty-color (0.6.0) - tty-markdown (0.7.2) - kramdown (>= 1.16.2, < 3.0) - pastel (~> 0.8) - rouge (>= 3.14, < 5.0) - strings (~> 0.2.0) - tty-color (~> 0.5) - tty-screen (~> 0.8) - tty-screen (0.8.2) - tzinfo (2.0.6) - concurrent-ruby (~> 1.0) - unicode-display_width (2.5.0) - unicode_utils (1.4.0) - webmock (3.19.1) - addressable (>= 2.8.0) - crack (>= 0.3.2) - hashdiff (>= 0.4.0, < 2.0.0) - zeitwerk (2.6.12) - -PLATFORMS - arm64-darwin-22 - -DEPENDENCIES - database_cleaner-sequel (~> 1.8) - debug - factory_bot (~> 6.1) - <%= library_name %>! - rspec (~> 3.10) - webmock (~> 3.11) - -BUNDLED WITH - 2.3.23 diff --git a/spec/inferno/apps/cli/new_spec.rb b/spec/inferno/apps/cli/new_spec.rb index 83f5807c8..86d4f782f 100644 --- a/spec/inferno/apps/cli/new_spec.rb +++ b/spec/inferno/apps/cli/new_spec.rb @@ -18,6 +18,7 @@ %w[test-fhir-app --author ABC --author DEF] ].each do |cli_args| cli_args.append('--quiet') + cli_args.append('--skip-bundle') it "runs inferno new #{cli_args.join(' ')}" do expect { described_class.start(cli_args) }.to_not raise_error From 891f7f0fe281dffcb65179035a2c2c7496328c6e Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 3 Jan 2024 18:57:28 -0500 Subject: [PATCH 42/50] add and debug publish_template.sh script --- publish_template.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 publish_template.sh diff --git a/publish_template.sh b/publish_template.sh new file mode 100755 index 000000000..40cac8b9d --- /dev/null +++ b/publish_template.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# +# Push a new branch to inferno-template GitHub Repository with Inferno updates +# USAGE: +# run ./publish_template +# submit and merge a pull request from the new branch on GitHub + +set -e +set -v + +#REPO_URL=git@github.com:inferno-framework/inferno-template.git +REPO_URL=git@github.com:Shaumik-Ashraf/test_publish_template_script_2.git +TIMESTAMP=$(date -I) + +mkdir -p tmp +cd tmp +rm -rf inferno-template +git clone $REPO_URL inferno-template +rm -f inferno-template/Gemfile.lock +git -C ./inferno-template checkout -b update-$TIMESTAMP +bundle exec ../bin/inferno new inferno-template --author 'Inferno Template' --force +git -C ./inferno-template add --all +git -C ./inferno-template commit -m "update inferno-template via inferno new on $TIMESTAMP" +git -C ./inferno-template push -u origin update-$TIMESTAMP --force +cd .. From 10b86412f44b55d439d2d07691c88b497ec99f82 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 3 Jan 2024 19:01:29 -0500 Subject: [PATCH 43/50] rubocop conformance --- lib/inferno/apps/cli/new.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index 93525971b..fadb90e4c 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -43,7 +43,7 @@ def self.source_root type: :boolean, aliases: '-b', default: false, - desc: "Do not run bundle install" + desc: 'Do not run bundle install' add_runtime_options! @@ -55,6 +55,7 @@ def create_app say_unless_quiet "Created #{root_name} Inferno test kit!", :green return unless options['pretend'] + say_unless_quiet 'This was a dry run; re-run without `--pretend` to actually create project', :yellow end @@ -78,7 +79,7 @@ def bundle_install inside(root_name) do Bundler.with_unbundled_env do - run 'bundle install', verbose: !options['quiet'], capture: !!options['quiet'] + run 'bundle install', verbose: !options['quiet'], capture: options['quiet'] end end end From 0c239058aac61f4697b9f496a403f8e20e038ae7 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 3 Jan 2024 19:09:05 -0500 Subject: [PATCH 44/50] put inferno-template repo url in publish_template.sh --- publish_template.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/publish_template.sh b/publish_template.sh index 40cac8b9d..98b145927 100755 --- a/publish_template.sh +++ b/publish_template.sh @@ -8,8 +8,7 @@ set -e set -v -#REPO_URL=git@github.com:inferno-framework/inferno-template.git -REPO_URL=git@github.com:Shaumik-Ashraf/test_publish_template_script_2.git +REPO_URL=git@github.com:inferno-framework/inferno-template.git TIMESTAMP=$(date -I) mkdir -p tmp From d05e84e33acc010b54c8597f68623ba6c07318a6 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Mon, 8 Jan 2024 17:56:25 -0500 Subject: [PATCH 45/50] debugging --- lib/inferno/apps/cli/new.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index fadb90e4c..568e4509b 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -1,5 +1,6 @@ require 'thor' require_relative '../../utils/named_thor_actions' +require_relative '../../version' module Inferno module CLI From d4bbf8292303a50042009e14a37930d8c76f354b Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Tue, 9 Jan 2024 16:44:18 -0500 Subject: [PATCH 46/50] fix bundler bug in inferno new --- lib/inferno/apps/cli/new.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index 568e4509b..1693c15c2 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -1,4 +1,5 @@ require 'thor' +require 'bundler' require_relative '../../utils/named_thor_actions' require_relative '../../version' From e4ab6752bf48a13c947e59ae430b6c9b5843e362 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Tue, 9 Jan 2024 16:45:18 -0500 Subject: [PATCH 47/50] remove publish_template.sh --- publish_template.sh | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100755 publish_template.sh diff --git a/publish_template.sh b/publish_template.sh deleted file mode 100755 index 98b145927..000000000 --- a/publish_template.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -# -# Push a new branch to inferno-template GitHub Repository with Inferno updates -# USAGE: -# run ./publish_template -# submit and merge a pull request from the new branch on GitHub - -set -e -set -v - -REPO_URL=git@github.com:inferno-framework/inferno-template.git -TIMESTAMP=$(date -I) - -mkdir -p tmp -cd tmp -rm -rf inferno-template -git clone $REPO_URL inferno-template -rm -f inferno-template/Gemfile.lock -git -C ./inferno-template checkout -b update-$TIMESTAMP -bundle exec ../bin/inferno new inferno-template --author 'Inferno Template' --force -git -C ./inferno-template add --all -git -C ./inferno-template commit -m "update inferno-template via inferno new on $TIMESTAMP" -git -C ./inferno-template push -u origin update-$TIMESTAMP --force -cd .. From de4e0cf0c1a219c4be0d8d4b028b4a45ecd24e30 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Tue, 9 Jan 2024 16:48:48 -0500 Subject: [PATCH 48/50] change fallback name from todo to put_your_name_here --- lib/inferno/apps/cli/new.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index 1693c15c2..a47db34a9 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -73,7 +73,7 @@ def authors end def default_author - ENV['USER'] || ENV['USERNAME'] || 'TODO' + ENV['USER'] || ENV['USERNAME'] || 'PUT_YOUR_NAME_HERE' end def bundle_install From 02770d554f843f917224285b45cb2844c10f932c Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Thu, 11 Jan 2024 13:17:26 -0500 Subject: [PATCH 49/50] add run inferno migrate --- lib/inferno/apps/cli/new.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index a47db34a9..6396bc7ee 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -53,6 +53,7 @@ def create_app directory('.', root_name, { mode: :preserve, recursive: true, verbose: !options['quiet'] }) bundle_install + inferno_migrate say_unless_quiet "Created #{root_name} Inferno test kit!", :green @@ -86,6 +87,14 @@ def bundle_install end end + def inferno_migrate + return if options['skip_bundle'] + + inside(root_name) do + run 'inferno migrate', verbose: !options['quiet'], capture: options['quiet'] + end + end + def say_unless_quiet(*args) say(*args) unless options['quiet'] end From 11da63d0f5c44df0fe92c036f6283ca79c012d73 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 17 Jan 2024 15:29:01 -0500 Subject: [PATCH 50/50] add bundle exec to inferno migrate in lib/inferno/apps/cli/new.rb Co-authored-by: Stephen MacVicar --- lib/inferno/apps/cli/new.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/inferno/apps/cli/new.rb b/lib/inferno/apps/cli/new.rb index 6396bc7ee..4d6e313e9 100644 --- a/lib/inferno/apps/cli/new.rb +++ b/lib/inferno/apps/cli/new.rb @@ -91,7 +91,7 @@ def inferno_migrate return if options['skip_bundle'] inside(root_name) do - run 'inferno migrate', verbose: !options['quiet'], capture: options['quiet'] + run 'bundle exec inferno migrate', verbose: !options['quiet'], capture: options['quiet'] end end