Class: XamarinTestCloud::CLI
- Inherits:
-
Thor
- Object
- Thor
- XamarinTestCloud::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/xamarin-test-cloud/cli.rb
Constant Summary collapse
- FILE_UPLOAD_ENDPOINT =
'upload2'
- FORM_URL_ENCODED_ENDPOINT =
'upload'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#app ⇒ Object
Returns the value of attribute app.
-
#appname ⇒ Object
Returns the value of attribute appname.
-
#async ⇒ Object
Returns the value of attribute async.
-
#async_json ⇒ Object
Returns the value of attribute async_json.
-
#config ⇒ Object
Returns the value of attribute config.
-
#device_selection ⇒ Object
Returns the value of attribute device_selection.
-
#dry_run ⇒ Object
Returns the value of attribute dry_run.
-
#endpoint_path ⇒ Object
Returns the value of attribute endpoint_path.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#pretty ⇒ Object
Returns the value of attribute pretty.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#profile ⇒ Object
Returns the value of attribute profile.
-
#series ⇒ Object
Returns the value of attribute series.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#skip_config_check ⇒ Object
Returns the value of attribute skip_config_check.
-
#test_parameters ⇒ Object
Returns the value of attribute test_parameters.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #submit(app, api_key) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/xamarin-test-cloud/cli.rb', line 46 def initialize(*args) self.session_id = SecureRandom.hex begin r = JSON.parse(http_post("check_version", {args: ARGV})) if r["error_message"] puts r["error_message"] exit 1 end rescue end super(*args) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def api_key @api_key end |
#app ⇒ Object
Returns the value of attribute app.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def app @app end |
#appname ⇒ Object
Returns the value of attribute appname.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def appname @appname end |
#async ⇒ Object
Returns the value of attribute async.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def async @async end |
#async_json ⇒ Object
Returns the value of attribute async_json.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def async_json @async_json end |
#config ⇒ Object
Returns the value of attribute config.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def config @config end |
#device_selection ⇒ Object
Returns the value of attribute device_selection.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def device_selection @device_selection end |
#dry_run ⇒ Object
Returns the value of attribute dry_run.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def dry_run @dry_run end |
#endpoint_path ⇒ Object
Returns the value of attribute endpoint_path.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def endpoint_path @endpoint_path end |
#locale ⇒ Object
Returns the value of attribute locale.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def locale @locale end |
#pretty ⇒ Object
Returns the value of attribute pretty.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def pretty @pretty end |
#priority ⇒ Object
Returns the value of attribute priority.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def priority @priority end |
#profile ⇒ Object
Returns the value of attribute profile.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def profile @profile end |
#series ⇒ Object
Returns the value of attribute series.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def series @series end |
#session_id ⇒ Object
Returns the value of attribute session_id.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def session_id @session_id end |
#skip_config_check ⇒ Object
Returns the value of attribute skip_config_check.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def skip_config_check @skip_config_check end |
#test_parameters ⇒ Object
Returns the value of attribute test_parameters.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def test_parameters @test_parameters end |
#user ⇒ Object
Returns the value of attribute user.
37 38 39 |
# File 'lib/xamarin-test-cloud/cli.rb', line 37 def user @user end |
Class Method Details
.exit_on_failure? ⇒ Boolean
42 43 44 |
# File 'lib/xamarin-test-cloud/cli.rb', line 42 def self.exit_on_failure? true end |
.source_root ⇒ Object
63 64 65 |
# File 'lib/xamarin-test-cloud/cli.rb', line 63 def self.source_root File.join(File.dirname(__FILE__), '..') end |
Instance Method Details
#submit(app, api_key) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/xamarin-test-cloud/cli.rb', line 159 def submit(app, api_key) self.pretty = [:pretty] self.async_json = ['async-json'] self.async = [:async] || self.async_json # Async mode wraps all console output in a json object # So we need to intercept all writes to $stdout if self.async_json @async_log = StringIO.new @async_result = { test_run_id: nil, error_messages: [], log: [] } $stdout = @async_log end app_path = File.(app) unless File.exist?(app_path) raise ValidationError, "App is not a file: #{app_path}" end if shared_runtime?(app_path) puts "Xamarin Test Cloud doesn't yet support shared runtime apps." puts "To test your app it needs to be compiled for release." puts "You can learn how to compile you app for release here:" puts "http://docs.xamarin.com/guides/android/deployment%2C_testing%2C_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release" # TODO Change this to: "Shared runtime apps are not supported." raise ValidationError, "Aborting" end app_extension = File.extname(app_path) unless /ipa/i.match(app_extension) || /apk/i.match(app_extension) raise ValidationError, "App #{app_path} must be an .ipa or .apk file" end self.app = app_path self.user = ['user'] self.dry_run = ['dry-run'] self.api_key = api_key self.test_parameters = ['test-parameters'] || {} self.appname = ['app-name'] self.device_selection = ['devices'] device_selection_data = validate_device_selection self.locale = ['locale'] self.series = ['series'] self.priority = ['priority'] self.skip_config_check = ['skip-config-check'] # Resolves the workspace and sets the @derived_workspace variable. expect_features_directory_in_workspace # TODO: extract this method and the configuration branch below to a module parse_and_set_config_and_profile unless self.skip_config_check default_config = File.join(derived_workspace, 'config', 'cucumber.yml') # TODO .config/cucumber.yml is valid # TODO cucumber.yaml is valid if File.exist?(default_config) && self.config.nil? # TODO Reword the header. log_header 'Warning: Detected cucumber.yml config file, but no --config specified' # TODO Reword the message and pass to raise as message. puts "Please specify --config #{default_config}" puts 'and specify a profile via --profile' puts 'If you know what you are doing you can skip this check with' puts '--skip-config-check' # TODO This error message is wrong. # It should be cucumber.yml detected by no --config option set. raise ValidationError, "#{default_config} detected but no profile selected." end end if Environment.debug? puts "Host = #{self.host}" puts "User = #{self.user}" puts "App = #{self.app}" puts "App Name = #{self.app}" puts "TestParams = #{self.test_parameters}" puts "API Key = #{self.api_key}" puts "Device Selection = #{self.device_selection}" puts "Workspace = #{derived_workspace}" puts "Config = #{self.config}" puts "Profile = #{self.profile}" puts "dSym = #{self.dsym}" end #Argument parsing done test_jon_data = submit_test_job(device_selection_data) if self.dry_run return end json = test_jon_data[:body] if Environment.debug? p json end warn_about_priority_flag() log_header('Test enqueued') puts "User: #{json['user_email']}" puts "Team: #{json['team']}" if json['team'] rejected_devices = json['rejected_devices'] if rejected_devices && rejected_devices.size > 0 # TODO Break this into multiple lines and remove the parenthetical puts 'Skipping devices (you can update your selections via https://testcloud.xamarin.com)' rejected_devices.each { |d| puts d } end puts '' puts 'Running on Devices:' json['devices'].each do |device| puts device end puts '' unless self.async wait_for_job(json['id']) else log 'Async mode: not awaiting test results' @async_result[:test_run_id] = json['id'] if self.async_json end rescue XamarinTestCloud::ValidationError => e if self.async_json @async_result[:error_messages] << e. else raise end ensure $stdout = STDOUT if self.async_json process_async_log puts @async_result.to_json end end |
#version ⇒ Object
69 70 71 |
# File 'lib/xamarin-test-cloud/cli.rb', line 69 def version puts XamarinTestCloud::VERSION end |