code
stringlengths
26
124k
docstring
stringlengths
23
125k
func_name
stringlengths
1
98
language
stringclasses
1 value
repo
stringlengths
5
53
path
stringlengths
7
151
url
stringlengths
50
211
license
stringclasses
7 values
def prettify(raised, message=nil) # Get message from raised, if not given message ||= raised.message backtrace = raised.respond_to?(:backtrace) ? raised.backtrace : raised.location # Filter and clean backtrace backtrace = clean_backtrace(backtrace) # Add trace mark to first line. backtrace.first.insert(0, TRACE_MARK) io.puts Colorize.bold(message.tabto(TAB_SIZE)) io.puts backtrace.shift.tabto(TAB_SIZE - TRACE_MARK.length) io.puts backtrace.join("\n").tabto(TAB_SIZE) io.puts end
Cleanups and prints test payload Example: fail is not 1 @ test/test_runners.rb:46:in `test_autorun_with_trace' bin/turn:4:in `<main>'
prettify
ruby
turn-project/turn
lib/turn/reporters/pretty_reporter.rb
https://github.com/turn-project/turn/blob/master/lib/turn/reporters/pretty_reporter.rb
MIT
def fail(assertion, message=nil) @record[:fails][@_current_case] << assertion end
def start_test(test) end def pass(message=nil) end
fail
ruby
turn-project/turn
lib/turn/reporters/progress_reporter.rb
https://github.com/turn-project/turn/blob/master/lib/turn/reporters/progress_reporter.rb
MIT
def start suite = TestSuite.new testruns = @config.files.collect do |file| name = file.sub(Dir.pwd+'/','') suite.new_case(name, file) end test_loop_runner(suite) end
Runs the list of test calls passed to it. This is used by #test_solo and #test_cross.
start
ruby
turn-project/turn
lib/turn/runners/isorunner.rb
https://github.com/turn-project/turn/blob/master/lib/turn/runners/isorunner.rb
MIT
def test_loop_runner(suite) reporter.start_suite(suite) recase = [] suite.each_with_index do |kase, index| reporter.start_case(kase) turn_path = File.expand_path(File.dirname(__FILE__) + '/../bin.rb') files = kase.files.map{ |f| f.sub(Dir.pwd+'/', '') } # FRACKING GENIUS RIGHT HERE !!!!!!!!!!!! cmd = [] cmd << "ruby" cmd << "-I#{@loadpath.join(':')}" unless @loadpath.empty? cmd << "-r#{@requires.join(':')}" unless @requires.empty? cmd << "--" cmd << turn_path cmd << "--marshal" cmd << %[--loadpath="#{@loadpath.join(':')}"] unless @loadpath.empty? cmd << %[--requires="#{@requires.join(':')}"] unless @requires.empty? cmd << "--live" if @live cmd << files.join(' ') cmd = cmd.join(' ') #out = `#{cmd}` #err = '' out, err = nil, nil #p cmd Open3.popen3(cmd) do |stdin, stdout, stderr| stdin.close out = stdout.read.chomp err = stderr.read.chomp end # TODO: how to report? will need to add something to reporter # b/c it may have redirected stdout. Or use STDOUT? #if !err.empty? # puts err # raise #end files = kase.files # remove any unexpected output injected at the beginning b = out.index(/^---/m) yaml = out[b..-1] sub_suite = YAML.load(yaml) # TODO: How to handle pairs? #name = kase.name kases = sub_suite.cases suite.cases[index] = kases kases.each do |kase| kase.files = files #reporter.start_case(kase) kase.tests.each do |test| reporter.start_test(test) if test.error? #reporter.error(test.message) reporter.error(test.raised) elsif test.fail? #reporter.fail(test.message) reporter.error(test.raised) else reporter.pass end reporter.finish_test(test) end reporter.finish_case(kase) end end suite.cases.flatten! reporter.finish_suite(suite) suite end
The IsoRunner actually shells out to turn in manifest mode, to gather results from isolated runs.
test_loop_runner
ruby
turn-project/turn
lib/turn/runners/isorunner.rb
https://github.com/turn-project/turn/blob/master/lib/turn/runners/isorunner.rb
MIT
def log_report(report) if log #&& !dryrun? #logfile = File.join('log', apply_naming_policy('testlog', 'txt')) FileUtils.mkdir_p('log') logfile = File.join('log', 'testlog.txt') File.open(logfile, 'a') do |f| f << "= #{self.class} Test @ #{Time.now}\n" f << report f << "\n" end end end
def test_parse_result(result) if md = /(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors/.match(result) count = md[1..4].collect{|q| q.to_i} else count = [1, 0, 0, 1] # SHOULD NEVER HAPPEN end return count end NOT USED YET.
log_report
ruby
turn-project/turn
lib/turn/runners/isorunner.rb
https://github.com/turn-project/turn/blob/master/lib/turn/runners/isorunner.rb
MIT
def test_load(options={}) options = test_configuration(options) tests = options['tests'] loadpath = options['loadpath'] requires = options['requires'] live = options['live'] exclude = options['exclude'] files = Dir.multiglob_r(*tests) - Dir.multiglob_r(*exclude) return puts("No tests.") if files.empty? max = files.collect{ |f| f.size }.max list = [] files.each do |f| next unless File.file?(f) if r = system("ruby -I#{loadpath.join(':')} #{f} > /dev/null 2>&1") puts "%-#{max}s [PASS]" % [f] #if verbose? else puts "%-#{max}s [FAIL]" % [f] #if verbose? list << f end end puts " #{list.size} Load Failures" if verbose? unless list.empty? puts "\n-- Load Failures --\n" list.each do |f| print "* " system "ruby -I#{loadpath} #{f} 2>&1" #puts end puts end end end
TODO Load each test independently to ensure there are no require dependency issues. This is actually a bit redundant as test-solo will also cover these results. So we may deprecate this in the future. This does not generate a test log entry.
test_load
ruby
turn-project/turn
lib/turn/runners/loadrunner.rb
https://github.com/turn-project/turn/blob/master/lib/turn/runners/loadrunner.rb
MIT
def start(args=[]) # minitest changed #run in 6023c879cf3d5169953e on April 6th, 2011 if ::MiniTest::Unit.respond_to?(:runner=) ::MiniTest::Unit.runner = self end # FIXME: why isn't @test_count set? run(args) return @turn_suite end
Turn calls this method to start the test run.
start
ruby
turn-project/turn
lib/turn/runners/minirunner.rb
https://github.com/turn-project/turn/blob/master/lib/turn/runners/minirunner.rb
MIT
def _run_suite suite, type # suites are cases in minitest @turn_case = @turn_suite.new_case(suite.name) filter = normalize_filter(@options[:filter]) || @turn_config.pattern || /./ suite.send("#{type}_methods").grep(/#{filter}/).each do |test| @turn_case.new_test(test) end turn_reporter.start_case(@turn_case) header = "#{type}_suite_header" puts send(header, suite) if respond_to? header assertions = @turn_case.tests.map do |test| @turn_test = test turn_reporter.start_test(@turn_test) inst = suite.new(test.name) #method inst._assertions = 0 result = inst.run self if result == "." turn_reporter.pass end turn_reporter.finish_test(@turn_test) inst._assertions end @turn_case.count_assertions = assertions.inject(0) { |sum, n| sum + n } turn_reporter.finish_case(@turn_case) return assertions.size, assertions.inject(0) { |sum, n| sum + n } end
Override #_run_suite to iterate tests via Turn.
_run_suite
ruby
turn-project/turn
lib/turn/runners/minirunner.rb
https://github.com/turn-project/turn/blob/master/lib/turn/runners/minirunner.rb
MIT
def puke(klass, meth, err) case err when MiniTest::Skip @turn_test.skip!(err) turn_reporter.skip(err) when MiniTest::Assertion @turn_test.fail!(err) turn_reporter.fail(err) else @turn_test.error!(err) turn_reporter.error(err) end super(klass, meth, err) end
Override #puke to update Turn's internals and reporter.
puke
ruby
turn-project/turn
lib/turn/runners/minirunner.rb
https://github.com/turn-project/turn/blob/master/lib/turn/runners/minirunner.rb
MIT
def normalize_filter(filter) filter.sub(/^(\/)/, '').sub(/(\/)$/, '') if filter end
regex gets turned into a string literal with leading/trailing slashes so remove them
normalize_filter
ruby
turn-project/turn
lib/turn/runners/minirunner.rb
https://github.com/turn-project/turn/blob/master/lib/turn/runners/minirunner.rb
MIT
def test_ruby19_minitest_required setup_test('MiniTest', 'minitest/unit') result = turn 'tmp/test.rb' assert result.index('PASS') end
def test_ruby19_minitest_force setup_test('MiniTest') result = turn '--minitest tmp/test.rb' assert result.index('PASS') end
test_ruby19_minitest_required
ruby
turn-project/turn
test/test_framework.rb
https://github.com/turn-project/turn/blob/master/test/test_framework.rb
MIT
def test_ruby19_minitest_mocking setup_test('MiniTest', 'minitest/unit') result = turn 'tmp/test.rb' assert result.index('PASS'), "RESULT:\n#{result}" end
def test_ruby19_minitest_required_force setup_test('MiniTest', 'minitest/unit') result = turn '--minitest tmp/test.rb' assert result.index('PASS') end
test_ruby19_minitest_mocking
ruby
turn-project/turn
test/test_framework.rb
https://github.com/turn-project/turn/blob/master/test/test_framework.rb
MIT
def test_ruby19_minitest_mocking_required setup_test('Test', 'minitest/unit') result = turn 'tmp/test.rb' assert result.index('PASS') end
def test_ruby19_minitest_mocking_force setup_test('Test') result = turn '--minitest tmp/test.rb' assert result.index('PASS') end
test_ruby19_minitest_mocking_required
ruby
turn-project/turn
test/test_framework.rb
https://github.com/turn-project/turn/blob/master/test/test_framework.rb
MIT
def sub_dir(url) URI.parse(url) url.split('/')[7].split('_')[0].gsub('%2', '-').downcase end
This method relies on the GitHub release artefact URL e.g. https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.3%2B7/OpenJDK17U-jdk_aarch64_linux_hotspot_17.0.3_7.tar.gz
sub_dir
ruby
sous-chefs/java
libraries/openjdk_helpers.rb
https://github.com/sous-chefs/java/blob/master/libraries/openjdk_helpers.rb
Apache-2.0
def record return @record if @record @record = begin email_count = (MAX_RECORD_COUNT / 4.to_f).round attachment_count = ((MAX_RECORD_COUNT - email_count) / email_count.to_f).round campaign = Campaign.forge! emails: email_count, attachments: attachment_count # load associations into memory so they can be included during serialization... campaign.tap { |c| c.emails.each { |c| c.attachments.load } } end end
Returns the object to be serialized in benchmarks
record
ruby
hopsoft/universalid
bin/benchmarks/lib/runner.rb
https://github.com/hopsoft/universalid/blob/master/bin/benchmarks/lib/runner.rb
MIT
def has_many_descendant_instances_by_association_name has_many_associations.each_with_object({}) do |association, memo| relation = record.public_send(association.name) descendants = Set.new # persisted records relation.each { |descendant| descendants << descendant } if relation.loaded? # new records relation.target.each { |descendant| descendants << descendant } if relation.target.any? memo[association.name] = descendants.to_a if descendants.any? end end
Returns a has of the current in-memory `has_many` associated records keyed by name
has_many_descendant_instances_by_association_name
ruby
hopsoft/universalid
lib/universalid/extensions/active_record/base_packer.rb
https://github.com/hopsoft/universalid/blob/master/lib/universalid/extensions/active_record/base_packer.rb
MIT
def to_global_id_model UniversalID::Extensions::GlobalIDModel.new self end
Returns a UniversalID::Extensions::GlobalIDModel instance which implements the GlobalID::Identification interface/protocol
to_global_id_model
ruby
hopsoft/universalid
lib/universalid/extensions/global_id/global_id_uid_extension.rb
https://github.com/hopsoft/universalid/blob/master/lib/universalid/extensions/global_id/global_id_uid_extension.rb
MIT
def new(...) super.tap do |uri| if uri.invalid? raise ::URI::InvalidComponentError, "Scheme must be `#{SCHEME}`" if uri.scheme != SCHEME raise ::URI::InvalidComponentError, "Host must be `#{HOST}`" if uri.host != HOST raise ::URI::InvalidComponentError, "Unable to parse `payload` from the path component!" if uri.payload.strip.empty? end end end
Creates a new URI::UID with the given URI components. SEE: https://ruby-doc.org/3.2.2/stdlibs/uri/URI/Generic.html#method-c-new @param scheme [String] the scheme component. @param userinfo [String] the userinfo component. @param host [String] the host component. @param port [Integer] the port component. @param registry [String] the registry component. @param path [String] the path component. @param opaque [String] the opaque component. @param query [String] the query component. @param fragment [String] the fragment component. @param parser [URI::Parser] the parser to use for the URI, defaults to DEFAULT_PARSER. @param arg_check [Boolean] whether to check arguments, defaults to false. @return [URI::UID] the new URI::UID instance. # @raise [URI::InvalidURIError] if the URI is malformed. @raise [ArgumentError] if the number of arguments is incorrect or an argument is of the wrong type. @raise [TypeError] if an argument is not of the expected type. @raise [URI::InvalidComponentError] if a component of the URI is not valid. @raise [URI::BadURIError] if the URI is in a bad or unexpected state.
new
ruby
hopsoft/universalid
lib/uri/uid.rb
https://github.com/hopsoft/universalid/blob/master/lib/uri/uid.rb
MIT
def parse(payload, format: :json) case format # when :json then JSON.parse payload when :json then Oj.load payload else raise NotImplementedError end end
Parses a ActiveRecordETL transformed payload in the specified format @param payload [String] The tranformed payload to parse @param :format [Symbol] The data format to transform the record into (optional, defaults to :json) @return [Object] the parsed payload @raise [NotImplementedError] if the specified format is not supported
parse
ruby
hopsoft/universalid
test/rails_kit/models/active_record_etl.rb
https://github.com/hopsoft/universalid/blob/master/test/rails_kit/models/active_record_etl.rb
MIT
def initialize(record) @record = record end
Initializes a new ActiveRecord ETL Data Pipeline @param record [ActiveRecord] the record to ETL
initialize
ruby
hopsoft/universalid
test/rails_kit/models/active_record_etl.rb
https://github.com/hopsoft/universalid/blob/master/test/rails_kit/models/active_record_etl.rb
MIT
def associations(macro: nil) list = record.class.reflect_on_all_associations list = list.select { |a| a.macro == macro.to_sym } if macro list end
Returns a list of all the record's associations @param :macro [String, Symbol] (:belongs_to, :has_many, ... optional, defaults to nil) @return [Array<ActiveRecord::Reflection::AssociationReflection>]
associations
ruby
hopsoft/universalid
test/rails_kit/models/active_record_etl.rb
https://github.com/hopsoft/universalid/blob/master/test/rails_kit/models/active_record_etl.rb
MIT
def loaded_associations_by_name(macro: nil) associations(macro: macro).each_with_object({}) do |association, memo| collection_proxy = record.public_send(association.name) memo[association.name.to_s] = collection_proxy if collection_proxy.loaded? end end
Returns a the record's loaded associations by name @param :macro [String] (:belongs_to, :has_many, ... optional, defaults to nil) @return [Hash{String => ActiveRecord::Associations::CollectionProxy}]
loaded_associations_by_name
ruby
hopsoft/universalid
test/rails_kit/models/active_record_etl.rb
https://github.com/hopsoft/universalid/blob/master/test/rails_kit/models/active_record_etl.rb
MIT
def loaded_has_many_associations_by_name loaded_associations_by_name macro: :has_many end
Returns the record's loaded `has_many` associations by name @return [Hash{String => ActiveRecord::Associations::CollectionProxy}]
loaded_has_many_associations_by_name
ruby
hopsoft/universalid
test/rails_kit/models/active_record_etl.rb
https://github.com/hopsoft/universalid/blob/master/test/rails_kit/models/active_record_etl.rb
MIT
def loaded_nested_attribute_names nested_attribute_names & loaded_has_many_associations_by_name.keys end
Attribute names that the record `accepts_nested_attributes_for` that have been loaded into memory @return [Array<String>]
loaded_nested_attribute_names
ruby
hopsoft/universalid
test/rails_kit/models/active_record_etl.rb
https://github.com/hopsoft/universalid/blob/master/test/rails_kit/models/active_record_etl.rb
MIT
def parent_attribute_names record.class.reflections.each_with_object([]) do |(name, reflection), memo| memo << reflection.foreign_key if reflection.macro == :belongs_to end end
Attribute names for all the record's `belongs_to` associations @return [Array<String>]
parent_attribute_names
ruby
hopsoft/universalid
test/rails_kit/models/active_record_etl.rb
https://github.com/hopsoft/universalid/blob/master/test/rails_kit/models/active_record_etl.rb
MIT
def create(state) ::Kitchen::Terraform::Driver::Create.new( config: config, connection: transport.connection(state), logger: logger, version_requirement: version_requirement, workspace_name: workspace_name, ).call rescue => error action_failed.call message: error.message end
Creates a Test Kitchen instance by initializing the working directory and creating a test workspace. @param state [Hash] the mutable instance and driver state. @raise [Kitchen::ActionFailed] if the result of the action is a failure. @return [void]
create
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/driver/terraform.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/driver/terraform.rb
Apache-2.0
def destroy(state) ::Kitchen::Terraform::Driver::Destroy.new( config: config, connection: transport.connection(state.merge(environment: { "TF_WARN_OUTPUT_ERRORS" => "true" })), logger: logger, version_requirement: version_requirement, workspace_name: workspace_name, ).call rescue => error action_failed.call message: error.message end
Destroys a Test Kitchen instance by initializing the working directory, selecting the test workspace, deleting the state, selecting the default workspace, and deleting the test workspace. @param state [Hash] the mutable instance and driver state. @raise [Kitchen::ActionFailed] if the result of the action is a failure. @return [void]
destroy
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/driver/terraform.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/driver/terraform.rb
Apache-2.0
def doctor(state) errors = false deprecated_config.each_pair do |attribute, message| errors = true logger.warn "driver.#{attribute} is deprecated: #{message}" end methods.each do |method| next if !method.match? /doctor_config_.*/ config_error = send method errors = errors || config_error end transport_errors = transport.doctor state verifier_errors = instance.verifier.doctor state errors || transport_errors || verifier_errors end
doctor checks the system and configuration for common errors. @param state [Hash] the mutable Kitchen instance state. @return [Boolean] +true+ if any errors are found; +false+ if no errors are found.
doctor
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/driver/terraform.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/driver/terraform.rb
Apache-2.0
def finalize_config!(instance) super self.deprecated_config ||= {} transport = instance.transport self.transport = if ::Kitchen::Transport::Terraform == transport.class transport else ::Kitchen::Transport::Terraform.new(config).finalize_config! instance end self end
#finalize_config! invokes the super implementation and then initializes the strategies. @param instance [Kitchen::Instance] an associated instance. @raise [Kitchen::ClientError] if the instance is nil. @return [self]
finalize_config!
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/driver/terraform.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/driver/terraform.rb
Apache-2.0
def initialize(config = {}) super config self.action_failed = ::Kitchen::Terraform::Raise::ActionFailed.new logger: logger end
#initialize prepares a new instance of the class. @param config [Hash] the driver configuration. @return [Kitchen::Driver::Terraform]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/driver/terraform.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/driver/terraform.rb
Apache-2.0
def call(state) driver = instance.driver transport = driver.transport ::Kitchen::Terraform::Provisioner::Converge.new( config: driver.send(:config), connection: transport.connection({}), debug_connection: transport.connection(logger: ::Kitchen::Terraform::DebugLogger.new(logger)), logger: logger, version_requirement: version_requirement, workspace_name: workspace_name, ).call state: state rescue => error ::Kitchen::Terraform::Raise::ActionFailed.new(logger: logger).call message: error.message end
Converges a Test Kitchen instance. @param state [Hash] the mutable instance and provisioner state. @raise [Kitchen::ActionFailed] if the result of the action is a failure.
call
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/provisioner/terraform.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/provisioner/terraform.rb
Apache-2.0
def finalize_config!(instance) super instance self.version_requirement = ::Gem::Requirement.new ">= 0.11.4", "< 2.0.0" self.workspace_name = "kitchen-terraform-#{::Shellwords.escape instance.name}" end
#finalize_config! invokes the super implementation and then defines the workspace name and version requirement. @param instance [Kitchen::Instance] an associated instance. @raise [Kitchen::ClientError] if the instance is nil. @return [self]
finalize_config!
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/configurable.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/configurable.rb
Apache-2.0
def apply(config_attribute:) self.config_attribute = config_attribute define_singleton_included define_singleton_to_sym define_config_attribute_default_value self end
#apply applies the configuration attribute behaviour to a module. @param config_attribute [Module] a module. @return [self]
apply
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/config_attribute.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/config_attribute.rb
Apache-2.0
def initialize(attribute:, default_value:, schema:) self.attribute = attribute self.default_value = default_value self.schema = schema end
#initialize prepares a new instance of the class. @param attribute [Symbol] the name of the attribute. @param default_value [Proc] a block which returns the default value for the attribute. @param schema [Dry::Validation::Schema] the schema of the attribute.
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/config_attribute.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/config_attribute.rb
Apache-2.0
def define_cache(attribute_name: to_sym) define_method "config_#{attribute_name}" do instance_variable_defined? "@config_#{attribute_name}" and instance_variable_get "@config_#{attribute_name}" or instance_variable_set( "@config_#{attribute_name}", config.fetch(attribute_name) ) end end
Defines an instance method named "config_<attribute_name>" which caches the value of the configuration attribute lookup using an equivalently named instance variable. @param attribute_name [Symbol] the name of the attribute
define_cache
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/config_attribute_cacher.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/config_attribute_cacher.rb
Apache-2.0
def define(plugin_class:) plugin_class.required_config attribute do |_attribute, value, _plugin| process messages: schema.call(value: value).errors.to_h, plugin_class: plugin_class end plugin_class.default_config attribute do |plugin| plugin.send "config_#{attribute}_default_value" end self end
#define defines a configuration attribute on a plugin class. @param plugin_class [Kitchen::Configurable] a plugin class. @return [self]
define
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/config_attribute_definer.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/config_attribute_definer.rb
Apache-2.0
def initialize(attribute:, schema:) self.attribute = attribute.to_sym self.schema = schema end
#initialize prepares a new instance of the class. @param attribute [Kitchen::Terraform::ConfigAttribute] an attribute to be defined on a plugin class. @param schema [Dry::Validation::Schema] a schema to use for validation of values of the attribute. @return [Kitchen::Terraform::ConfigAttributeDefined]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/config_attribute_definer.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/config_attribute_definer.rb
Apache-2.0
def new(obj) if !obj.kind_of? ::Kitchen::Logger raise ::TypeError, "delegate must be a Kitchen::Logger; recevied #{obj.class}" end super end
.new creates a new instance of the class. @return [Kitchen::Terraform::DebugLogger]
new
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/debug_logger.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/debug_logger.rb
Apache-2.0
def define(plugin_class:) definer.define plugin_class: plugin_class plugin_class.expand_path_for attribute.to_sym self end
#define defines the file path configuration attribute on a plugin class. @param plugin_class [Kitchen::ConfigAttributeVerifier] a plugin class which has configuration attribute verification behaviour. @return [self]
define
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/file_path_config_attribute_definer.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/file_path_config_attribute_definer.rb
Apache-2.0
def initialize(attribute:, schema:) self.attribute = attribute self.definer = ::Kitchen::Terraform::ConfigAttributeDefiner.new attribute: attribute, schema: schema end
#initialize prepares a new instance of the class. @param attribute [Kitchen::Terraform::ConfigAttribute] an attribute to be defined on a plugin class. @param schema [Dry::Validation::Schema] a schema to use for validation of values of the attribute. @return [Kitchen::Terraform::FilePathConfigAttributeDefiner]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/file_path_config_attribute_definer.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/file_path_config_attribute_definer.rb
Apache-2.0
def build(options:, profile_locations:) if hosts.empty? ::Kitchen::Terraform::InSpec::WithoutHosts.new( options: options, profile_locations: profile_locations, ) elsif fail_fast ::Kitchen::Terraform::InSpec::FailFastWithHosts.new( hosts: hosts, options: options, profile_locations: profile_locations, ) else ::Kitchen::Terraform::InSpec::FailSlowWithHosts.new( hosts: hosts, options: options, profile_locations: profile_locations, ) end end
#build creates a new instance of an InSpec object. @param options [Hash] a mapping of InSpec options. @param profile_locations [Array<::String>] the locations of the InSpec profiles which contain the controls to be executed. @return [Kitchen::Terraform::InSpec::WithoutHosts, Kitchen::Terraform::InSpec::FailFastWithHosts, Kitchen::Terraform::InSpec::FailFastWithoutHosts]
build
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/inspec_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec_factory.rb
Apache-2.0
def initialize(fail_fast:, hosts:) self.fail_fast = fail_fast self.hosts = hosts end
#initialize prepares a new instance of the class @param fail_fast [Boolean] a toggle for fail fast or fail slow behaviour. @param hosts [Array<String>] a list of hosts to verify with InSpec. @return [Kitchen::Terraform::InSpecFactory]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/inspec_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec_factory.rb
Apache-2.0
def inputs_key if ::Gem::Requirement.new("< 4.3.2").satisfied_by? ::Gem::Version.new ::Inspec::VERSION :attributes else :inputs end end
#inputs_key provides a key for InSpec profile inputs which depends on the version of InSpec. @return [Symbol] if the version is less than 4.3.2, :attributes; else, :inputs.
inputs_key
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/inspec_options_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec_options_factory.rb
Apache-2.0
def build(attributes:, system_configuration_attributes:) map_system_to_inspec system_configuration_attributes: system_configuration_attributes options.store self.class.inputs_key, attributes resolve_bastion_host system_configuration_attributes: system_configuration_attributes options end
#build creates a mapping of InSpec options. Most key-value pairs are derived from the configuration attributes of a system; some key-value pairs are hard-coded. @param attributes [Hash] the attributes to be added to the InSpec options. @param system_configuration_attributes [Hash] the configuration attributes of a system. @raise [Kitchen::ClientError] if the system bastion host fails to be resolved. @return [Hash] a mapping of InSpec options.
build
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/inspec_options_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec_options_factory.rb
Apache-2.0
def initialize(outputs:) self.options = { "distinct_exit" => false } self.system_bastion_host_resolver = ::Kitchen::Terraform::SystemBastionHostResolver.new outputs: outputs self.system_inspec_map = ::Kitchen::Terraform::SYSTEM_INSPEC_MAP.dup end
#initialize prepares a new instance of the class. @param outputs [Hash] the Terraform output variables. @return [Kitchen::Terraform::InSpecOptionsFactory]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/inspec_options_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec_options_factory.rb
Apache-2.0
def exec run do |exit_code:| if 0 != exit_code raise ::Kitchen::TransientFailure, "#{action} failed due to a non-zero exit code of #{exit_code}." end end self end
#exec executes InSpec. @raise [Kitchen::TransientFailure] if the execution of InSpec fails. @return [self]
exec
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/inspec_runner.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec_runner.rb
Apache-2.0
def initialize(options:, profile_locations:) self.host = options.fetch :host do "" end ::Inspec::Plugin::V2::Loader.new.tap do |loader| loader.load_all loader.exit_on_load_error end self.runner = ::Inspec::Runner.new options.merge logger: ::Inspec::Log.logger profile_locations.each do |profile_location| runner.add_target profile_location end end
#initialize prepares a new instance of the class. @param options [Hash] options to configure the runner. @param profile_locations [Array<String>] a list of pathnames of profiles. @return [Kitchen::Terraform::InSpecRunner]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/inspec_runner.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec_runner.rb
Apache-2.0
def initialize self.state_key = :kitchen_terraform_outputs end
#initialize prepares a new instance of the class. @return [Kitchen::Terraform::OutputsManager]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/outputs_manager.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/outputs_manager.rb
Apache-2.0
def load(outputs:, state:) outputs.replace state.fetch state_key self rescue ::KeyError raise( ::Kitchen::ClientError, "Reading the Terraform output variables from the Kitchen instance state failed due to the absence of the " \ "'#{state_key}' key. This error could indicate that the Kitchen-Terraform provisioner plugin was not used " \ "to converge the Kitchen instance." ) end
#load reads the Terraform outputs from the Kitchen instance state and writes them to a container. @param outputs [Hash] the container to which the Terraform outputs will be written. @param state [Hash] the Kitchen instance state from which the Terraform outputs will be read. @return [self]
load
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/outputs_manager.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/outputs_manager.rb
Apache-2.0
def save(outputs:, state:) state.store state_key, outputs.dup self end
#save reads the Terraform outputs from container and writes them to the Kitchen instance state. @param outputs [Hash] the container from which the Terraform outputs will be read. @param state [Hash] the Kitchen instance state to which the Terraform outputs will be written. @return [self]
save
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/outputs_manager.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/outputs_manager.rb
Apache-2.0
def parse(json_outputs:) yield parsed_outputs: ::JSON.parse(json_outputs) self rescue ::JSON::ParserError raise ::Kitchen::TransientFailure, "Parsing the Terraform output variables as JSON failed." end
#parse parses the outputs. @param json_outputs [String] the output variables as a string of JSON. @raise [Kitchen::TransientFailure] if parsing the output variables fails. @yieldparam parsed_outputs [Hash] the output variables as a hash. @return [self]
parse
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/outputs_parser.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/outputs_parser.rb
Apache-2.0
def read(command:) json_outputs = "{}" begin json_outputs = connection.execute command rescue ::Kitchen::StandardError => error no_outputs_defined.match ::Regexp.escape error.original.to_s or raise ::Kitchen::TransientFailure, error.message end yield json_outputs: json_outputs self end
#read reads the output variables. @param command [Kitchen::Terraform::Command::Output] the output command. @raise [Kitchen::TransientFailure] if running the output command fails. @yieldparam json_outputs [String] the output variables as a string of JSON. @return [self]
read
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/outputs_reader.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/outputs_reader.rb
Apache-2.0
def initialize(connection:) self.connection = connection self.no_outputs_defined = /no\\ outputs\\ defined/ end
#initialize prepares a new instance of the class. @param connection [Kitchen::Terraform::Transport::Connection] a Terraform connection. @return [Kitchen::Terraform::OutputsReader]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/outputs_reader.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/outputs_reader.rb
Apache-2.0
def initialize(configuration_attributes:, logger:) self.attrs = {} self.attrs_outputs = configuration_attributes.fetch :attrs_outputs do {} end.dup self.configuration_attributes = configuration_attributes self.hosts = configuration_attributes.fetch :hosts do [] end.dup self.logger = logger end
#initialize prepares a new instance of the class. @param configuration_attributes [::Hash] a mapping of configuration attributes. @param logger [Kitchen::Logger] a logger to log messages. @option configuration_attributes [Hash{String=>String}] :attrs_outputs a mapping of InSpec attribute names to Terraform output names @option configuration_attributes [Array<String>] :hosts a list of static hosts in the system. @option configuration_attributes [String] :hosts_output the name of a Terraform output which contains one or more hosts in the system. @option configuration_attributes [String] :name the name of the system. @option configuration_attributes [Array<String>] :profile_locations a list of the locations of InSpec profiles. @return [Kitchen::Terraform::System]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/system.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/system.rb
Apache-2.0
def verify(fail_fast:, outputs:, variables:) resolve_and_execute fail_fast: fail_fast, outputs: outputs, variables: variables self rescue ::Kitchen::TransientFailure => error raise ::Kitchen::TransientFailure, "Verifying the '#{self}' system failed:\n\t#{error.message}" end
#verify verifies the system by executing InSpec. @param fail_fast [Boolean] a toggle to control the fast or slow failure of InSpec. @param outputs [Hash] the Terraform outputs to be utilized as InSpec profile attributes. @param variables [Hash] the Terraform variables to be utilized as InSpec profile attributes. @raise [Kitchen::ClientError, Kitchen::TransientFailure] if verifying the system fails. @return [self]
verify
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/system.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/system.rb
Apache-2.0
def build(systems:) if fail_fast ::Kitchen::Terraform::SystemsVerifier::FailFast.new systems: systems else ::Kitchen::Terraform::SystemsVerifier::FailSlow.new systems: systems end end
#build creates a SystemVerifier. @param systems [Array<::Kitchen::Terraform::System>] the Systems to be verified. @return [Kitchen::Terraform::SystemsVerifier::FailFast, ::Kitchen::Terraform::SystemsVerifier::FailSlow] a SystemsVerifier.
build
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/systems_verifier_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/systems_verifier_factory.rb
Apache-2.0
def initialize(fail_fast:) self.fail_fast = fail_fast end
#initialize prepares a new instance of the class. @param fail_fast [Boolean] a toggle to fail fast or fail slow. @return [Kitchen::Terraform::SystemsVerifierFactory]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/systems_verifier_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/systems_verifier_factory.rb
Apache-2.0
def initialize(attrs:) self.attrs = attrs end
#initialize prepares a new instance of the class. @param attrs [Hash] a container for attributes. @return [Kitchen::Terraform::SystemAttrsInputsResolver]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/system_attrs_inputs_resolver.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/system_attrs_inputs_resolver.rb
Apache-2.0
def resolve(inputs:) inputs.each_pair do |input_name, input_value| attrs.store "input_#{input_name}", input_value end self end
#resolve stores the inputs as attributes. @param inputs [Hash{String=>String}] the variables to be stored as inputs. @return self
resolve
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/system_attrs_inputs_resolver.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/system_attrs_inputs_resolver.rb
Apache-2.0
def initialize(attrs:) self.attrs = attrs end
#initialize prepares a new instance of the class. @param attrs [Hash] a container for attributes. @return [Kitchen::Terraform::SystemAttrsOutputsResolver]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/system_attrs_outputs_resolver.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/system_attrs_outputs_resolver.rb
Apache-2.0
def resolve(attrs_outputs:, outputs:) resolve_defaults outputs: outputs resolve_configuration attrs_outputs: attrs_outputs self end
#resolve fetches Terraform outputs and associates them with InSpec attributes. @param attrs_outputs [Hash{String=>String}] a mapping of InSpec attribute names to Terraform output names. @param outputs [Hash{String=>Hash}] Terraform outputs. @raise [Kitchen::ClientError] if the resolution fails. @return [self]
resolve
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/system_attrs_outputs_resolver.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/system_attrs_outputs_resolver.rb
Apache-2.0
def initialize(outputs:) self.outputs = Hash[outputs] end
#initialize prepares a new instance of the class. @param outputs [Hash] a map of Terraform output variables. @return [Kitchen::Terraform::SystemBastionHostResolver]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/system_bastion_host_resolver.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/system_bastion_host_resolver.rb
Apache-2.0
def resolve(bastion_host:, bastion_host_output:) if !bastion_host.empty? yield bastion_host: bastion_host elsif !bastion_host_output.empty? yield bastion_host: resolved_output(bastion_host_output: bastion_host_output).fetch(:value) end self rescue ::KeyError raise( ::Kitchen::ClientError, "Resolving the system bastion host failed due to the absence of the 'value' key from the " \ "'#{bastion_host_output}' Terraform output of the Kitchen instance state. This error indicates that the " \ "output format of `terraform output -json` is unexpected." ) end
#resolve resolves a bastion host from either the specified Terraform output or the static value. @param bastion_host [String] a statically defined host. @param bastion_host_output [String] the name of the Terraform output which contains a bastion host. @yieldparam bastion_host [String] the bastion host. @raise [Kitchen::ClientError] if the specified Terraform output is not found. @return [self]
resolve
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/system_bastion_host_resolver.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/system_bastion_host_resolver.rb
Apache-2.0
def initialize(outputs:) self.outputs = Hash[outputs] end
#initialize prepares a new instance of the class. @param outputs [Hash] a map of Terraform output variables. @return [Kitchen::Terraform::SystemHostsResolver]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/system_hosts_resolver.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/system_hosts_resolver.rb
Apache-2.0
def resolve(hosts:, hosts_output:) hosts.concat Array resolved_output(hosts_output: hosts_output).fetch :value self rescue ::KeyError raise( ::Kitchen::ClientError, "Resolving the system hosts failed due to the absence of the 'value' key from the '#{hosts_output}' " \ "Terraform output of the Kitchen instance state. This error indicates that the output format of " \ "`terraform output -json` is unexpected." ) end
#resolve reads the specified Terraform output and stores the value in a list of hosts. @param hosts [Array] the list of hosts. @param hosts_output [String] the name of the Terraform output which contains hosts. @raise [Kitchen::ClientError] if the specified Terraform output is not found. @return [self]
resolve
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/system_hosts_resolver.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/system_hosts_resolver.rb
Apache-2.0
def initialize self.state_key = :kitchen_terraform_variables end
#initialize prepares a new instance of the class. @return [Kitchen::Terraform::VariablesManager]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/variables_manager.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/variables_manager.rb
Apache-2.0
def load(variables:, state:) variables.replace state.fetch state_key self rescue ::KeyError => error raise( ::Kitchen::ClientError, "Reading the Terraform input variables from the Kitchen instance state failed due to the absence of the " \ "'#{state_key}' key. This error could indicate that the Kitchen-Terraform provisioner plugin was not used " \ "to converge the Kitchen instance." ) end
#load reads the Terraform variables from the Kitchen instance state and writes them to a container. @param variables [Hash] the container to which the Terraform variables will be written. @param state [Hash] the Kitchen instance state from which the Terraform variables will be read. @return [self]
load
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/variables_manager.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/variables_manager.rb
Apache-2.0
def save(variables:, state:) state.store state_key, variables self end
#save reads the Terraform variables from a container and writes them to the Kitchen instance state. @param variables [Hash] the container from which the Terraform variables will be read. @param state [Hash] the Kitchen instance state to which the Terraform variables will be written. @return [self]
save
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/variables_manager.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/variables_manager.rb
Apache-2.0
def call(version:) logger.warn start_message version_verifier.verify version: version logger.warn finish_message rescue ::Kitchen::Terraform::UnsupportedClientVersionError rescue_strategy.call self end
#call invokes the verification. @param version [Gem::Version] the Terraform client version. @raise [Kitchen::ActionFailed] if the verification fails. @return [self]
call
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/verify_version.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/verify_version.rb
Apache-2.0
def initialize(config:, logger:, version_requirement:) self.finish_message = "Finished verifying the Terraform client version." self.logger = logger self.rescue_strategy = ::Kitchen::Terraform::VerifyVersionRescueStrategyFactory.new( verify_version: config.fetch(:verify_version), ).build logger: logger self.start_message = "Verifying the Terraform client version is in the supported interval of " \ "#{version_requirement}..." self.version_verifier = ::Kitchen::Terraform::VersionVerifier.new version_requirement: version_requirement end
#initialize prepares a new instance of the class. @param config [Hash] the configuration of the driver. @param logger [Kitchen::Logger] a logger for logging messages. @param version_requirement [Gem::VersionRequirement] the required version of the Terraform client. @option config [Boolean] :verify_version a toggle of strict or permissive verification of support for the version of the Terraform client. @return [Kitchen::Terraform::VerifyVersion]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/verify_version.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/verify_version.rb
Apache-2.0
def build(logger:) if verify_version ::Kitchen::Terraform::VerifyVersionRescueStrategy::Strict.new else ::Kitchen::Terraform::VerifyVersionRescueStrategy::Permissive.new logger: logger end end
#build creates a strategy. @param logger [Kitchen::Logger] a logger to log messages. @return [Kitchen::Terraform::VerifyVersionRescueStrategy::Strict, Kitchen::Terraform::VerifyVersionRescueStrategy::Permissive]
build
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/verify_version_rescue_strategy_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/verify_version_rescue_strategy_factory.rb
Apache-2.0
def initialize(verify_version:) self.verify_version = verify_version end
#initialize prepares a new instance of the class. @param verify_version [Boolean] a toggle for a strict strategy or a permissive strategy. @return [Kitchen::Terraform::VerifyVersionRescueStrategyFactory]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/verify_version_rescue_strategy_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/verify_version_rescue_strategy_factory.rb
Apache-2.0
def assign_plugin_version(configurable_class:) configurable_class.plugin_version value.to_s self end
assign_plugin_version assigns the version to a class which includes Kitchen::Configurable. @param configurable_class [Kitchen::Configurable] the configurable class to which the version will be assigned. @return [self]
assign_plugin_version
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/version.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/version.rb
Apache-2.0
def assign_specification_version(specification:) specification.version = value self end
assign_specification_version assigns the version to a Gem::Specification. @param specification [Gem::Specification] the specification to which the version will be assigned. @return [self]
assign_specification_version
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/version.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/version.rb
Apache-2.0
def if_satisfies(requirement:) yield if ::Gem::Requirement.new(requirement).satisfied_by? value self end
if_satisfies yields control if the provided requirement is satisfied by the version. @param requirement [Gem::Requirement, ::String] the requirement to be satisfied by the version. @raise [Gem::Requirement::BadRequirementError] if the requirement is illformed. @return [self] @yield [] if the requirement is satisfied by the version.
if_satisfies
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/version.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/version.rb
Apache-2.0
def temporarily_override(version:) current_value = value self.value = version yield self.value = current_value self end
temporarily_override overrides the current version with the version provided, yields control, and then resets the version. @note temporarily_override must only be used in tests to validate version flow control logic. @raise [ArgumentError] if the version is malformed. @return [self] @yield [] the value of the version will be overridden while control is yielded.
temporarily_override
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/version.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/version.rb
Apache-2.0
def verify(version:) version_verifier_strategy_factory.build(version: version).call self end
#verify verifies a version against the requirement. @param version [Gem::Version] the Terraform client version. @raise [Kitchen::TransientFailure] if running the command fails. @raise [Kitchen::UserError] if the version is unsupported. @return [self]
verify
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/version_verifier.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/version_verifier.rb
Apache-2.0
def initialize(version_requirement:) self.version_verifier_strategy_factory = ::Kitchen::Terraform::VersionVerifierStrategyFactory.new( version_requirement: version_requirement, ) end
#initialize prepares a new instance of the class. @param version_requirement [Gem::Requirement] the requirement for version support. @return [Kitchen::Terraform::VersionVerifier]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/version_verifier.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/version_verifier.rb
Apache-2.0
def build(version:) if version_requirement.satisfied_by? version return ::Kitchen::Terraform::VersionVerifierStrategy::Supported.new else return ::Kitchen::Terraform::VersionVerifierStrategy::Unsupported.new end end
#build creates a strategy. @param version [Gem::Version] the Terraform client version. @return [Kitchen::Terraform::VersionVerifierStrategy::Supported, Kitchen::Terraform::VersionVerifierStrategy::Unsupported]
build
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/version_verifier_strategy_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/version_verifier_strategy_factory.rb
Apache-2.0
def initialize(version_requirement:) self.version_requirement = version_requirement end
#initialize prepares a new instance of the class. @param version_requirement [Gem::Requirement] the requirement for version support. @return [Kitchen::Terraform::VersionVerifierStrategyFactory]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/version_verifier_strategy_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/version_verifier_strategy_factory.rb
Apache-2.0
def initialize(config:) self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color) self.lock = config.fetch :lock self.lock_timeout = ::Kitchen::Terraform::CommandFlag::LockTimeout.new duration: config.fetch(:lock_timeout) self.parallelism = config.fetch :parallelism self.var_file = ::Kitchen::Terraform::CommandFlag::VarFile.new pathnames: config.fetch(:variable_files) self.var = ::Kitchen::Terraform::CommandFlag::Var.new arguments: config.fetch(:variables) end
#initialize prepares a new instance of the class. @param config [Hash] the configuration of the driver. @option config [Boolean] :color a toggle of colored output from the Terraform client. @option config [Boolean] :lock a toggle of locking for the Terraform state file. @option config [Integer] :lock_timeout the number of seconds that the Terraform client will wait for a lock on the state to be obtained during operations. @option config [Integer] :parallelism the number of concurrent operations to use while Terraform walks the resource graph. @option config [Array<String>] :variable_files a list of pathnames of Terraform variable files to evaluate. @option config [Hash{String=>String}] :variables a mapping of Terraform variables to evaluate. @return [Kitchen::Terraform::Command::Apply]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/apply.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/apply.rb
Apache-2.0
def to_s "apply " \ "-auto-approve " \ "-lock=#{lock} " \ "#{lock_timeout} " \ "-input=false " \ "#{color} " \ "-parallelism=#{parallelism} " \ "-refresh=true " \ "#{var} " \ "#{var_file}" end
@return [String] the command with flags.
to_s
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/apply.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/apply.rb
Apache-2.0
def initialize(config:) self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color) self.lock = config.fetch :lock self.lock_timeout = ::Kitchen::Terraform::CommandFlag::LockTimeout.new duration: config.fetch(:lock_timeout) self.parallelism = config.fetch :parallelism self.var_file = ::Kitchen::Terraform::CommandFlag::VarFile.new pathnames: config.fetch(:variable_files) self.var = ::Kitchen::Terraform::CommandFlag::Var.new arguments: config.fetch(:variables) end
#initialize prepares a new instance of the class. @param config [Hash] the configuration of the driver. @option config [Boolean] :color a toggle of colored output from the Terraform client. @option config [Boolean] :lock a toggle of locking for the Terraform state file. @option config [Integer] :lock_timeout the number of seconds that the Terraform client will wait for a lock on the state to be obtained during operations. @option config [Integer] :parallelism the number of concurrent operations to use while Terraform walks the resource graph. @option config [Array<String>] :variable_files a list of pathnames of Terraform variable files to evaluate. @option config [Hash{String=>String}] :variables a mapping of Terraform variables to evaluate. @return [Kitchen::Terraform::Command::Destroy]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/destroy.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/destroy.rb
Apache-2.0
def to_s "destroy " \ "-auto-approve " \ "-lock=#{lock} " \ "#{lock_timeout} " \ "-input=false " \ "#{color} " \ "-parallelism=#{parallelism} " \ "-refresh=true " \ "#{var} " \ "#{var_file}" end
@return [String] the command with flags.
to_s
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/destroy.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/destroy.rb
Apache-2.0
def to_s "get -update" end
@return [String] the command with flags.
to_s
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/get.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/get.rb
Apache-2.0
def build(config:) return ::Kitchen::Terraform::Command::Init::PreZeroFifteenZero.new config: config if requirement.satisfied_by? version ::Kitchen::Terraform::Command::Init::PostZeroFifteenZero.new config: config end
#build creates a new instance of an Init object. @param config [Hash] the configuration of the driver. @return [Kitchen::Terraform::Command::Init::PreZeroFifteenZero, Kitchen::Terraform::Command::Init::PostZeroFifteenZero]
build
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/init_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/init_factory.rb
Apache-2.0
def initialize(version:) self.requirement = ::Gem::Requirement.new "< 0.15.0" self.version = version end
#initialize prepares a new instance of the class @param version [Gem::Version] a client version. @return [Kitchen::Terraform::Command::InitFactory]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/init_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/init_factory.rb
Apache-2.0
def to_s "output -json" end
@return [String] the command with flags.
to_s
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/output.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/output.rb
Apache-2.0
def build(config:) if requirement.satisfied_by? version return ::Kitchen::Terraform::Command::Validate::PreZeroFifteenZero.new config: config end ::Kitchen::Terraform::Command::Validate::PostZeroFifteenZero.new config: config end
#build creates a new instance of an Validate object. @param config [Hash] the configuration of the driver. @return [Kitchen::Terraform::Command::Validate::PreZeroFifteenZero, Kitchen::Terraform::Command::Validate::PostZeroFifteenZero]
build
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/validate_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/validate_factory.rb
Apache-2.0
def initialize(version:) self.requirement = ::Gem::Requirement.new "< 0.15.0" self.version = version end
#initialize prepares a new instance of the class @param version [Gem::Version] a client version. @return [Kitchen::Terraform::Command::ValidateFactory]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/validate_factory.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/validate_factory.rb
Apache-2.0
def initialize(config:) self.workspace_name = config.fetch :workspace_name end
@param config [Hash] the configuration of the driver. @option config [String] :workspace_name the name of the Terraform workspace. @return [Kitchen::Terraform::Command::WorkspaceDelete]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/workspace_delete.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/workspace_delete.rb
Apache-2.0
def initialize(config:) self.workspace_name = config.fetch :workspace_name end
#initialize prepares a new instance of the class. @param config [Hash] the configuration of the driver. @option config [String] :workspace_name the name of the Terraform workspace. @return [Kitchen::Terraform::Command::WorkspaceNew]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/workspace_new.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/workspace_new.rb
Apache-2.0
def initialize(config:) self.workspace_name = config.fetch :workspace_name end
#initialize prepares a new instance of the class. @param config [Hash] the configuration of the driver. @option config [String] :workspace_name the name of the Terraform workspace. @return [Kitchen::Terraform::Command::WorkspaceSelect]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/workspace_select.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/workspace_select.rb
Apache-2.0
def initialize(config:) self.backend_config = ::Kitchen::Terraform::CommandFlag::BackendConfig.new arguments: config.fetch( :backend_configurations ) self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color) self.plugin_dir = ::Kitchen::Terraform::CommandFlag::PluginDir.new pathname: config.fetch( :plugin_directory ) self.upgrade = ::Kitchen::Terraform::CommandFlag::Upgrade.new enabled: config.fetch(:upgrade_during_init) end
#initialize prepares a new instance of the class. @param config [Hash] the configuration of the driver. @option config [Hash{String=>String}] :backend_configurations Terraform backend configuration arguments to complete a partial backend configuration. @option config [Boolean] :color a toggle of colored output from the Terraform client. on the state to be obtained during operations. @option config [String] :plugin_directory the pathname of the directory which contains customized Terraform provider plugins to install in place of the official Terraform provider plugins. @option config [Boolean] :upgrade_during_init a toggle for upgrading modules and plugins. @return [Kitchen::Terraform::Command::Init::PostZeroFifteenZero]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/init/post_zero_fifteen_zero.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/init/post_zero_fifteen_zero.rb
Apache-2.0
def to_s "init " \ "-backend=true " \ "#{backend_config} " \ "-force-copy=true " \ "-get=true " \ "-input=false " \ "#{color} " \ "#{plugin_dir} " \ "#{upgrade}" end
@return [String] the command with flags.
to_s
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/init/post_zero_fifteen_zero.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/init/post_zero_fifteen_zero.rb
Apache-2.0
def initialize(config:) self.backend_config = ::Kitchen::Terraform::CommandFlag::BackendConfig.new arguments: config.fetch( :backend_configurations ) self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color) self.lock = config.fetch :lock self.lock_timeout = ::Kitchen::Terraform::CommandFlag::LockTimeout.new duration: config.fetch(:lock_timeout) self.plugin_dir = ::Kitchen::Terraform::CommandFlag::PluginDir.new pathname: config.fetch( :plugin_directory ) self.upgrade = ::Kitchen::Terraform::CommandFlag::Upgrade.new enabled: config.fetch(:upgrade_during_init) end
#initialize prepares a new instance of the class. @param config [Hash] the configuration of the driver. @option config [Hash{String=>String}] :backend_configurations Terraform backend configuration arguments to complete a partial backend configuration. @option config [Boolean] :color a toggle of colored output from the Terraform client. @option config [Boolean] :lock a toggle of locking for the Terraform state file. @option config [Integer] :lock_timeout the number of seconds that the Terraform client will wait for a lock on the state to be obtained during operations. @option config [String] :plugin_directory the pathname of the directory which contains customized Terraform provider plugins to install in place of the official Terraform provider plugins. @option config [Boolean] :upgrade_during_init a toggle for upgrading modules and plugins. @return [Kitchen::Terraform::Command::Init::PreZeroFifteenZero]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/init/pre_zero_fifteen_zero.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/init/pre_zero_fifteen_zero.rb
Apache-2.0
def to_s "init " \ "-backend=true " \ "#{backend_config} " \ "-force-copy=true " \ "-get=true " \ "-get-plugins=true " \ "-input=false " \ "-lock=#{lock} " \ "#{lock_timeout} " \ "#{color} " \ "#{plugin_dir} " \ "#{upgrade} " \ "-verify-plugins=true" end
@return [String] the command with flags.
to_s
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/init/pre_zero_fifteen_zero.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/init/pre_zero_fifteen_zero.rb
Apache-2.0
def initialize(config:) self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color) end
#initialize prepares a new instance of the class. @param config [Hash] the configuration of the driver. @option config [Boolean] :color a toggle of colored output from the Terraform client. @return [Kitchen::Terraform::Command::Validate]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/validate/post_zero_fifteen_zero.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/validate/post_zero_fifteen_zero.rb
Apache-2.0
def to_s "validate " \ "#{color}" end
@return [String] the command with flags.
to_s
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/validate/post_zero_fifteen_zero.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/validate/post_zero_fifteen_zero.rb
Apache-2.0
def initialize(config:) self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color) self.var_file = ::Kitchen::Terraform::CommandFlag::VarFile.new pathnames: config.fetch(:variable_files) self.var = ::Kitchen::Terraform::CommandFlag::Var.new arguments: config.fetch(:variables) end
#initialize prepares a new instance of the class. @param config [Hash] the configuration of the driver. @option config [Boolean] :color a toggle of colored output from the Terraform client. @option config [Array<String>] :variable_files a list of pathnames of Terraform variable files to evaluate. @option config [Hash{String=>String}] :variables a mapping of Terraform variables to evaluate. @return [Kitchen::Terraform::Command::Validate]
initialize
ruby
newcontext-oss/kitchen-terraform
lib/kitchen/terraform/command/validate/pre_zero_fifteen_zero.rb
https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/validate/pre_zero_fifteen_zero.rb
Apache-2.0