1#!/usr/bin/env rspec
2
3require 'spec_helper'
4require File.join(File.dirname(__FILE__), "../../", "data", "nrpe_data")
5require File.join(File.dirname(__FILE__), "../../", "agent", "nrpe")
6
7module MCollective
8  module Data
9    describe "#query_data" do
10      before do
11        @ddl = mock('ddl')
12        @ddl.stubs(:dataquery_interface).returns({:output => {}})
13        @ddl.stubs(:meta).returns({:timeout => 1})
14        DDL.stubs(:new).returns(@ddl)
15      end
16
17      it "should return the correct exit code" do
18        MCollective::Agent::Nrpe.expects(:plugin_for_command).returns({:cmd => "test_command"})
19        MCollective::Agent::Nrpe.expects(:run).returns(0, "")
20        plugin = Nrpe_data.new
21        plugin.query_data("test_command")
22        plugin.result.exitcode.should == 0
23      end
24
25      it "should return unknown if the command cannot be found" do
26        MCollective::Agent::Nrpe.expects(:plugin_for_command).returns(nil)
27        plugin = Nrpe_data.new
28        plugin.query_data("test_command")
29        plugin.result.exitcode.should == 3
30      end
31    end
32  end
33end
34