Sha256: 74136a8c652358e45d1b210889ebc4298a76a34a523015df5a657e389458496b

Contents?: true

Size: 1.78 KB

Versions: 5

Compression:

Stored size: 1.78 KB

Contents

#!/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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mcollective-client-2.2.4 spec/unit/plugins/mcollective/discovery/flatfile_spec.rb
mcollective-client-2.2.3 spec/unit/plugins/mcollective/discovery/flatfile_spec.rb
mcollective-client-2.2.2 spec/unit/plugins/mcollective/discovery/flatfile_spec.rb
mcollective-client-2.2.1 spec/unit/plugins/mcollective/discovery/flatfile_spec.rb
mcollective-client-2.2.0 spec/unit/plugins/mcollective/discovery/flatfile_spec.rb