mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
move backend creation to profile context
keeping it in the runner will create conflicts with rspec runners
This commit is contained in:
parent
be614e9056
commit
132019a6d9
3 changed files with 41 additions and 37 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
require 'vulcano/rule'
|
require 'vulcano/rule'
|
||||||
require 'vulcano/dsl'
|
require 'vulcano/dsl'
|
||||||
|
require 'train'
|
||||||
|
|
||||||
module Vulcano
|
module Vulcano
|
||||||
class ProfileContext
|
class ProfileContext
|
||||||
|
@ -140,5 +141,36 @@ module Vulcano
|
||||||
end
|
end
|
||||||
# rubocop:enable all
|
# rubocop:enable all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Create the transport backend with aggregated resources.
|
||||||
|
#
|
||||||
|
# @param [Hash] config for the transport backend
|
||||||
|
# @return [Transport] enriched transport instance
|
||||||
|
def self.create_backend(config)
|
||||||
|
conf = Train.target_config(config)
|
||||||
|
name = conf[:backend] || :local
|
||||||
|
transport = Train.create(name, conf)
|
||||||
|
if transport.nil?
|
||||||
|
fail "Can't find transport backend '#{name}'."
|
||||||
|
end
|
||||||
|
|
||||||
|
connection = transport.connection
|
||||||
|
if connection.nil?
|
||||||
|
fail "Can't connect to transport backend '#{name}'."
|
||||||
|
end
|
||||||
|
|
||||||
|
cls = Class.new do
|
||||||
|
define_method :backend do
|
||||||
|
connection
|
||||||
|
end
|
||||||
|
Vulcano::Resource.registry.each do |id, r|
|
||||||
|
define_method id.to_sym do |*args|
|
||||||
|
r.new(self, id.to_s, *args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
cls.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
# author: Christoph Hartmann
|
# author: Christoph Hartmann
|
||||||
|
|
||||||
require 'uri'
|
require 'uri'
|
||||||
require 'train'
|
|
||||||
require 'vulcano/targets'
|
require 'vulcano/targets'
|
||||||
require 'vulcano/profile_context'
|
require 'vulcano/profile_context'
|
||||||
# spec requirements
|
# spec requirements
|
||||||
|
@ -38,35 +37,8 @@ module Vulcano
|
||||||
RSpec.configuration.add_formatter(@conf['format'] || 'progress')
|
RSpec.configuration.add_formatter(@conf['format'] || 'progress')
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_backend(config)
|
|
||||||
conf = Train.target_config(config)
|
|
||||||
name = conf[:backend] || :local
|
|
||||||
transport = Train.create(name, conf)
|
|
||||||
if transport.nil?
|
|
||||||
fail "Can't find transport backend '#{name}'."
|
|
||||||
end
|
|
||||||
|
|
||||||
connection = transport.connection
|
|
||||||
if connection.nil?
|
|
||||||
fail "Can't connect to transport backend '#{name}'."
|
|
||||||
end
|
|
||||||
|
|
||||||
cls = Class.new do
|
|
||||||
define_method :backend do
|
|
||||||
connection
|
|
||||||
end
|
|
||||||
Vulcano::Resource.registry.each do |id, r|
|
|
||||||
define_method id.to_sym do |*args|
|
|
||||||
r.new(self, id.to_s, *args)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
cls.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def configure_transport
|
def configure_transport
|
||||||
@backend = self.class.create_backend(@conf)
|
@backend = ProfileContext.create_backend(@conf)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_tests(tests)
|
def add_tests(tests)
|
||||||
|
|
|
@ -14,7 +14,7 @@ SimpleCov.start do
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'vulcano/resource'
|
require 'vulcano/resource'
|
||||||
require 'train'
|
require 'vulcano/profile_context'
|
||||||
|
|
||||||
class MockLoader
|
class MockLoader
|
||||||
# pass the os identifier to emulate a specific operating system
|
# pass the os identifier to emulate a specific operating system
|
||||||
|
@ -47,8 +47,11 @@ class MockLoader
|
||||||
scriptpath = ::File.realpath(::File.dirname(__FILE__))
|
scriptpath = ::File.realpath(::File.dirname(__FILE__))
|
||||||
|
|
||||||
# create mock backend
|
# create mock backend
|
||||||
@backend = Train.create('mock')
|
@backend = Vulcano::ProfileContext.create_backend({ backend: :mock })
|
||||||
mock = @backend.connection
|
mock = @backend.backend
|
||||||
|
|
||||||
|
# set os emulation
|
||||||
|
mock.mock_os(@os)
|
||||||
|
|
||||||
# create all mock files
|
# create all mock files
|
||||||
local = Train.create('local').connection
|
local = Train.create('local').connection
|
||||||
|
@ -92,11 +95,11 @@ class MockLoader
|
||||||
# create all mock commands
|
# create all mock commands
|
||||||
cmd = lambda {|x|
|
cmd = lambda {|x|
|
||||||
stdout = ::File.read(::File.join(scriptpath, '/unit/mock/cmd/'+x))
|
stdout = ::File.read(::File.join(scriptpath, '/unit/mock/cmd/'+x))
|
||||||
mock.mock_command(stdout, '', 0)
|
mock.mock_command('', stdout, '', 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
empty = lambda {
|
empty = lambda {
|
||||||
mock.mock_command('', '', 0)
|
mock.mock_command('', '', '', 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.commands = {
|
mock.commands = {
|
||||||
|
@ -179,9 +182,6 @@ class MockLoader
|
||||||
'iptables -S' => cmd.call('iptables-s'),
|
'iptables -S' => cmd.call('iptables-s'),
|
||||||
}
|
}
|
||||||
|
|
||||||
# set os emulation
|
|
||||||
mock.os = @os
|
|
||||||
|
|
||||||
@backend
|
@backend
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue