Class: Loadimpact::TestConfig

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

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Public: Initialize a TestConfig.

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

:id - The Integer id of the TestConfig (required).
:user_scenario_id - The Integer id of the UserScenario (required).
:name - The String name of the TestConfig (required).
:url - The String target url of the TestConfig (required).
:config - The Hash config of the TestConfig (required).


19
20
21
22
23
24
25
26
# File 'lib/loadimpact/test_config.rb', line 19

def initialize(client, options = {})
  @client = client
  @id = options["id"]
  @user_scenario_id = options["config"]["tracks"][0]["clips"][0]["user_scenario_id"]
  @name = options["name"]
  @url = options["url"]
  @config = options["config"]["load_schedule"][0]
end

Instance Attribute Details

#idObject (readonly)

Public: Returns the Integer id of the TestConfig.



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

def id
  @id
end

#user_scenario_idObject

Public: Gets/Sets the Integer id of the UserScenario.



8
9
10
# File 'lib/loadimpact/test_config.rb', line 8

def user_scenario_id
  @user_scenario_id
end

Instance Method Details

#clone(new_name) ⇒ Object

Public: Clone TestConfig and give it a new name.

new_name - The String new name of cloned TestConfig.

Examples

cloned_test_config = test_config.clone("My cloned test configuration")
# => #<Loadimpact::TestConfig>

Returns TestConfig object if successfully cloned. Raises LoadimpactError if invalid HTTP request.

Raises:



96
97
98
99
100
101
# File 'lib/loadimpact/test_config.rb', line 96

def clone(new_name)
  res = @client.post("/test-configs/#{@id}/clone", body: { name: new_name }.to_json)
  raise LoadimpactError.new(res["message"]) if res.key?("message")
  hsh = JSON.parse(res.body)
  TestConfig.new(@client, hsh)
end

#deleteObject

Public: Delete TestConfig.

Examples

test_config.delete
# => 204

Returns HTTP status code 204 if successfully deleted. Raises LoadimpactError if invalid HTTP request.

Raises:



79
80
81
82
83
# File 'lib/loadimpact/test_config.rb', line 79

def delete
  res = @client.delete("/test-configs/#{@id}")
  raise LoadimpactError.new(res["message"]) if res.key?("message")
  res.code
end

#infoObject

Public: Retrieve TestConfig information.

Examples

test_config.info
# => {"id"=>12345, "name"=>"My test configuration", # omitted }

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

Raises:



37
38
39
40
41
# File 'lib/loadimpact/test_config.rb', line 37

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

#startObject

Public: Start a Test based on the specified TestConfig.

Examples

test_config.start
# => #<Loadimpact::Test>

Returns Test object if successfully started. Raises LoadimpactError if invalid HTTP request. Raises NoConcurrentTestsError if another Test is running.



113
114
115
116
117
118
119
120
121
122
# File 'lib/loadimpact/test_config.rb', line 113

def start
  res = @client.post("/test-configs/#{@id}/start")
  if res.code == 500
    raise NoConcurrentTestsError.new
  elsif res.key?("message")
    raise LoadimpactError.new(res["message"])
  end
  hsh = JSON.parse(res.body)
  Test.new(@client, hsh)
end

#update(options = {}) ⇒ Object

Public: Update TestConfig.

options - The Hash options used to update the TestConfig:

:user_scenario_id - The Integer id of the UserScenario (optional).
:name - The String name of the TestConfig (optional).
:url - The String target url of the TestConfig (optional).
:config - The Hash config of the TestConfig (optional).

Examples

my_config = { users: 5, duration: 2 }
test_config.update(
name: "My updated test configuration",
url: "http://google.com",
config: my_config)
# => 200

Returns HTTP status code 200 if successfully updated. Raises LoadimpactError if invalid HTTP request. Raises InvalidDataStoreError if invalid data store.

Raises:



63
64
65
66
67
68
# File 'lib/loadimpact/test_config.rb', line 63

def update(options = {})
  test_config_builder(options)
  res = @client.put("/test-configs/#{@id}", body: payload)
  raise LoadimpactError.new(res["message"]) if res.key?("message")
  res.code
end