From d44a3cfb0dbb5ab68952a3bc7fc7325d7dde2005 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Mon, 9 Dec 2024 18:35:29 -0500 Subject: [PATCH 1/6] draft client dev suite --- .../dev_client_testing/client_test_suite.rb | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 dev_suites/dev_client_testing/client_test_suite.rb diff --git a/dev_suites/dev_client_testing/client_test_suite.rb b/dev_suites/dev_client_testing/client_test_suite.rb new file mode 100644 index 000000000..f43b9cfa0 --- /dev/null +++ b/dev_suites/dev_client_testing/client_test_suite.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +module DevClientTesting + class ClientTestSuite < Inferno::TestSuite + title 'Client Test Suite' + id :dev_client_test_suite + description 'Inferno Core Developer Suite for testing clients.' + + ## BUG: this endpoint is return 302 Found instead of 200 OK + route(:get, 'client_test_endpoint', ->(rack_env) { [200, {'Content-Type' => 'application/json'}, JSON.pretty_generate(rack_env).split] }) + + resume_test_route :get, '/client_test_endpoint' do |request| + request.query_parameters['uid'] + end + + group do + title 'Client Test Group' + id :dev_client_test_group + + test do + title 'Wait For Request' + id :dev_wait_for_request_test + output :uid + + receives_request :client_test_endpoint + + run do + uid = SecureRandom.uuid + output uid: uid + + wait( + identifier: uid, + message: <<~WAIT_FOR_REQUEST_MESSAGE + Send a GET request to the following URL to continue: + + #{Inferno::Application['base_url']}/custom/dev_client_test_suite/client_test_endpoint?uid=#{uid} + + I.e: + + ``` + curl -X GET #{Inferno::Application['base_url']}/custom/dev_client_test_suite/client_test_endpoint?uid=#{uid} + ``` + WAIT_FOR_REQUEST_MESSAGE + ) + end + end + + test do + title 'Validate Request' + id :dev_validate_request_test + input :uid, optional: true + + uses_request :client_test_endpoint + + run do + assert request.query_parameters[:uid] == uid + end + end + end + end +end From d5d193e4f9399544f31eeb4da0001b73908737a1 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Tue, 10 Dec 2024 15:34:45 -0500 Subject: [PATCH 2/6] use SuiteEndpoint --- .../client_test_endpoint.rb | 19 +++++++++++++++++++ .../dev_client_testing/client_test_suite.rb | 11 ++++------- 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 dev_suites/dev_client_testing/client_test_endpoint.rb diff --git a/dev_suites/dev_client_testing/client_test_endpoint.rb b/dev_suites/dev_client_testing/client_test_endpoint.rb new file mode 100644 index 000000000..2d4a6715b --- /dev/null +++ b/dev_suites/dev_client_testing/client_test_endpoint.rb @@ -0,0 +1,19 @@ +class ClientTestEndpoint < Inferno::DSL::SuiteEndpoint + def test_run_identifier + request.params[:uid] + end + + def make_response + response.status = 200 + response.body = {status: 'ok'}.to_json + response.format = :json + end + + def update_result + results_repo.update(result.id, result: 'pass') + end + + def tags + [] + end +end diff --git a/dev_suites/dev_client_testing/client_test_suite.rb b/dev_suites/dev_client_testing/client_test_suite.rb index f43b9cfa0..f4743718b 100644 --- a/dev_suites/dev_client_testing/client_test_suite.rb +++ b/dev_suites/dev_client_testing/client_test_suite.rb @@ -1,17 +1,14 @@ # frozen_string_literal: true +require_relative 'client_test_endpoint' + module DevClientTesting class ClientTestSuite < Inferno::TestSuite title 'Client Test Suite' id :dev_client_test_suite description 'Inferno Core Developer Suite for testing clients.' - ## BUG: this endpoint is return 302 Found instead of 200 OK - route(:get, 'client_test_endpoint', ->(rack_env) { [200, {'Content-Type' => 'application/json'}, JSON.pretty_generate(rack_env).split] }) - - resume_test_route :get, '/client_test_endpoint' do |request| - request.query_parameters['uid'] - end + suite_endpoint :get, '/client_test_endpoint', ClientTestEndpoint group do title 'Client Test Group' @@ -53,7 +50,7 @@ class ClientTestSuite < Inferno::TestSuite uses_request :client_test_endpoint run do - assert request.query_parameters[:uid] == uid + assert 200 == request.status end end end From 571da637b14e9424f064bc774be0d9403f5829db Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 18 Dec 2024 12:45:02 -0500 Subject: [PATCH 3/6] fix describe suite command and comment --- lib/inferno/apps/cli/suite.rb | 1 + lib/inferno/config/boot/suites.rb | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/inferno/apps/cli/suite.rb b/lib/inferno/apps/cli/suite.rb index c2984fda7..a207a83d4 100644 --- a/lib/inferno/apps/cli/suite.rb +++ b/lib/inferno/apps/cli/suite.rb @@ -24,6 +24,7 @@ def input_template(suite_id) LONGDESC def describe(suite_id) ENV['NO_DB'] = 'true' + require_relative '../../../inferno' Inferno::Application.start(:suites) suite = Inferno::Repositories::TestSuites.new.find(suite_id) diff --git a/lib/inferno/config/boot/suites.rb b/lib/inferno/config/boot/suites.rb index 58eaa257d..df06e2559 100644 --- a/lib/inferno/config/boot/suites.rb +++ b/lib/inferno/config/boot/suites.rb @@ -1,3 +1,6 @@ +# You must require 'lib/inferno.rb' file before invoking +# this provider via `Inferno::Application.start(:suites)` +# because `Inferno.routes` must be defined for some suites Inferno::Application.register_provider(:suites) do prepare do target_container.start :logging From e5bbdba8ef273a6dd0771028a21ac77481056598 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Wed, 18 Dec 2024 14:06:50 -0500 Subject: [PATCH 4/6] rm dev_client_suites --- .../client_test_endpoint.rb | 19 ------ .../dev_client_testing/client_test_suite.rb | 58 ------------------- 2 files changed, 77 deletions(-) delete mode 100644 dev_suites/dev_client_testing/client_test_endpoint.rb delete mode 100644 dev_suites/dev_client_testing/client_test_suite.rb diff --git a/dev_suites/dev_client_testing/client_test_endpoint.rb b/dev_suites/dev_client_testing/client_test_endpoint.rb deleted file mode 100644 index 2d4a6715b..000000000 --- a/dev_suites/dev_client_testing/client_test_endpoint.rb +++ /dev/null @@ -1,19 +0,0 @@ -class ClientTestEndpoint < Inferno::DSL::SuiteEndpoint - def test_run_identifier - request.params[:uid] - end - - def make_response - response.status = 200 - response.body = {status: 'ok'}.to_json - response.format = :json - end - - def update_result - results_repo.update(result.id, result: 'pass') - end - - def tags - [] - end -end diff --git a/dev_suites/dev_client_testing/client_test_suite.rb b/dev_suites/dev_client_testing/client_test_suite.rb deleted file mode 100644 index f4743718b..000000000 --- a/dev_suites/dev_client_testing/client_test_suite.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -require_relative 'client_test_endpoint' - -module DevClientTesting - class ClientTestSuite < Inferno::TestSuite - title 'Client Test Suite' - id :dev_client_test_suite - description 'Inferno Core Developer Suite for testing clients.' - - suite_endpoint :get, '/client_test_endpoint', ClientTestEndpoint - - group do - title 'Client Test Group' - id :dev_client_test_group - - test do - title 'Wait For Request' - id :dev_wait_for_request_test - output :uid - - receives_request :client_test_endpoint - - run do - uid = SecureRandom.uuid - output uid: uid - - wait( - identifier: uid, - message: <<~WAIT_FOR_REQUEST_MESSAGE - Send a GET request to the following URL to continue: - - #{Inferno::Application['base_url']}/custom/dev_client_test_suite/client_test_endpoint?uid=#{uid} - - I.e: - - ``` - curl -X GET #{Inferno::Application['base_url']}/custom/dev_client_test_suite/client_test_endpoint?uid=#{uid} - ``` - WAIT_FOR_REQUEST_MESSAGE - ) - end - end - - test do - title 'Validate Request' - id :dev_validate_request_test - input :uid, optional: true - - uses_request :client_test_endpoint - - run do - assert 200 == request.status - end - end - end - end -end From f599e88ed18cbd64689a52348ea2c37a48217c46 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Thu, 19 Dec 2024 15:48:24 -0500 Subject: [PATCH 5/6] create lib/inferno/route_storage.rb --- lib/inferno.rb | 4 +--- lib/inferno/apps/cli/suite.rb | 2 +- lib/inferno/apps/cli/suites.rb | 2 +- lib/inferno/config/boot/suites.rb | 4 +--- lib/inferno/route_storage.rb | 10 ++++++++++ 5 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 lib/inferno/route_storage.rb diff --git a/lib/inferno.rb b/lib/inferno.rb index 8e79d096b..2c74f1f5b 100644 --- a/lib/inferno.rb +++ b/lib/inferno.rb @@ -1,7 +1,4 @@ module Inferno - def self.routes - @routes ||= [] - end end require_relative 'inferno/config/application' @@ -14,3 +11,4 @@ def self.routes require_relative 'inferno/test_runner' require_relative 'inferno/version' require_relative 'inferno/utils/static_assets' +require_relative 'inferno/route_storage' diff --git a/lib/inferno/apps/cli/suite.rb b/lib/inferno/apps/cli/suite.rb index a207a83d4..a80456308 100644 --- a/lib/inferno/apps/cli/suite.rb +++ b/lib/inferno/apps/cli/suite.rb @@ -24,7 +24,7 @@ def input_template(suite_id) LONGDESC def describe(suite_id) ENV['NO_DB'] = 'true' - require_relative '../../../inferno' + # TODO delete me require_relative '../../../inferno' Inferno::Application.start(:suites) suite = Inferno::Repositories::TestSuites.new.find(suite_id) diff --git a/lib/inferno/apps/cli/suites.rb b/lib/inferno/apps/cli/suites.rb index 2ae36f8dc..fcb717648 100644 --- a/lib/inferno/apps/cli/suites.rb +++ b/lib/inferno/apps/cli/suites.rb @@ -6,7 +6,7 @@ class Suites def run ENV['NO_DB'] = 'true' - require_relative '../../../inferno' + # TODO delete me require_relative '../../../inferno' Inferno::Application.start(:suites) diff --git a/lib/inferno/config/boot/suites.rb b/lib/inferno/config/boot/suites.rb index df06e2559..9445c946f 100644 --- a/lib/inferno/config/boot/suites.rb +++ b/lib/inferno/config/boot/suites.rb @@ -1,6 +1,3 @@ -# You must require 'lib/inferno.rb' file before invoking -# this provider via `Inferno::Application.start(:suites)` -# because `Inferno.routes` must be defined for some suites Inferno::Application.register_provider(:suites) do prepare do target_container.start :logging @@ -9,6 +6,7 @@ require 'inferno/entities/test_group' require 'inferno/entities/test_suite' require 'inferno/entities/test_kit' + require 'inferno/route_storage' files_to_load = Dir.glob(File.join(Dir.pwd, 'lib', '*.rb')) diff --git a/lib/inferno/route_storage.rb b/lib/inferno/route_storage.rb new file mode 100644 index 000000000..d9c780bd6 --- /dev/null +++ b/lib/inferno/route_storage.rb @@ -0,0 +1,10 @@ +module Inferno + # @private + module RouteStorage + def routes + @routes ||= [] + end + end + + extend RouteStorage +end From 21ca8659874c27ae439c80b306e5f53157f30155 Mon Sep 17 00:00:00 2001 From: Shaumik-Ashraf Date: Thu, 19 Dec 2024 15:58:14 -0500 Subject: [PATCH 6/6] clean --- lib/inferno/apps/cli/suite.rb | 1 - lib/inferno/apps/cli/suites.rb | 2 -- 2 files changed, 3 deletions(-) diff --git a/lib/inferno/apps/cli/suite.rb b/lib/inferno/apps/cli/suite.rb index a80456308..c2984fda7 100644 --- a/lib/inferno/apps/cli/suite.rb +++ b/lib/inferno/apps/cli/suite.rb @@ -24,7 +24,6 @@ def input_template(suite_id) LONGDESC def describe(suite_id) ENV['NO_DB'] = 'true' - # TODO delete me require_relative '../../../inferno' Inferno::Application.start(:suites) suite = Inferno::Repositories::TestSuites.new.find(suite_id) diff --git a/lib/inferno/apps/cli/suites.rb b/lib/inferno/apps/cli/suites.rb index fcb717648..03946dc34 100644 --- a/lib/inferno/apps/cli/suites.rb +++ b/lib/inferno/apps/cli/suites.rb @@ -6,8 +6,6 @@ class Suites def run ENV['NO_DB'] = 'true' - # TODO delete me require_relative '../../../inferno' - Inferno::Application.start(:suites) suites = Inferno::Repositories::TestSuites.new.all