2019-05-15 07:20:27 +00:00
|
|
|
##
|
|
|
|
# Do not add any code above this line.
|
|
|
|
|
2022-02-03 16:54:31 +00:00
|
|
|
##
|
|
|
|
# Do not add any other code to this code block. Simplecov
|
|
|
|
# only until the next code block:
|
|
|
|
|
|
|
|
if ENV["CI_ENABLE_COVERAGE"]
|
|
|
|
require "simplecov/no_defaults"
|
|
|
|
require "helpers/simplecov_minitest"
|
|
|
|
|
|
|
|
SimpleCov.start do
|
|
|
|
add_filter "/test/"
|
|
|
|
add_group "Resources", ["lib/resources", "lib/inspec/resources"]
|
|
|
|
add_group "Matchers", ["lib/matchers", "lib/inspec/matchers"]
|
|
|
|
add_group "Backends", "lib/inspec/backend"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-15 07:20:27 +00:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# Do not add any other code from here until the end of this code
|
|
|
|
# block.
|
|
|
|
#
|
|
|
|
# Before ANYTHING else happens, this must happen:
|
|
|
|
#
|
|
|
|
# 1) require minitest/autorun
|
2019-05-31 18:21:20 +00:00
|
|
|
# 2) require rspec/core/dsl
|
|
|
|
# 3) override RSpec::Core::DSL.expose_globally! to do nothing.
|
|
|
|
# 4) require rspec
|
2019-05-15 07:20:27 +00:00
|
|
|
#
|
|
|
|
# Explanation: eventually, our tests get around to inspec/runner_rspec
|
2019-05-31 18:21:20 +00:00
|
|
|
# (and a few others), and they load rspec. By default, when rspec
|
|
|
|
# loads, it creates it's own global `describe` method, overwriting
|
|
|
|
# minitest's.
|
|
|
|
#
|
|
|
|
# Another aspect of rspec's expose_globally! is that it also messes
|
|
|
|
# with mocha's methods. Any tests that occur after our runner has run
|
|
|
|
# RSpec::Core::ExampleGroup.describe will fail if they use any mocha
|
|
|
|
# stubs (specifially any_instance) as the method will be gone. Don't
|
|
|
|
# know why, but the above sequence avoids that.
|
2019-05-15 07:20:27 +00:00
|
|
|
#
|
|
|
|
# Before this, the tests would get to the point of loading rspec, then
|
|
|
|
# all subsequently loaded spec-style tests would just disappear into
|
|
|
|
# the aether. Differences in test load order created differences in
|
|
|
|
# test count and vast differences in test time (which should have been
|
|
|
|
# a clue that something was up--windows is just NOT THAT FAST).
|
|
|
|
|
|
|
|
require "minitest/autorun"
|
|
|
|
|
2019-05-31 18:21:20 +00:00
|
|
|
require "rspec/core/dsl"
|
|
|
|
module RSpec::Core::DSL
|
2019-11-23 00:16:16 +00:00
|
|
|
class << self
|
|
|
|
alias expose_globally! expose_globally! # alias prevents duplicate warning
|
|
|
|
end
|
|
|
|
# rubocop:disable Lint/DuplicateMethods
|
2019-05-31 18:21:20 +00:00
|
|
|
def self.expose_globally!
|
|
|
|
# do nothing
|
|
|
|
end
|
2019-11-23 00:16:16 +00:00
|
|
|
# rubocop:enable Lint/DuplicateMethods
|
2019-05-15 07:20:27 +00:00
|
|
|
end
|
|
|
|
require "rspec"
|
|
|
|
|
|
|
|
# End of rspec vs minitest fight
|
|
|
|
########################################################################
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "webmock/minitest"
|
2019-12-16 22:00:40 +00:00
|
|
|
require "mocha/minitest"
|
2019-06-11 22:24:35 +00:00
|
|
|
require "inspec/log"
|
|
|
|
require "inspec/backend"
|
2022-03-04 18:47:56 +00:00
|
|
|
require_relative "helpers/mock_loader"
|
|
|
|
require_relative "helpers/resources"
|
2019-05-19 00:02:34 +00:00
|
|
|
|
2019-06-04 06:20:32 +00:00
|
|
|
TMP_CACHE = {} # rubocop: disable Style/MutableConstant
|
2015-09-03 15:33:19 +00:00
|
|
|
|
2017-06-15 16:10:47 +00:00
|
|
|
Inspec::Log.logger = Logger.new(nil)
|
|
|
|
|
2015-09-22 16:31:21 +00:00
|
|
|
def load_resource(*args)
|
2019-05-18 21:59:10 +00:00
|
|
|
MockLoader.new.load_resource(*args)
|
2015-09-03 15:33:19 +00:00
|
|
|
end
|
2019-02-21 17:24:19 +00:00
|
|
|
|
2019-04-15 18:48:26 +00:00
|
|
|
# Low-level deprecation handler. Use the more convenient version when possible.
|
|
|
|
# a_group => :expect_warn
|
|
|
|
# a_group => :expect_fail
|
|
|
|
# a_group => :expect_ignore
|
|
|
|
# a_group => :expect_something
|
|
|
|
# a_group => :tolerate # No opinion
|
|
|
|
# all => ... # Any of the 5 values above
|
|
|
|
# all_others => ... # Any of the 5 values above
|
|
|
|
def handle_deprecations(opts_in, &block)
|
|
|
|
opts = opts_in.dup
|
|
|
|
|
|
|
|
# Determine the default expectation
|
|
|
|
opts[:all_others] = opts.delete(:all) if opts.key?(:all) && opts.count == 1
|
|
|
|
expectations = {}
|
|
|
|
expectations[:all_others] = opts.delete(:all_others) || :tolerate
|
|
|
|
expectations.merge!(opts)
|
|
|
|
|
|
|
|
# Expand the list of deprecation groups given
|
|
|
|
known_group_names = Inspec::Deprecation::ConfigFile.new.groups.keys
|
|
|
|
known_group_names.each do |group_name|
|
|
|
|
next if opts.key?(group_name)
|
2019-07-09 00:20:30 +00:00
|
|
|
|
2019-04-15 18:48:26 +00:00
|
|
|
expectations[group_name] = expectations[:all_others]
|
|
|
|
end
|
|
|
|
|
2019-11-08 20:09:09 +00:00
|
|
|
# Wire up Inspec.deprecator accordingly using mocha stubbing
|
2019-04-15 18:48:26 +00:00
|
|
|
expectations.each do |group_name, expectation|
|
|
|
|
inst = Inspec::Deprecation::Deprecator.any_instance
|
|
|
|
case expectation
|
|
|
|
when :tolerate
|
|
|
|
inst.stubs(:handle_deprecation).with(group_name, anything, anything)
|
|
|
|
when :expect_something
|
|
|
|
inst.stubs(:handle_deprecation).with(group_name, anything, anything).at_least_once
|
|
|
|
when :expect_warn
|
|
|
|
inst.stubs(:handle_warn_action).with(group_name, anything).at_least_once
|
|
|
|
when :expect_fail
|
|
|
|
inst.stubs(:handle_fail_control_action).with(group_name, anything).at_least_once
|
|
|
|
when :expect_ignore
|
|
|
|
inst.stubs(:handle_ignore_action).with(group_name, anything).at_least_once
|
|
|
|
when :expect_exit
|
|
|
|
inst.stubs(:handle_exit_action).with(group_name, anything).at_least_once
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
|
|
|
|
# Use this to absorb everything.
|
|
|
|
def tolerate_all_deprecations(&block)
|
|
|
|
handle_deprecations(all: :tolerate, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_deprecation_warning(group, &block)
|
|
|
|
handle_deprecations(group => :expect_warn, all_others: :tolerate, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_deprecation(group, &block)
|
|
|
|
handle_deprecations(group => :expect_something, all_others: :tolerate, &block)
|
|
|
|
end
|
2019-05-17 09:15:07 +00:00
|
|
|
|
2022-05-05 00:17:10 +00:00
|
|
|
def darwin?
|
|
|
|
!!(RbConfig::CONFIG["host_os"] =~ /darwin/)
|
|
|
|
end
|
|
|
|
|
2019-05-17 09:15:07 +00:00
|
|
|
class Minitest::Test
|
2019-07-31 19:24:57 +00:00
|
|
|
# TODO: push up to minitest
|
2019-06-11 22:24:35 +00:00
|
|
|
def skip_until(y, m, d, msg)
|
2019-05-17 09:15:07 +00:00
|
|
|
raise msg if Time.now > Time.local(y, m, d)
|
2019-07-09 00:20:30 +00:00
|
|
|
|
2019-05-17 09:15:07 +00:00
|
|
|
skip msg
|
|
|
|
end
|
2019-07-24 23:49:00 +00:00
|
|
|
|
2020-12-21 20:17:24 +00:00
|
|
|
# These tests are being worked on. These are github issues for them.
|
|
|
|
# Related: https://github.com/inspec/inspec/pull/5063
|
2019-07-24 23:49:00 +00:00
|
|
|
def skip_windows!
|
2020-12-21 20:17:24 +00:00
|
|
|
skip "These have never passed" if windows?
|
2019-07-24 23:49:00 +00:00
|
|
|
end
|
2019-10-31 09:30:55 +00:00
|
|
|
|
|
|
|
def unmock(&blk)
|
|
|
|
# eg: resource = unmock { group "staff" }
|
2019-11-22 14:57:28 +00:00
|
|
|
require "inspec/fetcher/mock"
|
2019-10-31 09:30:55 +00:00
|
|
|
require "inspec/runner"
|
|
|
|
|
|
|
|
# TODO: there is WAY too much magic going on in here
|
|
|
|
runner = Inspec::Runner.new
|
|
|
|
runner.add_target("inspec.yml" => "name: inspec-shell")
|
|
|
|
profile = runner.target_profiles.first
|
|
|
|
ctx = profile.runner_context
|
|
|
|
|
|
|
|
ctx.load blk
|
|
|
|
end
|
2019-05-17 09:15:07 +00:00
|
|
|
end
|
2019-06-01 20:08:10 +00:00
|
|
|
|
|
|
|
class InspecTest < Minitest::Test
|
|
|
|
# shared stuff here
|
|
|
|
end
|