Class: Kitchen::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/config.rb

Overview

Base configuration class for Kitchen. This class exposes configuration such as the location of the Kitchen config file, instances, log_levels, etc. This object is a factory object, meaning that it is responsible for consuming the desired testing configuration in and returning Ruby objects which are used to perfom the work.

Most internal objects are created with the expectation of being immutable, meaning that internal state cannot be modified after creation. Any data manipulation or thread-unsafe activity is performed in this object so that the subsequently created objects (such as Instances, Platforms, Drivers, etc.) can safely run in concurrent threads of execution. To prevent the re-creation of duplicate objects, most created objects are memoized. The consequence of this is that once the Instance Array has been requested (with the #instances message), you will always be returned the same Instance objects.

Examples:

fetching all instances


Kitchen::Config.new.instances

fetching an instance by name


Kitchen::Config.new.instances.get("default-ubuntu-12.04")

fetching all instances matching a regular expression


Kitchen::Config.new.instances.get_all(/ubuntu/)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Creates a new configuration, representing a particular testing configuration for a project.

Options Hash (options):

  • :loader (#read)

    an object that responds to #read with a Hash structure suitable for manipulating (default: Kitchen::Loader::YAML.new)

  • :kitchen_root (String)

    an absolute path to the root of a Test Kitchen project, usually containing a .kitchen.yml file (default Dir.pwd)

  • :log_root (String)

    an absolute path to the directory into which all Test Kitchen log files will be written (default: "#{kitchen_root}/.kitchen/logs")

  • :test_base_path (String)

    an absolute path to the directory containing test suites and other testing-related files and directories (default: "#{kitchen_root}/test/integration")

  • :log_level (Symbol)

    the log level verbosity that the loggers will use when outputing information (default: :info)



93
94
95
96
97
98
99
# File 'lib/kitchen/config.rb', line 93

def initialize(options = {})
  @loader         = options.fetch(:loader) { Kitchen::Loader::YAML.new }
  @kitchen_root   = options.fetch(:kitchen_root) { Dir.pwd }
  @log_level      = options.fetch(:log_level) { Kitchen::DEFAULT_LOG_LEVEL }
  @log_root       = options.fetch(:log_root) { default_log_root }
  @test_base_path = options.fetch(:test_base_path) { default_test_base_path }
end

Instance Attribute Details

#kitchen_rootString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the absolute path to the root of a Test Kitchen project.



54
55
56
# File 'lib/kitchen/config.rb', line 54

def kitchen_root
  @kitchen_root
end

#loader#read (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The data loader that responds to a #read message, returning a Hash data structure



69
70
71
# File 'lib/kitchen/config.rb', line 69

def loader
  @loader
end

#log_levelSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the logging verbosity level.



73
74
75
# File 'lib/kitchen/config.rb', line 73

def log_level
  @log_level
end

#log_rootString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the absolute path to the directory into which all Test Kitchen log files will be written.



59
60
61
# File 'lib/kitchen/config.rb', line 59

def log_root
  @log_root
end

#test_base_pathString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the absolute path to the directory containing test suites and other testing-related file and directories.



64
65
66
# File 'lib/kitchen/config.rb', line 64

def test_base_path
  @test_base_path
end

Instance Method Details

#instancesCollection<Instance>



103
104
105
# File 'lib/kitchen/config.rb', line 103

def instances
  @instances ||= Collection.new(build_instances)
end

#platformsCollection<Platform>



109
110
111
112
# File 'lib/kitchen/config.rb', line 109

def platforms
  @platforms ||= Collection.new(
    data.platform_data.map { |pdata| Platform.new(pdata) })
end

#suitesCollection<Suite>



116
117
118
119
# File 'lib/kitchen/config.rb', line 116

def suites
  @suites ||= Collection.new(
    data.suite_data.map { |sdata| Suite.new(sdata) })
end