Class: Loadimpact::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/loadimpact/test.rb

Overview

Public: Various methods useful for managing a user's Tests. All methods are instance methods and should be called on the Test object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, options = {}) ⇒ Test

Public: Initialize a Test.

client - A Client object. options - The Hash options used to initialize the Test:

:id - The Integer id of the Test (required).


13
14
15
16
# File 'lib/loadimpact/test.rb', line 13

def initialize(client, options = {})
  @client = client
  @id = options["id"]
end

Instance Attribute Details

#idObject (readonly)

Public: Returns the Integer id of the Test.



6
7
8
# File 'lib/loadimpact/test.rb', line 6

def id
  @id
end

Instance Method Details

#abortObject

Public: Abort Test.

Examples

test.abort
# => 204

Returns HTTP status code 204 if successfully aborted. Raises LoadimpactError if invalid HTTP request. Raises TestInvalidStateError if Test is in a state where it can't be aborted.



43
44
45
46
47
48
49
50
51
# File 'lib/loadimpact/test.rb', line 43

def abort
  res = @client.post("/tests/#{@id}/abort")
  if res.code == 409
    raise TestInvalidStateError.new
  elsif res.key?("message")
    raise LoadimpactError.new(res["message"])
  end
  res.code
end

#infoObject

Public: Retrieve Test information.

Examples

test.info
# => {"id"=>12345, "status_text"=>"Running", # omitted }

Returns Hash of Test information. Raises LoadimpactError if invalid HTTP request.

Raises:



27
28
29
30
31
# File 'lib/loadimpact/test.rb', line 27

def info
  res = @client.get("/tests/#{@id}")
  raise LoadimpactError.new(res["message"]) if res.key?("message")
  JSON.parse(res.body)
end