Skip to content
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
30 changes: 30 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Unit Tests

on:
push:
branches:
- master
pull_request:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-24.04

steps:
- name: Checkout repository
uses: actions/checkout@v7

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.4.9'
bundler-cache: true

- name: Run unit tests
run: >-
bundle exec ruby -Ilib -Itest -e
'ARGV.each { |file| require File.expand_path(file) }'
$(find test -name '*_test.rb' -print)
7 changes: 2 additions & 5 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
require 'simplecov'
SimpleCov.command_name 'Unit Tests'
SimpleCov.start do
add_filter "test/"
add_group "Library", "lib"
end
SimpleCov.skip "test/"
SimpleCov.group "Library", "lib"

class SimpleCov::Formatter::QualityFormatter
def format(result)
Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ source 'https://rubygems.org'

gemspec

gem 'fhir_dstu2_models', git: 'https://github.com/incendilabs/fhir_dstu2_models.git', branch: 'master'
gem 'fhir_models', git: 'https://github.com/incendilabs/fhir_models.git', branch: 'master'
gem 'fhir_stu3_models', git: 'https://github.com/incendilabs/fhir_stu3_models.git', branch: 'master'

group :test do
gem 'rubocop', '~> 0.52.1', require: false
gem 'awesome_print', require: 'ap'
Expand Down
2 changes: 1 addition & 1 deletion fhir_client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'fhir_stu3_models', '>= 3.0.1'
spec.add_dependency 'fhir_dstu2_models', '>= 1.0.10'
spec.add_dependency 'nokogiri', '>= 1.10.4'
spec.add_dependency 'oauth2', '~> 1.1'
spec.add_dependency 'oauth2', '>= 2.0', '< 3.0'
spec.add_dependency 'rack', '>= 1.5'
spec.add_dependency 'rest-client', '~> 2.0'
spec.add_dependency 'tilt', '>= 1.1'
Expand Down
17 changes: 9 additions & 8 deletions lib/fhir_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ def parse_reply(klass, format, response)
res = format.include?('xml') ? parser.from_xml(response.body) : parser.from_json(response.body)
res.client = self unless res.nil?
rescue => e
FHIR.logger.error "Failed to parse #{format} as resource #{klass}: #{e.message}"
message = "Failed to parse #{format} as resource #{klass}: #{e.message}"
FHIR.logger.debug(message)
res = nil
end
res
Expand Down Expand Up @@ -492,7 +493,7 @@ def get(path, headers = {})
if !e.respond_to?(:response) || e.response.nil?
# Re-raise the client error if there's no response. Otherwise, logging
# and other things break below!
FHIR.logger.error "GET - Request: #{url} failed! No response from server: #{e}"
FHIR.logger.debug "GET - Request: #{url} failed! No response from server: #{e}"
raise # Re-raise the same error we caught.
end
response = e.response if e.response
Expand Down Expand Up @@ -539,7 +540,7 @@ def get(path, headers = {})
if !e.respond_to?(:response) || e.response.nil?
# Re-raise the client error if there's no response. Otherwise, logging
# and other things break below!
FHIR.logger.error "GET - Request: #{url} failed! No response from server: #{e}"
FHIR.logger.debug "GET - Request: #{url} failed! No response from server: #{e}"
raise # Re-raise the same error we caught.
end
response = e.response
Expand Down Expand Up @@ -574,7 +575,7 @@ def post(path, resource, headers)
if !e.respond_to?(:response) || e.response.nil?
# Re-raise the client error if there's no response. Otherwise, logging
# and other things break below!
FHIR.logger.error "POST - Request: #{url} failed! No response from server: #{e}"
FHIR.logger.debug "POST - Request: #{url} failed! No response from server: #{e}"
raise # Re-raise the same error we caught.
end
response = e.response if e.response
Expand Down Expand Up @@ -621,7 +622,7 @@ def put(path, resource, headers)
if !e.respond_to?(:response) || e.response.nil?
# Re-raise the client error if there's no response. Otherwise, logging
# and other things break below!
FHIR.logger.error "PUT - Request: #{url} failed! No response from server: #{e}"
FHIR.logger.debug "PUT - Request: #{url} failed! No response from server: #{e}"
raise # Re-raise the same error we caught.
end
response = e.response if e.response
Expand Down Expand Up @@ -668,7 +669,7 @@ def patch(path, patchset, headers)
if !e.respond_to?(:response) || e.response.nil?
# Re-raise the client error if there's no response. Otherwise, logging
# and other things break below!
FHIR.logger.error "PATCH - Request: #{url} failed! No response from server: #{e}"
FHIR.logger.debug "PATCH - Request: #{url} failed! No response from server: #{e}"
raise # Re-raise the same error we caught.
end
response = e.response if e.response
Expand Down Expand Up @@ -704,7 +705,7 @@ def patch(path, patchset, headers)
if !e.respond_to?(:response) || e.response.nil?
# Re-raise the client error if there's no response. Otherwise, logging
# and other things break below!
FHIR.logger.error "PATCH - Request: #{url} failed! No response from server: #{e}"
FHIR.logger.debug "PATCH - Request: #{url} failed! No response from server: #{e}"
raise # Re-raise the same error we caught.
end
req = {
Expand Down Expand Up @@ -736,7 +737,7 @@ def delete(path, headers)
if !e.respond_to?(:response) || e.response.nil?
# Re-raise the client error if there's no response. Otherwise, logging
# and other things break below!
FHIR.logger.error "DELETE - Request: #{url} failed! No response from server: #{e}"
FHIR.logger.debug "DELETE - Request: #{url} failed! No response from server: #{e}"
raise # Re-raise the same error we caught.
end
response = e.response if e.response
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'simplecov'
SimpleCov.start

require 'stringio'
require 'pry'
require 'test/unit'
require 'webmock/test_unit'
Expand All @@ -14,4 +15,3 @@

ACCEPT_REGEX_XML_DSTU2 = /^(\s*application\/xml\+fhir\s*)(;\s*charset\s*=\s*utf-8\s*)?$/
ACCEPT_REGEX_JSON_DSTU2 = /^(\s*application\/json\+fhir\s*)(;\s*charset\s*=\s*utf-8\s*)?$/

20 changes: 20 additions & 0 deletions test/unit/multiversion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ def test_autodetect_stu3
assert client.default_format.include? 'json'
end

def test_autodetect_logs_intermediate_parse_failure_at_debug
root = File.expand_path '..', File.dirname(File.absolute_path(__FILE__))
capabilitystatement = File.read(File.join(root, 'fixtures', 'capabilitystatement.json'))
stub_request(:get, /autodetect/).to_return(body: capabilitystatement)
original_logger = FHIR.logger
log_output = StringIO.new
FHIR.logger = Logger.new(log_output)

client = FHIR::Client.new('autodetect', fhir_version: :auto)
client.default_xml
client.use_r4
client.detect_version

message = 'Failed to parse application/fhir+xml as resource FHIR::STU3::CapabilityStatement'
assert_match(/DEBUG -- : #{Regexp.escape(message)}/, log_output.string)
assert_no_match(/ERROR -- : #{Regexp.escape(message)}/, log_output.string)
ensure
FHIR.logger = original_logger
end

def test_autodetect_dstu2
root = File.expand_path '..', File.dirname(File.absolute_path(__FILE__))
conformance = File.read(File.join(root, 'fixtures', 'conformance.json'))
Expand Down