Class: Res::Reporters::Testmine

Inherits:
Object
  • Object
show all
Defined in:
lib/res/reporters/testmine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Testmine

Returns a new instance of Testmine.



9
10
11
12
13
14
15
# File 'lib/res/reporters/testmine.rb', line 9

def initialize(args)
  @url = args[:url]
  @config = Res::Config.new([:project, :component, :suite, :url, :target, :version],
                            :optional => [:hive_job_id, :cert, :cacert, :ssl_verify_mode],
                            :pre_env  => 'TESTMINE_')
  config.process(args)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/res/reporters/testmine.rb', line 7

def config
  @config
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/res/reporters/testmine.rb', line 7

def url
  @url
end

Instance Method Details

#submit_results(ir, args = nil) ⇒ 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
41
42
43
44
45
46
47
48
49
# File 'lib/res/reporters/testmine.rb', line 17

def submit_results(ir, args = nil)
  # Set missing project information
  ir.project     = config.project
  ir.suite       = config.suite
  ir.target      = config.target
  ir.hive_job_id = config.hive_job_id 
  
  # Load world information into json hash
  ir.world = {
    :project   => @config.project,
    :component => @config.component,
    :version   => @config.version,
  }

  # Submit to testmine

  uri = URI.parse(config.url)
  @http = Net::HTTP.new(uri.host, uri.port)
  if config.cert
    pem = File.read(config.cert)
    @http.use_ssl = true if uri.scheme == 'https'
    @http.cert = OpenSSL::X509::Certificate.new(pem)
    @http.key = OpenSSL::PKey::RSA.new(pem)
    @http.ca_file = config.cacert if config.cacert
    @http.verify_mode = config.ssl_verify_mode if config.ssl_verify_mode
  end
  
  request = Net::HTTP::Post.new(config.url + "/api/v1/submit")
  request.content_type = 'application/json'
  request.set_form_data({"data" => ir.to_json})
  response = @http.request(request)
  response.body
end