Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

FI-2748: Add TestKit to template #561

Merged
merged 18 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/inferno/apps/cli/templates/%library_name%.gemspec.tt
Shaumik-Ashraf marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
require_relative 'lib/<%= library_name %>/version'

Gem::Specification.new do |spec|
spec.name = '<%= library_name %>'
spec.version = '0.0.1'
spec.version = <%= module_name %>::VERSION
spec.authors = <%= authors %>
# spec.email = ['TODO']
spec.date = Time.now.utc.strftime('%Y-%m-%d')
spec.summary = '<%= title_name %> Test Kit'
spec.description = '<%= human_name %> Inferno test kit for FHIR'
spec.summary = '<%= title_name %>'
# spec.description = <<~DESCRIPTION
# This is a big markdown description of the test kit.
# DESCRIPTION
Shaumik-Ashraf marked this conversation as resolved.
Show resolved Hide resolved
# spec.homepage = 'TODO'
spec.license = 'Apache-2.0'
spec.add_runtime_dependency 'inferno_core', '~> <%= Inferno::VERSION %>'
Expand Down
5 changes: 3 additions & 2 deletions lib/inferno/apps/cli/templates/Dockerfile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ RUN mkdir -p $INSTALL_PATH

WORKDIR $INSTALL_PATH

ADD lib/<%= library_name %>/metadata.rb $INSTALL_PATH/lib/<%= library_name %>/metadata.rb
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
# 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
# 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
Expand Down
59 changes: 1 addition & 58 deletions lib/inferno/apps/cli/templates/lib/%library_name%.rb.tt
Original file line number Diff line number Diff line change
@@ -1,58 +1 @@
require_relative '<%= library_name %>/patient_group'

module <%= module_name %>
class Suite < Inferno::TestSuite
id :<%= test_suite_id %>
title '<%= title_name %> Test Suite'
description '<%= human_name %> test suite.'

# 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 requests will use this FHIR validator
fhir_resource_validator do
# igs 'identifier#version' # Use this method for published IGs/versions
# igs 'igs/filename.tgz' # Use this otherwise

exclude_message do |message|
message.message.match?(/\A\S+: \S+: URL value '.*' does not resolve/)
end
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
require_relative '<%= library_name %>/suite'
18 changes: 18 additions & 0 deletions lib/inferno/apps/cli/templates/lib/%library_name%/metadata.rb.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative 'version'

module <%= module_name %>
class Metadata < Inferno::TestKit
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not wild about Metadata as the class name. Maybe TestKitMetadata would be better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the Metadata, it makes the global name SomethingTestKit::Metadata which makes sense since the RubyGem itself is the Test Kit, SomethingTestKit is the namespace, and Metadata is really just metadata and maybe config.

If anything I would rename/alias Inferno::TestKit to Inferno::TestKitMetadata.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the class Metadata (or whatever we call it) into lib/%library_name%.rb.tt (i.e: lib/my_test_kit.rb)? And then the content currently in lib/my_test_kit.rb should be moved into lib/my_test_kit/my_test_kit_suite.rb. Then people can copy-paste the suite file to kick start Test Kits that house multiple Test Suites like PDex.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think we should move the current contents into a separate suite file, but I don't think we should move the metadata there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so lib/my_test_kit.rb will only have a couple of includes in it?

I don't care that much one way or another, but Shaumik's suggestion sounds pretty reasonable to me. This way lib/my_test_kit.rb contains metadata about the test kit in a very obvious file (the 'most important' file), and we have fewer files to deal with in the main gem directory? I can see if you wanted to make it so you can load just the Test Kit metadata without loading everything "within" the test kit too. But is there a use case for that? Unfortunately we can't reference this thing in our .gemspec, which means it can't be used like version.rb is used and why its great to have that in its own file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my goal was to be able to load just the test kits without loading the suites, but I guess the platform will need the suites anyway.

id :<%= test_kit_id %>
title '<%= title_name %>'
description <<~DESCRIPTION
This is a big markdown description of the test kit.
DESCRIPTION
suite_ids [:<%= test_suite_id %>]
# tags ['SMART App Launch', 'US Core']
# last_updated '2024-03-07'
version VERSION
maturity 'Low'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should force a standard here. I'm ok not for now though i suppose just to get through this first iteration.

