Class: MCollective::Test::DataTest

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/mcollective/test/data_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(data, options = {}) ⇒ DataTest

Returns a new instance of DataTest.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mcollective/test/data_test.rb', line 8

def initialize(data, options={})
  config = options.fetch(:config, {})

  ARGV.clear

  @config = create_config_mock(config)
  @logger = create_logger_mock

  @plugin = load_data(data, options[:data_file])
  @plugin.stubs(:ddl_validate).returns(true)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#pluginObject (readonly)

Returns the value of attribute plugin.



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

def plugin
  @plugin
end

Instance Method Details

#load_data(data, data_file = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mcollective/test/data_test.rb', line 20

def load_data(data, data_file=nil)
  classname = "MCollective::Data::%s " % data.capitalize

  PluginManager.delete(data.downcase)

  if data_file
    raise("Cannot find data file %s for data plugin %s" % [data_file, data]) unless File.exist?(data_file)
    load data_file
  else
    PluginManager.loadclass(classname)
  end

  ddl = DDL::Base.new(data, :data, false)
  ddl.stubs(:dataquery_interface).returns(:output => {})

  DDL.stubs(:new).with(data, :data).returns(ddl)

  unless PluginManager.pluginlist.include?(data.downcase)
    PluginManager << {:type => data, :class => "MCollective::Data::%s" % data.capitalize, :single_instance => false}
  end

  PluginManager[data.downcase]
end