diff --git a/src/mad/ruby/test/OpenNebulaDriver_spec.rb b/src/mad/ruby/test/OpenNebulaDriver_spec.rb index 29ada40933..408b907337 100644 --- a/src/mad/ruby/test/OpenNebulaDriver_spec.rb +++ b/src/mad/ruby/test/OpenNebulaDriver_spec.rb @@ -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<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