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, :version, :url, :target],
                            :optional => [:hive_job_id],
                            :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
# 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)
  net = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Post.new("/api/v1/submit")
  request.set_form_data({"data" => ir.to_json})
  net.read_timeout = 60
  net.open_timeout = 10
  
  response = net.start do |http|
    http.request(request)
  end
  
  response.read_body
end