Update mcollective.init according to OSCI-855
[packages/precise/mcollective.git] / spec / unit / plugins / mcollective / discovery / flatfile_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4
5 require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/discovery/flatfile.rb'
6
7 module MCollective
8   class Discovery
9     describe Flatfile do
10       describe "#discover" do
11         before do
12           @client = mock
13           @client.stubs(:options).returns({})
14           @client.stubs(:options).returns({:discovery_options => ["/nonexisting"]})
15
16
17           File.stubs(:readable?).with("/nonexisting").returns(true)
18           File.stubs(:readlines).with("/nonexisting").returns(["one", "two"])
19         end
20
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"]
25         end
26
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")
30         end
31
32         it "should fail for unreadable files" do
33           File.expects(:readable?).with("/nonexisting").returns(false)
34
35           expect { Flatfile.discover(Util.empty_filter, 0, 0, @client) }.to raise_error("Cannot read the file /nonexisting specified as discovery source")
36         end
37
38         it "should regex filters" do
39           Flatfile.discover(Util.empty_filter.merge("identity" => [/one/]), 0, 0, @client).should == ["one"]
40         end
41
42         it "should filter against non regex nodes" do
43           Flatfile.discover(Util.empty_filter.merge("identity" => ["one"]), 0, 0, @client).should == ["one"]
44         end
45       end
46     end
47   end
48 end