Class: XamarinTestCloud::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/xamarin-test-cloud/cli.rb

Constant Summary collapse

FILE_UPLOAD_ENDPOINT =
'upload2'
FORM_URL_ENCODED_ENDPOINT =
'upload'
MANIFEST_SCHEMA_VERSION =
"1.0.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/xamarin-test-cloud/cli.rb', line 50

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_keyObject

Returns the value of attribute api_key.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def api_key
  @api_key
end

#appObject

Returns the value of attribute app.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def app
  @app
end

#appnameObject

Returns the value of attribute appname.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def appname
  @appname
end

#asyncObject

Returns the value of attribute async.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def async
  @async
end

#async_jsonObject

Returns the value of attribute async_json.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def async_json
  @async_json
end

#configObject

Returns the value of attribute config.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def config
  @config
end

#device_selectionObject

Returns the value of attribute device_selection.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def device_selection
  @device_selection
end

#dry_runObject

Returns the value of attribute dry_run.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def dry_run
  @dry_run
end

#endpoint_pathObject

Returns the value of attribute endpoint_path.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def endpoint_path
  @endpoint_path
end

#include_files_inputObject

Returns the value of attribute include_files_input.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def include_files_input
  @include_files_input
end

#included_files_mapObject (readonly)

Returns the value of attribute included_files_map.



44
45
46
# File 'lib/xamarin-test-cloud/cli.rb', line 44

def included_files_map
  @included_files_map
end

#languageObject

Returns the value of attribute language.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def language
  @language
end

#localeObject

Returns the value of attribute locale.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def locale
  @locale
end

#prettyObject

Returns the value of attribute pretty.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def pretty
  @pretty
end

#priorityObject

Returns the value of attribute priority.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def priority
  @priority
end

#profileObject

Returns the value of attribute profile.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def profile
  @profile
end

#seriesObject

Returns the value of attribute series.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def series
  @series
end

#session_idObject

Returns the value of attribute session_id.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def session_id
  @session_id
end

#skip_config_checkObject

Returns the value of attribute skip_config_check.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def skip_config_check
  @skip_config_check
end

#test_parametersObject

Returns the value of attribute test_parameters.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def test_parameters
  @test_parameters
end

#userObject

Returns the value of attribute user.



38
39
40
# File 'lib/xamarin-test-cloud/cli.rb', line 38

def user
  @user
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/xamarin-test-cloud/cli.rb', line 46

def self.exit_on_failure?
  true
end

.source_rootObject



68
69
70
# File 'lib/xamarin-test-cloud/cli.rb', line 68

def self.source_root
  File.join(File.dirname(__FILE__), '..')
end

Instance Method Details

#prepare(app) ⇒ Object



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/xamarin-test-cloud/cli.rb', line 344

def prepare(app)
  @include_files_input = options[:include]
  artifact_directory = File.expand_path(options["artifacts-dir"])

  # Validates and sets the @app instance variable.
  verify_app!(app)

  # Resolves the workspace and sets the @derived_workspace variable.
  expect_features_directory_in_workspace

  # Verifies the --config and --profile options and sets these variables:
  # @config, @profile, @skip_config_check
  verify_cucumber_config_and_profile!

  require "xamarin-test-cloud/tmpdir"
  bundle_package_dir = XamarinTestCloud::TmpDir.mktmpdir

  stage_gemfile_and_bundle_package(bundle_package_dir)

  files = collect_test_suite_files(bundle_package_dir)

  FileUtils.mkdir_p(artifact_directory)
  manifest_file = File.join(artifact_directory, "manifest.json")

  log_header("Preparing the Artifact Directory")
  test_parameters = options["test-parameters"]
  test_parameters["profile"] = options[:profile] if options[:profile]

  manifest = generate_manifest_hash(files, test_parameters)
  write_manifest_to_file(manifest, manifest_file)

  puts ""
  puts "Copied files to:"
  puts "  #{File.expand_path(artifact_directory)}"
  puts ""
  puts "Wrote upload manifest to:"
  puts "  #{File.expand_path(manifest_file)}"

  files.each do |test_file|
    target = File.join(artifact_directory, test_file.remote_path)
    basedir = File.dirname(target)
    FileUtils.mkdir_p(basedir)
    FileUtils.cp(test_file.path, target)
  end

end

#submit(app, api_key) ⇒ Object



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
# File 'lib/xamarin-test-cloud/cli.rb', line 177

def submit(app, api_key)

  self.pretty = options[:pretty]
  self.async_json = options['async-json']
  self.async = options[: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

  # Verifies the app argument and sets the @app instance variable
  verify_app!(app)

  self.user = options['user']

  self.dry_run = options['dry-run']

  self.api_key = api_key

  self.test_parameters = options['test-parameters'] || {}

  self.appname = options['app-name']

  self.device_selection = options['devices']

  device_selection_data = validate_device_selection

  self.locale = options['locale']

  self.language = options['language']

  self.series = options['series']

  self.priority = options['priority']


  self.include_files_input = options['include']

  # Resolves the workspace and sets the @derived_workspace variable.
  expect_features_directory_in_workspace

  # Verifies the --config and --profile options and sets these variables:
  # @config, @profile, @skip_config_check
  verify_cucumber_config_and_profile!

  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}"
    puts "Include = #{included_files_map}"
    puts "Locale = #{self.locale}"
    puts "Language = #{self.language}"
  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(options)

  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.message
  else
    raise
  end

ensure
  $stdout = STDOUT
  if self.async_json
    process_async_log
    puts @async_result.to_json
  end
end

#versionObject



74
75
76
# File 'lib/xamarin-test-cloud/cli.rb', line 74

def version
  puts XamarinTestCloud::VERSION
end