X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Fplugins%2Fmcollective%2Fdiscovery%2Fflatfile_spec.rb;fp=spec%2Funit%2Fplugins%2Fmcollective%2Fdiscovery%2Fflatfile_spec.rb;h=73fc25bbd3244f308bfdaa721ae4f5a0714a3bce;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/plugins/mcollective/discovery/flatfile_spec.rb b/spec/unit/plugins/mcollective/discovery/flatfile_spec.rb new file mode 100644 index 0000000..73fc25b --- /dev/null +++ b/spec/unit/plugins/mcollective/discovery/flatfile_spec.rb @@ -0,0 +1,48 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/discovery/flatfile.rb' + +module MCollective + class Discovery + describe Flatfile do + describe "#discover" do + before do + @client = mock + @client.stubs(:options).returns({}) + @client.stubs(:options).returns({:discovery_options => ["/nonexisting"]}) + + + File.stubs(:readable?).with("/nonexisting").returns(true) + File.stubs(:readlines).with("/nonexisting").returns(["one", "two"]) + end + + it "should use a file specified in discovery_options" do + File.expects(:readable?).with("/nonexisting").returns(true) + File.expects(:readlines).with("/nonexisting").returns(["one", "two"]) + Flatfile.discover(Util.empty_filter, 0, 0, @client).should == ["one", "two"] + end + + it "should fail unless a file is specified" do + @client.stubs(:options).returns({:discovery_options => []}) + expect { Flatfile.discover(Util.empty_filter, 0, 0, @client) }.to raise_error("The flatfile discovery method needs a path to a text file") + end + + it "should fail for unreadable files" do + File.expects(:readable?).with("/nonexisting").returns(false) + + expect { Flatfile.discover(Util.empty_filter, 0, 0, @client) }.to raise_error("Cannot read the file /nonexisting specified as discovery source") + end + + it "should regex filters" do + Flatfile.discover(Util.empty_filter.merge("identity" => [/one/]), 0, 0, @client).should == ["one"] + end + + it "should filter against non regex nodes" do + Flatfile.discover(Util.empty_filter.merge("identity" => ["one"]), 0, 0, @client).should == ["one"] + end + end + end + end +end