mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-23 22:50:09 +03:00
feature #595: tests for OpenNebulaDriver local_action and log
This commit is contained in:
parent
4c124e45fd
commit
b659e39942
@ -224,5 +224,78 @@ describe OpenNebulaDriver do
|
||||
]
|
||||
end
|
||||
|
||||
it 'should execute local actions' do
|
||||
result=[] # here will be the parameters to send_message
|
||||
time=0 # this will count the executions of LocalCommand
|
||||
|
||||
driver=create_driver(*@create_params)
|
||||
|
||||
MonkeyPatcher.patch do
|
||||
# patch send_message
|
||||
patch_class(IO, :puts) do |*args|
|
||||
result<<args[0]
|
||||
end
|
||||
|
||||
patch_class(LocalCommand, :execute) do
|
||||
time+=1
|
||||
case time
|
||||
when 1 # Everything goes ok (Test 1)
|
||||
fake_execution('command info', 'ExitCode: 0')
|
||||
when 2 # Command fails (Test 2)
|
||||
fake_execution('', '
|
||||
ERROR MESSAGE --8<------
|
||||
the error message
|
||||
ERROR MESSAGE ------>8--
|
||||
ExitCode: 255')
|
||||
else
|
||||
puts "should not reach here"
|
||||
fake_execution('command info', 'ExitCode: 0')
|
||||
end
|
||||
end
|
||||
|
||||
# Test 1 - OK
|
||||
driver.local_action('command', 0, :DEPLOY)
|
||||
|
||||
# Test 2 - Error
|
||||
driver.local_action('command', 0, :DEPLOY)
|
||||
|
||||
end
|
||||
|
||||
result.should == [
|
||||
"LOG I 0 ExitCode: 0", "DEPLOY SUCCESS 0 command info",
|
||||
"LOG I 0 Command execution fail: command",
|
||||
"LOG E 0 the error message",
|
||||
"LOG I 0 ExitCode: 255", "DEPLOY FAILURE 0 the error message"
|
||||
]
|
||||
end
|
||||
|
||||
it "should correctly parse log lines" do
|
||||
tests=[
|
||||
[
|
||||
"ERROR MESSAGE --8<------\nerror message\n"<<
|
||||
"ERROR MESSAGE ------>8--\n",
|
||||
['LOG', 'E', 0, 'error message']
|
||||
],
|
||||
['ERROR: error message', ['LOG', 'E', 0, 'error message']],
|
||||
['DEBUG: debug message', ['LOG', 'D', 0, 'debug message']],
|
||||
['INFO: info message', ['LOG', 'I', 0, 'info message']],
|
||||
['info message', ['LOG', 'I', 0, 'info message']]
|
||||
]
|
||||
|
||||
driver=create_driver(*@create_params)
|
||||
result=''
|
||||
|
||||
MonkeyPatcher.patch do
|
||||
patch_class(OpenNebulaDriver, :send_message) do |*args|
|
||||
result=args
|
||||
end
|
||||
|
||||
tests.each do |test|
|
||||
driver.log(0, test[0])
|
||||
result.should == test[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user