Class: Testcube::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/testcube/report.rb

Constant Summary collapse

UPLOAD_START_URL =
"https://us-central1-testcube.cloudfunctions.net/startUpload"

Class Method Summary collapse

Class Method Details

.save(api_key) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/testcube/report.rb', line 8

def self.save(api_key)
  test_files = Testcube.tracker.test_files_with_time

  if test_files.empty?
    Testcube.logger.warn("No test files were executed")
  end

  upload_results(test_files, Testcube::BuildEnv.current, api_key)
end

.upload_results(test_files, build_env, api_key) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/testcube/report.rb', line 18

def self.upload_results(test_files, build_env, api_key)
  content = JSON.generate({ results: test_files, build_env: build_env })

  # get upload url
  start = Time.now
  res = HTTP.post(UPLOAD_START_URL, headers: { 'X-TESTCUBE-API-KEY' => api_key })
  Testcube.logger.debug("uploadStart: #{Time.now - start}")

  upload_url = nil
  if res.status.success?
    upload_url = JSON.parse(res.body.to_s)['uploadURL']
  else
    Testcube.logger.warn("Failed to upload to testcube!")
    return
  end

  start = Time.now
  res = HTTP.put(upload_url, body: content)
  Testcube.logger.debug("resultsUpload: #{Time.now - start}")

  if res.status.success?
    Testcube.logger.info("Successfully uploaded results!")
  else
    Testcube.logger.warn("Failed to upload to testcube!")
    return
  end
end