Module: RSMP::Validator::ModeDetection
- Included in:
- RSMP::Validator
- Defined in:
- lib/rsmp/validator/mode_detection.rb
Overview
Methods for detecting test mode and building the appropriate tester and auto node.
Instance Method Summary collapse
-
#abort_with_error(error) ⇒ Object
Print an error message and exit.
-
#build_auto_node ⇒ Object
Build the auto node (local site or supervisor to be tested).
-
#build_tester ⇒ Object
Build the tester instance.
-
#check_connection ⇒ Object
Initial connectivity check to verify we can connect to the site/supervisor being tested.
-
#determine_mode(sus_config) ⇒ Object
Determine mode from test file paths.
-
#infer_mode_from_path(path, site_dir, supervisor_dir) ⇒ Object
Determine the test mode from a single expanded path.
-
#select_mode(mode) ⇒ Object
Set whether we are testing a site or a supervisor.
Instance Method Details
#abort_with_error(error) ⇒ Object
Print an error message and exit.
6 7 8 9 |
# File 'lib/rsmp/validator/mode_detection.rb', line 6 def abort_with_error(error) warn "Error: #{error}".colorize(:red) exit 1 end |
#build_auto_node ⇒ Object
Build the auto node (local site or supervisor to be tested).
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rsmp/validator/mode_detection.rb', line 71 def build_auto_node return unless auto_node_config if mode == :site self.auto_node = AutoSite.new elsif mode == :supervisor self.auto_node = AutoSupervisor.new else abort_with_error "Unknown test mode: #{mode}" end end |
#build_tester ⇒ Object
Build the tester instance.
60 61 62 63 64 65 66 67 68 |
# File 'lib/rsmp/validator/mode_detection.rb', line 60 def build_tester if mode == :site SiteTester.instance = SiteTester.new elsif mode == :supervisor SupervisorTester.instance = SupervisorTester.new else abort_with_error "Unknown test mode: #{mode}" end end |
#check_connection ⇒ Object
Initial connectivity check to verify we can connect to the site/supervisor being tested.
12 13 14 15 16 17 18 19 |
# File 'lib/rsmp/validator/mode_detection.rb', line 12 def check_connection log "Initial #{mode} connection check" if mode == :site SiteTester.instance.connected { nil } elsif mode == :supervisor SupervisorTester.instance.connected { nil } end end |
#determine_mode(sus_config) ⇒ Object
Determine mode from test file paths.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rsmp/validator/mode_detection.rb', line 37 def determine_mode(sus_config) paths = sus_config.paths.any? ? sus_config.paths : sus_config.test_paths site_dir = File.('test/site', sus_config.root) supervisor_dir = File.('test/supervisor', sus_config.root) paths.each do |path_str| = File.(path_str, sus_config.root) inferred = infer_mode_from_path(, site_dir, supervisor_dir) select_mode inferred if inferred end abort_with_error 'Could not determine test mode (site or supervisor) from test paths' unless mode end |
#infer_mode_from_path(path, site_dir, supervisor_dir) ⇒ Object
Determine the test mode from a single expanded path.
52 53 54 55 56 57 |
# File 'lib/rsmp/validator/mode_detection.rb', line 52 def infer_mode_from_path(path, site_dir, supervisor_dir) return :site if path == site_dir || path.start_with?("#{site_dir}/") return :supervisor if path == supervisor_dir || path.start_with?("#{supervisor_dir}/") nil end |
#select_mode(mode) ⇒ Object
Set whether we are testing a site or a supervisor.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rsmp/validator/mode_detection.rb', line 22 def select_mode(mode) if self.mode abort_with_error 'Cannot run tests in both test/site/ and test/supervisor/' if self.mode != mode return end case mode when :site, :supervisor self.mode = mode else abort_with_error "Unknown test mode: #{mode}" end end |