1#!/usr/bin/env rspec 2 3require 'spec_helper' 4require File.join(File.dirname(__FILE__), '../../', 'data', 'service_data.rb') 5require File.join(File.dirname(__FILE__), '../../', 'agent', 'service.rb') 6 7module MCollective 8 module Data 9 describe Service_data do 10 describe '#query_data' do 11 let(:plugin){Service_data.new} 12 13 before do 14 @ddl = mock('ddl') 15 @ddl.stubs(:dataquery_interface).returns({:output => {}}) 16 @ddl.stubs(:meta).returns({:timeout => 1}) 17 DDL.stubs(:new).returns(@ddl) 18 end 19 20 it 'should show running if the service is running' do 21 Agent::Service.expects(:do_service_action).with('status', 'rspec').returns('running') 22 plugin.query_data('rspec').should == 'running' 23 end 24 25 it 'should show stopped if the service is stopped' do 26 Agent::Service.expects(:do_service_action).with('status', 'rspec').returns('stopped') 27 plugin.query_data('rspec').should == 'stopped' 28 end 29 30 it 'should display an error message if agent status cannot be determined' do 31 Agent::Service.expects(:do_service_action).with('status', 'rspec').raises('error') 32 MCollective::Log.expects(:warn).with("Could not get status for service rspec: error") 33 plugin.query_data('rspec') 34 end 35 end 36 end 37 end 38end 39