mirror of
https://github.com/inspec/inspec
synced 2024-12-11 22:02:47 +00:00
5fdf659df1
The goal of these changes is to ensure that the libraries from dependencies are loaded even if their controls are never included. To facilitate this, we break up the loading into seperate steps, and move the loading code into the Profile which has acceess to the dependency information. Signed-off-by: Steven Danna <steve@chef.io>
58 lines
1.3 KiB
Ruby
58 lines
1.3 KiB
Ruby
# encoding: utf-8
|
|
# author: Dominik Richter
|
|
|
|
require_relative 'docker_run'
|
|
require_relative '../lib/inspec'
|
|
#
|
|
# BUGON: These requires are to get around concurrency issues with
|
|
# autoloading in Ruby
|
|
#
|
|
require 'train'
|
|
require 'train/plugins'
|
|
require 'train/plugins/transport'
|
|
require 'train/transports/docker'
|
|
|
|
tests = ARGV
|
|
if tests.empty?
|
|
puts 'Nothing to do.'
|
|
exit 0
|
|
end
|
|
|
|
class DockerTester
|
|
def initialize(tests)
|
|
@tests = tests
|
|
@docker = DockerRunner.new
|
|
end
|
|
|
|
def run
|
|
puts ['Running tests:', @tests].flatten.join("\n- ")
|
|
puts ''
|
|
|
|
conf = RSpec.configuration
|
|
reporter = conf.reporter
|
|
results = nil
|
|
|
|
# start reporting loop
|
|
reporter.report(0) do |report|
|
|
results = @docker.run_all do |name, container|
|
|
status = test_container(container, report)
|
|
status.all? ? nil : "Failed to run tests on #{name}"
|
|
end
|
|
end
|
|
|
|
# check if we were successful
|
|
failures = results.compact
|
|
failures.each { |f| puts "\033[31;1m#{f}\033[0m\n\n" }
|
|
failures.empty? or fail 'Test failures'
|
|
end
|
|
|
|
def test_container(container, report)
|
|
puts "--> run test on docker #{container.id}"
|
|
opts = { 'target' => "docker://#{container.id}" }
|
|
runner = Inspec::Runner.new(opts)
|
|
@tests.each { |test| runner.add_target(test) }
|
|
runner.tests.map { |g| g.run(report) }
|
|
end
|
|
end
|
|
|
|
DockerTester.new(tests).run
|