1#!/usr/bin/env rspec 2 3require 'spec_helper' 4require File.join(File.dirname(__FILE__), '../../', 'application', 'nrpe.rb') 5 6module MCollective 7 class Application 8 describe Nrpe do 9 before do 10 application_file = File.join(File.dirname(__FILE__), '../../', 'application', 'nrpe.rb') 11 @app = MCollective::Test::ApplicationTest.new('nrpe', :application_file => application_file).plugin 12 end 13 14 describe '#application_description' do 15 it 'should have a descrption set' do 16 @app.should have_a_description 17 end 18 end 19 20 describe '#validate_configuration' do 21 it 'should fail if a check name has not been specified' do 22 expect{ 23 @app.validate_configuration 24 }.to raise_error 25 end 26 end 27 28 describe '#main' do 29 let(:resultset) do 30 [{:data => {:exitcode => 0}, :statuscode => 0, :sender => 'rspec1', :statusmsg => 'ok'}, 31 {:data => {:exitcode => 1}, :statuscode => 0, :sender => 'rspec2', :statusmsg => 'ok'}, 32 {:data => {:exitcode => 2}, :statuscode => 0, :sender => 'rspec3', :statusmsg => 'ok'}, 33 {:data => {:exitcode => 3}, :statuscode => 0, :sender => 'rspec4', :statusmsg => 'ok'}, 34 {:data => {:exitcode => 1}, :statuscode => 0, :sender => 'rspec5', :statusmsg => 'ok'}] 35 end 36 37 let(:rpcclient) { mock } 38 39 before do 40 @app.expects(:rpcclient).returns(rpcclient) 41 @app.configuration[:command] = "rspec" 42 rpcclient.stubs(:stats).returns({:noresponsefrom => ['rspec']}) 43 @app.expects(:printrpcstats).with(:summarize => true, :caption => "rspec NRPE results") 44 end 45 46 it 'should run the command and output the results if verbose is set' do 47 rpcclient.expects(:runcommand).returns(resultset) 48 rpcclient.stubs(:verbose).returns(true) 49 @app.expects(:printf).with("%-40s status=%s\n", 'rspec1', 'ok') 50 @app.main 51 end 52 53 it 'should run the command and output the results if verbose is not set' do 54 rpcclient.expects(:runcommand).returns(resultset) 55 rpcclient.stubs(:verbose).returns(false) 56 @app.main 57 end 58 end 59 end 60 end 61end 62