Little refactoring of mcollective rspec test

This commit is contained in:
Mike Scherbakov 2012-10-02 17:46:30 +04:00
parent 44ed8ae253
commit ead633567b

View File

@ -3,32 +3,37 @@ require 'mcollective'
include MCollective::RPC
describe "MCollective" do
context "When MC agent is up and running" do
it "it should send echo message to MC agent and get it back" do
node = "admin"
data_to_send = "simple message of node '#{node}'"
mc = rpcclient("fake")
mc.progress = false
mc.discover(:nodes => [node])
stats = mc.echo(:msg => data_to_send)
stats.should have(1).items
stats[0].results[:statuscode].should eql(0)
stats[0].results[:data][:msg].should eql("Hello, it is my reply: #{data_to_send}")
end
context "When MC agent is up and running" do
it "it should send echo message to MC agent and get it back" do
node = "admin"
data_to_send = "simple message of node '#{node}'"
mc = rpcclient("fake")
mc.progress = false
mc.discover(:nodes => [node])
stats = mc.echo(:msg => data_to_send)
check_mcollective_result(stats)
stats[0].results[:data][:msg].should eql("Hello, it is my reply: #{data_to_send}")
end
it "it should update facts file with new key-value and could get it back" do
value_to_send = rand(2**30).to_s
node = "admin"
mc = rpcclient("nailyfact")
mc.progress = false
mc.discover(:nodes => [node])
stats = mc.put(:key => "role", :value => value_to_send)
stats.should have(1).items
stats[0].results[:statuscode].should eql(0)
stats = mc.get(:key => "role")
stats.should have(1).items
stats[0].results[:statuscode].should eql(0)
stats[0].results[:data][:value].should eql(value_to_send)
it "it should update facts file with new key-value and could get it back" do
value_to_send = rand(2**30).to_s
node = "admin"
mc = rpcclient("nailyfact")
mc.progress = false
mc.discover(:nodes => [node])
stats = mc.put(:key => "role", :value => value_to_send)
stats.should have(1).items
stats[0].results[:statuscode].should eql(0)
stats = mc.get(:key => "role")
check_mcollective_result(stats)
stats[0].results[:data][:value].should eql(value_to_send)
end
end
end
private
def check_mcollective_result(stats)
stats.should have(1).items
stats[0].results[:statuscode].should eql(0)
end