X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Fdata%2Fbase_spec.rb;fp=spec%2Funit%2Fdata%2Fbase_spec.rb;h=51ffa6ce0d6419f67a6f1f43b3efdacc479063db;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/data/base_spec.rb b/spec/unit/data/base_spec.rb new file mode 100644 index 0000000..51ffa6c --- /dev/null +++ b/spec/unit/data/base_spec.rb @@ -0,0 +1,90 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +module MCollective + module Data + describe Base do + before do + @ddl = mock + @ddl.stubs(:meta).returns({:timeout => 1}) + end + + describe "#initialize" do + it "should set the plugin name, ddl and timeout and call the startup hook" do + DDL.stubs(:new).returns(@ddl) + Base.any_instance.expects(:startup_hook).once + plugin = Base.new + plugin.name.should == "base" + plugin.timeout.should == 1 + plugin.result.class.should == Result + end + end + + describe "#lookup" do + before do + DDL.stubs(:new).returns(@ddl) + @plugin = Base.new + end + + it "should validate the request" do + @plugin.expects(:ddl_validate).with("hello world").returns(true) + @plugin.stubs(:query_data) + @plugin.lookup("hello world") + end + + it "should query the plugin" do + @plugin.stubs(:ddl_validate) + @plugin.expects(:query_data).with("hello world") + @plugin.lookup("hello world").class.should == Result + end + + it "should raise MsgTTLExpired errors for Timeout errors" do + @plugin.stubs(:ddl_validate) + @plugin.expects(:query_data).raises(Timeout::Error) + + msg = "Data plugin base timed out on query 'hello world'" + Log.expects(:error).with(msg) + expect { @plugin.lookup("hello world") }.to raise_error(msg) + end + end + + describe "#query" do + it "should create a new method" do + class Rspec_data