Project

General

Profile

« Previous | Next » 

Revision 6e7af6fc

Added by Dominic Cleal almost 8 years ago

fixes #15573 - support rest-client 2.x

Add a test helper that understands how to create fake responses for both
supported 1.8 and 2.x versions.

View differences:

test/lib/proxy_api/bmc_test.rb
require "mocha/setup"
class ProxyApiBmcTest < ActiveSupport::TestCase
# Called before every test method runs. Can be used
# to set up fixture information.
def setup
@url="http://localhost:8443"
@options = {:username => "testuser", :password => "fakepass"}
@testbmc = ProxyAPI::BMC.new({:user => "admin", :password => "secretpass", :url => @url})
end
# Called after every test method runs. Can be used to tear
# down fixture information.
def teardown
# Do nothing
end
def fake_response(data)
net_http_resp = Net::HTTPResponse.new(1.0, 200, "OK")
net_http_resp.add_field 'Set-Cookie', 'Monster'
RestClient::Response.create(JSON(data), net_http_resp, nil, RestClient::Request.new(:method=>'get', :url=>'http://localhost:8443'))
end
test "constructor should complete" do
assert_not_nil(@testbmc)
end
......
test "providers should get list of providers" do
expected = ["freeipmi", "ipmitool"]
@testbmc.stubs(:get).returns(fake_response(expected))
@testbmc.stubs(:get).returns(fake_rest_client_response(expected))
assert_equal(expected, @testbmc.providers)
end
test "providers installed should get list of installed providers" do
expected = ["freeipmi", "ipmitool"]
@testbmc.stubs(:get).returns(fake_response(expected))
@testbmc.stubs(:get).returns(fake_rest_client_response(expected))
assert_equal(expected, @testbmc.providers_installed)
end
......
end
test "boot function should not raise nomethod exception when function does exist" do
@testbmc.stubs(:put).returns(fake_response(["fakedata"]))
@testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
@testbmc.boot_pxe(@options)
end
......
device = "pxe"
expected_path = "/127.0.0.1/chassis/config/bootdevice/#{device}"
data = @options.merge({:function => "bootdevice", :device => device})
@testbmc.stubs(:put).returns(fake_response(["fakedata"]))
@testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:put).with(data, expected_path).at_least_once
@testbmc.boot_pxe(@options)
end
......
device = "disk"
expected_path = "/127.0.0.1/chassis/config/bootdevice/#{device}"
data = @options.merge({:function => "bootdevice", :device => device})
@testbmc.stubs(:put).returns(fake_response(["fakedata"]))
@testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:put).with(data, expected_path).at_least_once
@testbmc.boot_disk(@options)
end
......
device = "cdrom"
expected_path = "/127.0.0.1/chassis/config/bootdevice/#{device}"
data = @options.merge({:function => "bootdevice", :device => device})
@testbmc.stubs(:put).returns(fake_response(["fakedata"]))
@testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:put).with(data, expected_path).at_least_once
@testbmc.boot_cdrom(@options)
end
......
device = "bios"
expected_path = "/127.0.0.1/chassis/config/bootdevice/#{device}"
data = @options.merge({:function => "bootdevice", :device => device})
@testbmc.stubs(:put).returns(fake_response(["fakedata"]))
@testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:put).with(data, expected_path).at_least_once
@testbmc.boot_bios(@options)
end
......
action = "off"
expected_path = "/127.0.0.1/chassis/power/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:put).returns(fake_response(["fakedata"]))
@testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:put).with(data, expected_path).at_least_once
@testbmc.power_off(@options)
end
......
action = "on"
expected_path = "/127.0.0.1/chassis/power/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:put).returns(fake_response(["fakedata"]))
@testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:put).with(data, expected_path).at_least_once
@testbmc.power_on(@options)
end
......
action = "cycle"
expected_path = "/127.0.0.1/chassis/power/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:put).returns(fake_response(["fakedata"]))
@testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:put).with(data, expected_path).at_least_once
@testbmc.power_cycle(@options)
end
......
action = "soft"
expected_path = "/127.0.0.1/chassis/power/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:put).returns(fake_response({"result" => true}))
@testbmc.stubs(:put).returns(fake_rest_client_response({"result" => true}))
@testbmc.expects(:put).with(data, expected_path).at_least_once
@testbmc.power_soft(@options)
end
......
action = "off"
expected_path = "/127.0.0.1/chassis/power/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:get).returns(fake_response(["fakedata"]))
@testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:get).with(expected_path, data).at_least_once
@testbmc.power_off?(@options)
end
......
action = "on"
expected_path = "/127.0.0.1/chassis/power/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:get).returns(fake_response(["fakedata"]))
@testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:get).with(expected_path, data).at_least_once
@testbmc.power_on?(@options)
end
......
action = "status"
expected_path = "/127.0.0.1/chassis/power/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:get).returns(fake_response(["fakedata"]))
@testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:get).with(expected_path, data).at_least_once
@testbmc.power_status(@options)
end
......
action = "off"
expected_path = "/127.0.0.1/chassis/identify/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:put).returns(fake_response(["fakedata"]))
@testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:put).with(data, expected_path).at_least_once
@testbmc.identify_off(@options)
end
......
action = "on"
expected_path = "/127.0.0.1/chassis/identify/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:put).returns(fake_response(["fakedata"]))
@testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:put).with(data, expected_path).at_least_once
@testbmc.identify_on(@options)
end
......
action = "status"
expected_path = "/127.0.0.1/chassis/identify/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:get).returns(fake_response(["fakedata"]))
@testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:get).with(expected_path, data).at_least_once
@testbmc.identify_status(@options)
end
......
action = "ip"
expected_path = "/127.0.0.1/lan/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:get).returns(fake_response(["fakedata"]))
@testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:get).with(expected_path, data).at_least_once
@testbmc.lan_ip(@options)
end
......
action = "netmask"
expected_path = "/127.0.0.1/lan/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:get).returns(fake_response(["fakedata"]))
@testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:get).with(expected_path, data).at_least_once
@testbmc.lan_netmask(@options)
end
......
action = "gateway"
expected_path = "/127.0.0.1/lan/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:get).returns(fake_response(["fakedata"]))
@testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:get).with(expected_path, data).at_least_once
@testbmc.lan_gateway(@options)
end
......
action = "mac"
expected_path = "/127.0.0.1/lan/#{action}"
data = @options.merge({:action => action})
@testbmc.stubs(:get).returns(fake_response(["fakedata"]))
@testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
@testbmc.expects(:get).with(expected_path, data).at_least_once
@testbmc.lan_mac(@options)
end

Also available in: Unified diff