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'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/xamarin-test-cloud/cli.rb', line 39

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.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def api_key
  @api_key
end

#appObject

Returns the value of attribute app.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def app
  @app
end

#appnameObject

Returns the value of attribute appname.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def appname
  @appname
end

#asyncObject

Returns the value of attribute async.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def async
  @async
end

#configObject

Returns the value of attribute config.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def config
  @config
end

#device_selectionObject

Returns the value of attribute device_selection.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def device_selection
  @device_selection
end

#dry_runObject

Returns the value of attribute dry_run.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def dry_run
  @dry_run
end

#dsymObject

Returns the value of attribute dsym.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def dsym
  @dsym
end

#endpoint_pathObject

Returns the value of attribute endpoint_path.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def endpoint_path
  @endpoint_path
end

#localeObject

Returns the value of attribute locale.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def locale
  @locale
end

#prettyObject

Returns the value of attribute pretty.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def pretty
  @pretty
end

#priorityObject

Returns the value of attribute priority.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def priority
  @priority
end

#profileObject

Returns the value of attribute profile.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def profile
  @profile
end

#seriesObject

Returns the value of attribute series.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def series
  @series
end

#session_idObject

Returns the value of attribute session_id.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def session_id
  @session_id
end

#skip_config_checkObject

Returns the value of attribute skip_config_check.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def skip_config_check
  @skip_config_check
end

#test_parametersObject

Returns the value of attribute test_parameters.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def test_parameters
  @test_parameters
end

#userObject

Returns the value of attribute user.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def user
  @user
end

#workspaceObject

Returns the value of attribute workspace.



29
30
31
# File 'lib/xamarin-test-cloud/cli.rb', line 29

def workspace
  @workspace
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/xamarin-test-cloud/cli.rb', line 35

def self.exit_on_failure?
  true
end

.source_rootObject



56
57
58
# File 'lib/xamarin-test-cloud/cli.rb', line 56

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

Instance Method Details

#submit(app, api_key) ⇒ Object



149
150
151
152
153
154
155
156
157
158
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
# File 'lib/xamarin-test-cloud/cli.rb', line 149

def submit(app, api_key)

  self.pretty = options[:pretty]

  app_path = File.expand_path(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"
    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 = options['user']

  self.async = options[:async]

  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.series = options['series']

  self.priority = options['priority']

  self.skip_config_check = options['skip-config-check']

  self.dsym= options['dsym-file']
  if dsym
    dsym_extension = File.extname(self.dsym)
    unless /dsym/i.match(dsym_extension) && File.directory?(dsym)
      raise ValidationError, "dsym-file must be a directory and have dSYM extension: #{dsym}"
    end
  end

  workspace_path = options[:workspace] || File.expand_path('.')

  unless File.directory?(workspace_path)
    raise ValidationError, "Provided workspace: #{workspace_path} is not a directory."
  end

  workspace_basename = File.basename(workspace_path)
  if workspace_basename.downcase == 'features'
    self.workspace = File.expand_path(File.join(workspace_path,'..'))
    puts "Deriving workspace #{self.workspace} from features folder #{workspace_basename}"
  else
    self.workspace = File.expand_path(workspace_path)
  end

  self.workspace = File.join(self.workspace, File::Separator)


  unless File.directory?(File.join(self.workspace, 'features'))
    log_header "Did not find features folder in workspace #{self.workspace}"
    puts "Either run the test-cloud command from the directory containing your features"
    puts "or use the --workspace option to refer to this directory"
    puts "See also test-cloud help submit"
    raise ValidationError, "Unable to find features folder in #{self.workspace}"
  end

  parse_and_set_config_and_profile
  unless self.skip_config_check
    default_config = File.join(self.workspace,'config','cucumber.yml')
    if File.exist?(default_config) && self.config.nil?
      log_header 'Warning: Detected cucumber.yml config file, but no --config specified'
      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'
      raise ValidationError, "#{default_config} detected but no profile selected."
    end
  end

  if 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 = #{self.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 debug?
    p json
  end

  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
    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'
  end

end

#versionObject



62
63
64
# File 'lib/xamarin-test-cloud/cli.rb', line 62

def version
  puts XamarinTestCloud::VERSION
end