2016-03-25 00:31:19 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
|
|
|
|
require 'helper'
|
|
|
|
|
|
|
|
require 'minitest/hell'
|
|
|
|
class Minitest::Test
|
|
|
|
parallelize_me!
|
|
|
|
end
|
|
|
|
|
|
|
|
class Module
|
|
|
|
include Minitest::Spec::DSL
|
|
|
|
end
|
|
|
|
|
|
|
|
module FunctionalHelper
|
|
|
|
let(:repo_path) { File.expand_path(File.join( __FILE__, '..', '..', '..')) }
|
|
|
|
let(:exec_inspec) { File.join(repo_path, 'bin', 'inspec') }
|
|
|
|
let(:profile_path) { File.join(repo_path, 'test', 'unit', 'mock', 'profiles') }
|
|
|
|
let(:examples_path) { File.join(repo_path, 'examples') }
|
2017-08-15 18:41:24 +00:00
|
|
|
let(:integration_test_path) { File.join(repo_path, 'test', 'integration', 'default') }
|
2016-03-25 00:31:19 +00:00
|
|
|
|
|
|
|
let(:example_profile) { File.join(examples_path, 'profile') }
|
2016-04-20 04:50:18 +00:00
|
|
|
let(:example_control) { File.join(example_profile, 'controls', 'example.rb') }
|
2016-03-25 00:31:19 +00:00
|
|
|
let(:inheritance_profile) { File.join(examples_path, 'profile') }
|
2016-09-01 12:25:56 +00:00
|
|
|
let(:failure_control) { File.join(profile_path, 'failures', 'controls', 'failures.rb') }
|
2016-09-01 22:54:03 +00:00
|
|
|
let(:simple_inheritance) { File.join(profile_path, 'simple-inheritance') }
|
2017-08-25 20:21:49 +00:00
|
|
|
let(:sensitive_profile) { File.join(examples_path, 'profile-sensitive') }
|
2016-03-25 00:31:19 +00:00
|
|
|
|
|
|
|
let(:dst) {
|
|
|
|
# create a temporary path, but we only want an auto-clean helper
|
|
|
|
# so remove the file and give back the path
|
|
|
|
res = Tempfile.new('inspec-shred')
|
|
|
|
FileUtils.rm(res.path)
|
|
|
|
TMP_CACHE[res.path] = res
|
|
|
|
}
|
|
|
|
|
2016-11-09 14:41:48 +00:00
|
|
|
def inspec(commandline, prefix = nil)
|
|
|
|
CMD.run_command("#{prefix} #{exec_inspec} #{commandline}")
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
2017-06-12 12:01:26 +00:00
|
|
|
|
|
|
|
# Copy all examples to a temporary directory for functional tests.
|
|
|
|
# You can provide an optional directory which will be handed to your
|
|
|
|
# test block with its absolute path. If nothing is provided you will
|
|
|
|
# get the path of the examples directory in the tmp environment.
|
|
|
|
#
|
|
|
|
# @param dir = nil [String] optional directory you want to test
|
|
|
|
# @param &block [Type] actual test block
|
|
|
|
def prepare_examples(dir = nil, &block)
|
|
|
|
Dir.mktmpdir do |tmpdir|
|
|
|
|
FileUtils.cp_r(examples_path, tmpdir)
|
|
|
|
bn = File.basename(examples_path)
|
|
|
|
block.call(File.join(tmpdir, bn, dir.to_s))
|
|
|
|
end
|
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|