Class: Hiptest::CliOptionsChecker
- Inherits:
-
Object
- Object
- Hiptest::CliOptionsChecker
- Defined in:
- lib/hiptest-publisher/cli_options_checker.rb
Instance Attribute Summary collapse
-
#cli_options ⇒ Object
readonly
Returns the value of attribute cli_options.
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
Instance Method Summary collapse
- #check! ⇒ Object
- #check_actionwords_signature_file ⇒ Object
- #check_build_options ⇒ Object
- #check_config_file ⇒ Object
- #check_execution_environment ⇒ Object
- #check_filters ⇒ Object
- #check_language_and_only ⇒ Object
- #check_meta ⇒ Object
- #check_numeric_list(option_name) ⇒ Object
- #check_output_directory ⇒ Object
- #check_push_file ⇒ Object
- #check_secret_token ⇒ Object
- #check_status_filter ⇒ Object
- #check_tag_list(option_name) ⇒ Object
- #check_test_run_id ⇒ Object
- #check_xml_file ⇒ Object
-
#initialize(cli_options, reporter) ⇒ CliOptionsChecker
constructor
A new instance of CliOptionsChecker.
Constructor Details
#initialize(cli_options, reporter) ⇒ CliOptionsChecker
Returns a new instance of CliOptionsChecker.
12 13 14 15 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 12 def initialize(, reporter) @cli_options = @reporter = reporter end |
Instance Attribute Details
#cli_options ⇒ Object (readonly)
Returns the value of attribute cli_options.
11 12 13 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 11 def @cli_options end |
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
11 12 13 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 11 def reporter @reporter end |
Instance Method Details
#check! ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 17 def check! check_config_file if .only == 'list' return end check_secret_token check_filters check_status_filter if .push? check_execution_environment check_push_file else check_output_directory check_actionwords_signature_file check_xml_file check_test_run_id check_language_and_only end end |
#check_actionwords_signature_file ⇒ Object
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 135 def check_actionwords_signature_file if .actionwords_diff? actionwords_signature_file = Pathname.new(.output_directory).join("actionwords_signature.yaml") if actionwords_signature_file.directory? raise CliOptionError, I18n.t('errors.cli_options.actionwords_signature_directory', path: actionwords_signature_file.realpath) elsif !actionwords_signature_file.exist? raise CliOptionError, I18n.t('errors.cli_options.missing_actionwords_signature_file', directory_path: File.(.output_directory)) end end end |
#check_build_options ⇒ Object
217 218 219 220 221 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 217 def if present?(.build_id) && present?(.build_name) raise CliOptionError, I18n.t('errors.cli_options.multiple_build_options') end end |
#check_config_file ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 42 def check_config_file begin ParseConfig.new(.config) if present?(.config) rescue Errno::EACCES => err raise CliOptionError, I18n.t('errors.cli_options.missing_config_file', config_file: .config) end end |
#check_execution_environment ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 111 def check_execution_environment if .execution_environment if .execution_environment.length > 255 raise CliOptionError, I18n.t('errors.cli_options.invalid_execution_environment') end end end |
#check_filters ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 50 def check_filters filters = [ .filter_on_scenario_ids, .filter_on_folder_ids, .filter_on_scenario_name, .filter_on_folder_name, . ].reject {|opt| absent?(opt) } return if filters.empty? if filters.size > 1 raise CliOptionError, I18n.t('errors.cli_options.multiple_filters') end if present?(.test_run_id) || present?(.test_run_name) raise CliOptionError, I18n.t('errors.cli_options.filter_with_test_run') end check_numeric_list(:filter_on_scenario_ids) check_numeric_list(:filter_on_folder_ids) check_tag_list(:filter_on_tags) end |
#check_language_and_only ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 194 def check_language_and_only if present?(.language) begin language_config_parser = LanguageConfigParser.new() rescue ArgumentError => err raise CliOptionError, err. end if present?(.only) if language_config_parser.filtered_group_names != .groups_to_keep unknown_categories = .groups_to_keep - language_config_parser.group_names raise CliOptionError, I18n.t( 'errors.cli_options.invalid_category', count: unknown_categories.length, invalid_categories: formatted_categories(unknown_categories), available_categories: formatted_categories(language_config_parser.group_names), language: .language_framework ) end end end end |
#check_meta ⇒ Object
184 185 186 187 188 189 190 191 192 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 184 def value = . return if absent?(value) value.split(',').each do |val| next if (val.strip) raise CliOptionError, I18n.t('errors.cli_options.invalid_meta', incorrect_value: val.strip.inspect) end end |
#check_numeric_list(option_name) ⇒ Object
164 165 166 167 168 169 170 171 172 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 164 def check_numeric_list(option_name) value = .send(option_name) return if absent?(value) value.split(',').each do |val| next if numeric?(val.strip) raise CliOptionError, I18n.t('errors.cli_options.invalid_numeric_value_list', option: option_name, incorrect_value: val.strip.inspect) end end |
#check_output_directory ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 119 def check_output_directory output_directory = clean_path(.output_directory) parent = first_existing_parent(output_directory) if !parent.writable? if parent.realpath === Pathname.new(.output_directory).cleanpath raise CliOptionError, I18n.t('errors.cli_options.output_directory_not_writable', output_dir: .output_directory) else raise CliOptionError, I18n.t('errors.cli_options.output_directory_parent_not_writable', realpath: parent.realpath, output_dir: .output_directory) end elsif !parent.directory? raise CliOptionError, I18n.t('errors.cli_options.output_directory_not_directory', output_dir: .output_directory) end end |
#check_push_file ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 94 def check_push_file if .push && !.global_failure_on_missing_reports agnostic_path = clean_path(.push) globbed_files = Dir.glob(agnostic_path) if globbed_files.length == 0 raise CliOptionError, I18n.t('errors.cli_options.unreadable_report_file', path: .push) elsif globbed_files.length == 1 && globbed_files == [.push] if !File.readable?(agnostic_path) raise CliOptionError, I18n.t('errors.cli_options.unreadable_report_file', path: .push) elsif !File.file?(agnostic_path) raise CliOptionError, I18n.t('errors.cli_options.irregular_report_file', path: .push) end end end end |
#check_secret_token ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 82 def check_secret_token if absent?(.xml_file) if absent?(.token) raise CliOptionError, I18n.t('errors.cli_options.missing_token') end unless numeric?(.token) raise CliOptionError, I18n.t('errors.cli_options.invalid_token', token: .token) end end end |
#check_status_filter ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 74 def check_status_filter return if absent?(.filter_on_status) if absent?(.test_run_id) && absent?(.test_run_name) raise CliOptionError, I18n.t('errors.cli_options.filter_status_without_test_run') end end |
#check_tag_list(option_name) ⇒ Object
174 175 176 177 178 179 180 181 182 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 174 def check_tag_list(option_name) value = .send(option_name) return if absent?(value) value.split(',').each do |val| next if tag_compatible?(val.strip) raise CliOptionError, I18n.t('errors.cli_options.invalid_tag_value_list', option: option_name, incorrect_value: val.strip.inspect) end end |
#check_test_run_id ⇒ Object
158 159 160 161 162 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 158 def check_test_run_id if present?(.test_run_id) && !numeric?(.test_run_id) raise CliOptionError, I18n.t('errors.cli_options.invalid_test_run_id', test_run_id: .test_run_id) end end |
#check_xml_file ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/hiptest-publisher/cli_options_checker.rb', line 146 def check_xml_file if .xml_file xml_path = clean_path(.xml_file) if !File.readable?(xml_path) raise CliOptionError, I18n.t('errors.cli_options.unreadable_xml_file', path: .xml_file) elsif !File.file?(xml_path) raise CliOptionError, I18n.t('errors.cli_options.irregular_xml_file', path: .xml_file) end end end |