<commit_before>require 'support/mcollective'

describe Support::MCollective do
  before do
    extend Support::MCollective
    @mock_rpcclient = double
    class Support::MCollective::MCollectiveRPC
      def self.mco_options
        return @@mco_options
      end

      def self.rpcclient=(rpcclient)
        @@rpcclient = rpcclient
      end

      def rpcclient(name, options)
        @@mco_options = options
        return @@rpcclient
      end
    end
    Support::MCollective::MCollectiveRPC.rpcclient=@mock_rpcclient

    def async_fork_and_return(&block)
      return Support::Forking::Future.new(&block)
    end

    @mock_rpcclient.should_receive(:disconnect)
  end

  it 'shortcuts a nested mco_client' do
    @mock_rpcclient.should_receive(:discover).with(no_args)
    mco_client("blah") do |mco|
      mco.should eql(@mock_rpcclient)
    end
  end

  it 'applies a filter so that only machines in the fabric are addressed' do
    @mock_rpcclient.should_receive(:discover).with(no_args)
    @mock_rpcclient.should_receive(:fact_filter).with("domain", "mgmt.st.net.local")
    mco_client("blah", :fabric => "st") do |mco|
    end
  end

  it 'applies a filter so that only local machines are addressed' do
    @mock_rpcclient.should_receive(:discover).with(no_args).ordered
    @mock_rpcclient.should_receive(:identity_filter).with(`hostname --fqdn`.chomp)
    mco_client("blah", :fabric => "local") do |mco|
    end
  end

  it 'uses a timeout if supplied' do
    @mock_rpcclient.should_receive(:discover).with(no_args).ordered
    @mock_rpcclient.should_receive(:identity_filter).with(`hostname --fqdn`.chomp)
    mco_client("blah", :fabric => "local", :timeout => 44) do |mco|
    end
    Support::MCollective::MCollectiveRPC.mco_options[:options][:timeout].should eql(44)
  end

  it 'can be pre-injected with a list of hosts to discover' do
    my_nodes = ["1", "2", "3"]
    @mock_rpcclient.should_receive(:discover).with({:nodes => my_nodes})
    mco_client("blah", :nodes => my_nodes) do |mco|
    end
  end

  it 'switch the mco key to use' do
    @mock_rpcclient.should_receive(:discover).with(no_args).ordered
    mco_client("blah", :key => 'seed') do
    end
    ::MCollective::Config.instance().pluginconf["ssl_client_public"].should eql("/etc/mcollective/ssl/seed.pem")
  end
end<commit_msg>rpearce/dellis; Fixing tests<commit_after>require 'support/mcollective'
require 'facter'

describe Support::MCollective do
  before do
    extend Support::MCollective
    ENV['FACTERLIB'] = "/var/lib/puppet/lib/facter:/var/lib/puppet/facts"
    @mock_rpcclient = double
    class Support::MCollective::MCollectiveRPC
      def self.mco_options
        return @@mco_options
      end

      def self.rpcclient=(rpcclient)
        @@rpcclient = rpcclient
      end

      def rpcclient(name, options)
        @@mco_options = options
        return @@rpcclient
      end
    end
    Support::MCollective::MCollectiveRPC.rpcclient=@mock_rpcclient

    def async_fork_and_return(&block)
      return Support::Forking::Future.new(&block)
    end

    @mock_rpcclient.should_receive(:disconnect)
  end

  it 'shortcuts a nested mco_client' do
    @mock_rpcclient.should_receive(:discover).with(no_args)
    mco_client("blah") do |mco|
      mco.should eql(@mock_rpcclient)
    end
  end

  it 'applies a filter so that only machines in the fabric are addressed' do
    @mock_rpcclient.should_receive(:discover).with(no_args)
    @mock_rpcclient.should_receive(:fact_filter).with("domain", "mgmt.st.net.local")
    mco_client("blah", :fabric => "st") do |mco|
    end
  end

  it 'applies a filter so that only local machines are addressed' do
    @mock_rpcclient.should_receive(:discover).with(no_args).ordered
    @mock_rpcclient.should_receive(:fact_filter).with("owner", Facter.value('owner'))
    mco_client("blah", :fabric => "local") do |mco|
    end
  end

  it 'uses a timeout if supplied' do
    @mock_rpcclient.should_receive(:discover).with(no_args).ordered
    @mock_rpcclient.should_receive(:fact_filter).with("owner", Facter.value('owner'))
    mco_client("blah", :fabric => "local", :timeout => 44) do |mco|
    end
    Support::MCollective::MCollectiveRPC.mco_options[:options][:timeout].should eql(44)
  end

  it 'can be pre-injected with a list of hosts to discover' do
    my_nodes = ["1", "2", "3"]
    @mock_rpcclient.should_receive(:discover).with({:nodes => my_nodes})
    mco_client("blah", :nodes => my_nodes) do |mco|
    end
  end

  it 'switch the mco key to use' do
    @mock_rpcclient.should_receive(:discover).with(no_args).ordered
    mco_client("blah", :key => 'seed') do
    end
    ::MCollective::Config.instance().pluginconf["ssl_client_public"].should eql("/etc/mcollective/ssl/seed.pem")
  end
end
{'fraction_non_alphanumeric': 0.12579013906447534, 'fraction_numerical': 0.0029498525073746312, 'mean_word_length': 3.965481171548117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2625533', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1589, 'n_words': 333}