Class: MCollective::Test::LocalAgentTest

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/mcollective/test/local_agent_test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#create_config_mock, #create_connector_mock, #create_facts_mock, #create_logger_mock, #create_response, #load_agent, #load_application, #mock_validators

Constructor Details

#initialize(agent, options = {}) ⇒ LocalAgentTest

Returns a new instance of LocalAgentTest.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mcollective/test/local_agent_test.rb', line 8

def initialize(agent, options={})
  config = options[:config]

  facts = options[:facts] || {"fact" => "value"}

  @config = create_config_mock(config)
  @agent = agent.to_s
  @logger = create_logger_mock
  @connector = create_connector_mock
  @plugin = load_agent(agent, options[:agent_file])

  create_facts_mock(facts)
  mock_validators

  make_call_helper
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



4
5
6
# File 'lib/mcollective/test/local_agent_test.rb', line 4

def agent
  @agent
end

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/mcollective/test/local_agent_test.rb', line 4

def config
  @config
end

#connectorObject (readonly)

Returns the value of attribute connector.



4
5
6
# File 'lib/mcollective/test/local_agent_test.rb', line 4

def connector
  @connector
end

#factsObject (readonly)

Returns the value of attribute facts.



4
5
6
# File 'lib/mcollective/test/local_agent_test.rb', line 4

def facts
  @facts
end

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/mcollective/test/local_agent_test.rb', line 4

def logger
  @logger
end

#pluginObject (readonly)

Returns the value of attribute plugin.



4
5
6
# File 'lib/mcollective/test/local_agent_test.rb', line 4

def plugin
  @plugin
end

Instance Method Details

#make_call_helperObject

Place the mocked connector into the plugin instance and create a call helper method that passes the connector in and call the action via handlemsg.

This will let you test auditing etc



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mcollective/test/local_agent_test.rb', line 31

def make_call_helper
  @plugin.instance_variable_set("@mocked_connector", @connector)

  @plugin.instance_eval "
    def call(action, args={})
        request = {:action => action.to_s,
                   :agent => '#{@agent}',
                   :data => args}

        handlemsg({:body => request}, @mocked_connector)
    end
  "
end