authors <%= authors %>
arscan marked this conversation as resolved.
Show resolved Hide resolved
# repo 'TODO'
end
end
59 changes: 59 additions & 0 deletions lib/inferno/apps/cli/templates/lib/%library_name%/suite.rb.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require_relative 'metadata'
require_relative 'patient_group'

module <%= module_name %>
class Suite < Inferno::TestSuite
id :<%= test_suite_id %>
title '<%= title_name %> Test Suite'
description '<%= human_name %> test suite.'

# 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 requests will use this FHIR validator
fhir_resource_validator do
# igs 'identifier#version' # Use this method for published IGs/versions
# igs 'igs/filename.tgz' # Use this otherwise

exclude_message do |message|
message.message.match?(/\A\S+: \S+: URL value '.*' does not resolve/)
end
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module <%= module_name %>
VERSION = '0.0.0'.freeze
end
1 change: 1 addition & 0 deletions lib/inferno/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require_relative 'entities/session_data'
require_relative 'entities/test'
require_relative 'entities/test_group'
require_relative 'entities/test_kit'
require_relative 'entities/test_run'
require_relative 'entities/test_session'
require_relative 'entities/test_suite'
Expand Down
6 changes: 4 additions & 2 deletions lib/inferno/entities/test_kit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Entities
# @example
#
# module USCoreTestKit
# class TestKit < Inferno::Entities::TestKit
# class Metadata < Inferno::Entities::TestKit
# id :us_core
# title 'US Core Test Kit'
# description <<~DESCRIPTION
Expand Down Expand Up @@ -156,7 +156,7 @@ def add_self_to_repository

# @private
def repository
@repository ||= Inferno::Repositories::TestKits
@repository ||= Inferno::Repositories::TestKits.new
end

# @private
Expand All @@ -168,4 +168,6 @@ def copy_instance_variables
end
end
end

TestKit = Entities::TestKit
end
26 changes: 23 additions & 3 deletions lib/inferno/entities/test_suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ def reference_hash
}
end

# Set/get the version of this test suite.
# Set/get the version of this test suite. Defaults to the TestKit
# version.
#
# @param version [String]
#
# @return [String, nil]
def version(version = nil)
return @version if version.nil?
@version = version if version.present?

@version = version
@version || test_kit&.version
end

# @private
Expand Down Expand Up @@ -186,6 +187,25 @@ def suite_summary(suite_summary = nil)

@suite_summary = format_markdown(suite_summary)
end

# Get the TestKit this suite belongs to
#
# @return [Inferno::Entities::TestKit]
def test_kit
return @test_kit if @test_kit

module_name = name

while module_name.present? && @test_kit.nil?
Shaumik-Ashraf marked this conversation as resolved.
Show resolved Hide resolved
module_name = module_name.deconstantize

next unless const_defined?("#{module_name}::Metadata")

@test_kit = const_get("#{module_name}::Metadata")
end

@test_kit
end
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/inferno/utils/named_thor_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ def title_name
human_name.split.map(&:capitalize).join(' ')
end

def test_kit_id
library_name.delete_suffix('_test_kit')
end

def test_suite_id
"#{library_name}_test_suite"
test_kit_id
end
end
end
Expand Down
10 changes: 4 additions & 6 deletions spec/inferno/cli/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@
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? '--author'
expect(File.read('test-fhir-app/test_fhir_app.gemspec')).to match(/authors\s*=.*ABC/)
end

if cli_args.count('--author') == 2
expect(File.read('test-fhir-app/test_fhir_app.gemspec')).to match(/authors\s*=.*ABC.*DEF/)
if cli_args.count('--author') == 1
expect(File.read('test-fhir-app/lib/test_fhir_app/metadata.rb')).to include('authors ["ABC"]')
elsif cli_args.count('--author') == 2
expect(File.read('test-fhir-app/lib/test_fhir_app/metadata.rb')).to include('authors ["ABC", "DEF"]')
end

if cli_args.count('--implementation-guide') == 1
Expand Down
Loading
Loading