5 require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/discovery/flatfile.rb'
10 describe "#discover" do
13 @client.stubs(:options).returns({})
14 @client.stubs(:options).returns({:discovery_options => ["/nonexisting"]})
17 File.stubs(:readable?).with("/nonexisting").returns(true)
18 File.stubs(:readlines).with("/nonexisting").returns(["one", "two"])
21 it "should use a file specified in discovery_options" do
22 File.expects(:readable?).with("/nonexisting").returns(true)
23 File.expects(:readlines).with("/nonexisting").returns(["one", "two"])
24 Flatfile.discover(Util.empty_filter, 0, 0, @client).should == ["one", "two"]
27 it "should fail unless a file is specified" do
28 @client.stubs(:options).returns({:discovery_options => []})
29 expect { Flatfile.discover(Util.empty_filter, 0, 0, @client) }.to raise_error("The flatfile discovery method needs a path to a text file")
32 it "should fail for unreadable files" do
33 File.expects(:readable?).with("/nonexisting").returns(false)
35 expect { Flatfile.discover(Util.empty_filter, 0, 0, @client) }.to raise_error("Cannot read the file /nonexisting specified as discovery source")
38 it "should regex filters" do
39 Flatfile.discover(Util.empty_filter.merge("identity" => [/one/]), 0, 0, @client).should == ["one"]
42 it "should filter against non regex nodes" do
43 Flatfile.discover(Util.empty_filter.merge("identity" => ["one"]), 0, 0, @client).should == ["one"]