How to use version method of Inspec.Backend.Base Package

Best Inspec_ruby code snippet using Inspec.Backend.Base.version

inspec_spec.rb

Source:inspec_spec.rb Github

copy

Full Screen

...70 end71 let(:verifier) do72 Kitchen::Verifier::Inspec.new(config).finalize_config!(instance)73 end74 it "verifier api_version is 1" do75 expect(verifier.diagnose_plugin[:api_version]).to eq(1)76 end77 it "plugin_version is set to Kitchen::Verifier::INSPEC_VERSION" do78 expect(verifier.diagnose_plugin[:version])79 .to eq(Kitchen::Verifier::INSPEC_VERSION)80 end81 describe "configuration" do82 let(:transport) do83 Kitchen::Transport::Ssh.new({})84 end85 it "supports reporter config platform and suite replacements" do86 config = verifier.send(:runner_options, transport, {}, "osx", "internal")87 expected_value = [88 "cli",89 "junit:path/to/results/osx_internal_inspec.xml",90 ]91 expect(config.to_hash).to include("reporter" => expected_value)92 end...

Full Screen

Full Screen

inspec.rb

Source:inspec.rb Github

copy

Full Screen

...17# See the License for the specific language governing permissions and18# limitations under the License.19require "kitchen/transport/ssh"20require "kitchen/transport/winrm"21require "kitchen/verifier/inspec_version"22require "kitchen/verifier/base"23require "uri"24require "pathname"25require "hashie"26require "inspec/plugin/v2"27module Kitchen28 module Verifier29 # InSpec verifier for Kitchen.30 #31 # @author Fletcher Nichol <fnichol@chef.io>32 class Inspec < Kitchen::Verifier::Base # rubocop:disable Metrics/ClassLength33 kitchen_verifier_api_version 134 plugin_version Kitchen::Verifier::INSPEC_VERSION35 # Chef InSpec is based on RSpec, which is not thread safe36 # (https://github.com/rspec/rspec-core/issues/1254)37 # Tell test kitchen not to multithread the verify step38 no_parallel_for :verify39 default_config :inspec_tests, []40 default_config :load_plugins, true41 default_config :plugin_config, {}42 default_config :backend_cache, true43 # A lifecycle method that should be invoked when the object is about44 # ready to be used. A reference to an Instance is required as45 # configuration dependant data may be access through an Instance. This46 # also acts as a hook point where the object may wish to perform other47 # last minute checks, validations, or configuration expansions.48 #49 # @param instance [Instance] an associated instance50 # @return [self] itself, for use in chaining51 # @raise [ClientError] if instance parameter is nil52 def finalize_config!(instance)53 super54 # We want to switch kitchen-inspec to look for its tests in55 # `cookbook_dir/test/recipes` instead of `cookbook_dir/test/integration`56 # Unfortunately there is no way to read `test_base_path` from the57 # .kitchen.yml, it can only be provided on the CLI.58 # See https://github.com/test-kitchen/test-kitchen/issues/107759 inspec_test_dir = File.join(config[:kitchen_root], "test", "recipes")60 if File.directory?(inspec_test_dir)61 config[:test_base_path] = inspec_test_dir62 end63 self64 end65 # (see Base#call)66 def call(state)67 logger.debug("Initialize InSpec")68 # gather connection options69 opts = runner_options(instance.transport, state, instance.platform.name, instance.suite.name)70 logger.debug "Options #{opts.inspect}"71 # add inputs and waivers72 setup_inputs(opts, config)73 setup_waivers(opts, config)74 # setup Inspec75 ::Inspec::Log.init(STDERR)76 ::Inspec::Log.level = Kitchen::Util.from_logger_level(logger.level)77 load_plugins # Must load plugins prior to config validation78 inspec_config = ::Inspec::Config.new(opts)79 # handle plugins80 setup_plugin_config(inspec_config)81 # initialize runner82 runner = ::Inspec::Runner.new(inspec_config)83 # add each profile to runner84 tests = collect_tests85 profile_ctx = nil86 tests.each do |target|87 profile_ctx = runner.add_target(target)88 end89 profile_ctx ||= []90 profile_ctx.each do |profile|91 logger.info("Loaded #{profile.name} ")92 end93 exit_code = runner.run94 # 101 is a success as well (exit with no fails but has skipped controls)95 return if exit_code == 0 || exit_code == 10196 raise ActionFailed, "InSpec Runner returns #{exit_code}"97 end98 private99 def setup_waivers(opts, config)100 # InSpec expects the singular inflection101 opts[:waiver_file] = config[:waiver_files] || []102 end103 def setup_inputs(opts, config)104 inspec_version = Gem::Version.new(::Inspec::VERSION)105 # Handle input files106 if config[:attrs]107 logger.warn("kitchen-inspec: please use 'input-files' instead of 'attrs'")108 config[:input_files] = config[:attrs]109 end110 if config[:input_files]111 # Note that inspec expects the singular inflection, input_file112 files_key = inspec_version >= Gem::Version.new("3.10") ? :input_file : :attrs113 opts[files_key] = config[:input_files]114 end115 # Handle YAML => Hash inputs116 if config[:attributes]117 logger.warn("kitchen-inspec: please use 'inputs' instead of 'attributes'")118 config[:inputs] = config[:attributes]119 end120 if config[:inputs]121 # Version here is dependent on https://github.com/inspec/inspec/issues/3856122 inputs_key = inspec_version >= Gem::Version.new("4.10") ? :inputs : :attributes123 opts[inputs_key] = Hashie.stringify_keys config[:inputs]124 end125 end126 def load_plugins127 return unless config[:load_plugins]128 v2_loader = ::Inspec::Plugin::V2::Loader.new129 v2_loader.load_all130 v2_loader.exit_on_load_error131 # Suppress input caching or all suites will get identical inputs, not different ones132 if ::Inspec::InputRegistry.instance.respond_to?(:cache_inputs=) && config[:cache_inputs]133 ::Inspec::InputRegistry.instance.cache_inputs = !!config[:cache_inputs]134 end135 end136 def setup_plugin_config(inspec_config)137 return unless config[:load_plugins]138 unless inspec_config.respond_to?(:merge_plugin_config)139 logger.warn("kitchen-inspec: skipping `plugin_config` which requires InSpec version 4.26.2 or higher. Your version: #{::Inspec::VERSION}")140 return141 end142 config[:plugin_config].each do |plugin_name, plugin_config|143 inspec_config.merge_plugin_config(plugin_name, plugin_config)144 end145 end146 # (see Base#load_needed_dependencies!)147 def load_needed_dependencies!148 require "inspec"149 # TODO: this should be easier. I would expect to load a single class here150 # load supermarket plugin, this is part of the inspec gem151 require "bundles/inspec-supermarket/api"152 require "bundles/inspec-supermarket/target"153 # load the compliance plugin154 require "bundles/inspec-compliance/configuration"155 require "bundles/inspec-compliance/support"156 require "bundles/inspec-compliance/http"157 require "bundles/inspec-compliance/api"158 require "bundles/inspec-compliance/target"159 end160 # Returns an Array of test suite filenames for the related suite currently161 # residing on the local workstation. Any special provisioner-specific162 # directories (such as a Chef roles/ directory) are excluded.163 #164 # we support the base directories165 # - test/integration166 # - test/integration/inspec (preferred if used with other test environments)167 #168 # we do not filter for specific directories, this is core of inspec169 #170 # @return [Array<String>] array of suite directories171 # @api private172 def local_suite_files173 base = File.join(config[:test_base_path], config[:suite_name])174 legacy_mode = false175 # check for testing frameworks, we may need to add more176 %w{inspec serverspec bats pester rspec cucumber minitest bash}.each do |fw|177 if Pathname.new(File.join(base, fw)).exist?178 logger.info("Detected alternative framework tests for `#{fw}`")179 legacy_mode = true180 end181 end182 base = File.join(base, "inspec") if legacy_mode183 # only return the directory if it exists184 Pathname.new(base).exist? ? [{ path: base }] : []185 end186 # Takes config[:inspec_tests] and modifies any value with a key of :path by adding the full path187 # @return [Array] array of modified hashes188 # @api private189 def resolve_config_inspec_tests190 config[:inspec_tests].map do |test_item|191 if test_item.is_a?(Hash)192 # replace the "path" key with an absolute path193 test_item[:path] = File.expand_path(test_item[:path]) if test_item.key?(:path)194 # delete any unnecessary keys to ensure deduplication in #collect_tests isn't195 # foiled by extra stuff. However, if the only entry is a "name" key, then196 # leave it alone so it can default to resolving to the Supermarket.197 unless test_item.keys == [:name]198 type_keys = [:path, :url, :git, :compliance, :supermarket]199 git_keys = [:branch, :tag, :ref, :relative_path]200 supermarket_keys = [:supermarket_url]201 test_item.delete_if { |k, v| !(type_keys + git_keys + supermarket_keys).include?(k) }202 end203 elsif File.exist?(test_item)204 # if the entry is a path to something on disk, rewrite as a Hash entry with a path key.205 # This is necessary to ensure that auto-detected local suite files found with206 # #local_suite_files are de-duplicated with relative path entries supplied by the user207 # in the inspec_tests array.208 #209 # If the path doesn't exist, it could be a URL, or it could simply be an error.210 # We will let it fall through and let InSpec raise the appropriate exception.211 test_item = { path: File.expand_path(test_item) }212 end213 test_item unless test_item.nil? || test_item.empty?214 end215 end216 # Returns an array of test profiles217 # @return [Array<String>] array of suite directories or remote urls218 # @api private219 def collect_tests220 # get local tests and get run list of profiles221 (local_suite_files + resolve_config_inspec_tests).compact.uniq222 end223 # Returns a configuration Hash that can be passed to a `Inspec::Runner`.224 #225 # @return [Hash] a configuration hash of string-based keys226 # @api private227 def runner_options(transport, state = {}, platform = nil, suite = nil) # rubocop:disable Metrics/AbcSize228 transport_data = transport.diagnose.merge(state)229 if respond_to?("runner_options_for_#{transport.name.downcase}", true)230 send("runner_options_for_#{transport.name.downcase}", transport_data)231 else232 raise Kitchen::UserError, "Verifier #{name} does not support the #{transport.name} Transport"233 end.tap do |runner_options|234 # default color to true to match InSpec behavior235 runner_options["color"] = (config[:color].nil? ? true : config[:color])236 runner_options["format"] = config[:format] unless config[:format].nil?237 runner_options["output"] = config[:output] % { platform: platform, suite: suite } unless config[:output].nil?238 runner_options["profiles_path"] = config[:profiles_path] unless config[:profiles_path].nil?239 runner_options["reporter"] = config[:reporter].map { |s| s % { platform: platform, suite: suite } } unless config[:reporter].nil?240 runner_options[:controls] = config[:controls]241 # check to make sure we have a valid version for caching242 if config[:backend_cache]243 runner_options[:backend_cache] = config[:backend_cache]244 else245 # default to false until we default to true in inspec246 runner_options[:backend_cache] = false247 end248 end249 end250 # Returns a configuration Hash that can be passed to a `Inspec::Runner`.251 #252 # @return [Hash] a configuration hash of string-based keys253 # @api private254 def runner_options_for_ssh(config_data)255 kitchen = instance.transport.send(:connection_options, config_data).dup...

Full Screen

Full Screen

helpers.rb

Source:helpers.rb Github

copy

Full Screen

...235def get_saltstack_package_full_name(package)236 # pillar = YAML.safe_load(File.read('test/salt/pillar/windows.sls'))237 url = 'https://raw.githubusercontent.com/saltstack/salt-winrepo-ng/master/'238 files = [package + '.sls', package + '/init.sls']239 # example: package = "7zip"=>{"version"=>"18.06.00.0", "refresh_minion_env_path"=>false}240 saltstack_package_full_name = files.find do |checkme|241 ps = "$f = (((Get-ChildItem -Path $env:LOCALAPPDATA -Filter 'salt-winrepo-ng' -Recurse -Directory).Fullname[0]) + '\\#{checkme.sub('/', '\\')}'); if (Test-Path $f -PathType Leaf) {Get-Content -Path $f}"242 begin243 file = (open(url + checkme) & :read)244 rescue245 begin246 file = (powershell(ps).stdout)247 rescue248 next249 end250 end251 unless file.nil? || file.empty?252 candidate = file.match(/full_name: '([\S]+).*'/).captures[0]253 end...

Full Screen

Full Screen

version

Using AI Code Generation

copy

Full Screen

1 class MyResource < Inspec.resource(1)2 class MyResource < Inspec.resource(1)3 class MyResource < Inspec.resource(1)4 class MyResource < Inspec.resource(1)5 class MyResource < Inspec.resource(1)6 Inspec::Backend::Base.new.send(:version)7 class MyResource < Inspec.resource(1)8 Inspec::Backend::Base.new.send(:version)

Full Screen

Full Screen

version

Using AI Code Generation

copy

Full Screen

1describe file('/tmp/testfile') do2 it { should exist }3describe file('/tmp/testfile') do4 it { should exist }5describe file('/tmp/testfile') do6 it { should exist }7describe file('/tmp/testfile') do8 it { should exist }9describe file('/tmp/testfile') do10 it { should exist }11describe file('/tmp/testfile') do12 it { should exist }13describe file('/tmp/testfile') do14 it { should exist }15describe file('/tmp/testfile') do16 it { should exist }17describe file('/tmp/testfile') do18 it { should exist }19describe file('/tmp/testfile') do20 it { should exist }21describe file('/tmp/testfile') do22 it { should exist }23describe file('/tmp/testfile') do24 it { should exist }25describe file('/tmp/testfile') do26 it { should exist }27describe file('/tmp/testfile') do28 it { should exist }29describe file('/tmp/testfile') do30 it { should exist }31describe file('/tmp/testfile') do32 it { should exist }33describe file('/tmp/testfile') do34 it { should exist }35describe file('/tmp/testfile') do36 it { should exist }37describe file('/tmp/testfile') do38 it { should exist }39describe file('/tmp/testfile') do40 it { should exist }41describe file('/tmp/testfile') do42 it { should exist }

Full Screen

Full Screen

version

Using AI Code Generation

copy

Full Screen

1 its('version') { should eq '1.2.3' }2 its('class.version') { should eq '1.2.3' }3 its('class.instance.version') { should eq '1.2.3' }4 its('class.instance.class.version') { should eq '1.2.3' }5 its('class.instance.class.instance.version') { should eq '1.2.3' }6 its('class.instance.class.instance.class.version') { should eq '1.2.3' }7 its('class.instance.class.instance.class.instance.version') { should eq '1.2.3' }8 its('class.instance.class.instance.class.instance.class.version') { should eq '1.2.3' }

Full Screen

Full Screen

version

Using AI Code Generation

copy

Full Screen

1describe file('/tmp/testfile') do2 it { should exist }3describe file('/tmp/testfile') do4 it { should exist }5describe file('/tmp/testfile') do6 it { should exist }7describe file('/tmp/testfile') do8 it { should exist }9describe file('/tmp/testfile') do10 it { should exist }11describe file('/tmp/testfile') do12 it { should exist }13describe file('/tmp/testfile') do14 it { should exist }15describe file('/tmp/testfile') do16 it { should exist }17describe file('/tmp/testfile') do18 it { should exist }19describe file('/tmp/testfile') do20 it { should exist }21describe file('/tmp/testfile') do22 it { should exist }23describe file('/tmp/testfile') do24 it { should exist }25describe file('/tmp/testfile') do26 it { should exist }27describe file('/tmp/testfile') do28 it { should exist }29describe file('/tmp/testfile') do30 it { should exist }31describe file('/tmp/testfile') do32 it { should exist }33describe file('/tmp/testfile') do34 it { should exist }35describe file('/tmp/testfile') do36 it { should exist }37describe file('/tmp/testfile') do38 it { should exist }39describe file('/tmp/testfile') do40 it { should exist }41describe file('/tmp/testfile') do42 it { should exist }

Full Screen

Full Screen

version

Using AI Code Generation

copy

Full Screen

1 its('version') { should eq '1.2.3' }2 its('class.version') { should eq '1.2.3' }3 its('class.instance.version') { should eq '1.2.3' }4 its('class.instance.class.version') { should eq '1.2.3' }5 its('class.instance.class.instance.version') { should eq '1.2.3' }6 its('class.instance.class.instance.class.version') { should eq '1.2.3' }7 its('class.instance.class.instance.class.instance.version') { should eq '1.2.3' }8 its('class.instance.class.instance.class.instance.class.version') { should eq '1.2.3' }

Full Screen

Full Screen

version

Using AI Code Generation

copy

Full Screen

1 class MyResource < Inspec.resource(1)2 class MyResource < Inspec.resource(1)3 class MyResource < Inspec.resource(1)4 class MyResource < Inspec.resource(1)5 class MyResource < Inspec.resource(1)6 Inspec::Backend::Base.new.send(:version)7 class MyResource < Inspec.resource(1)8 Inspec::Backend::Base.new.send(:version)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Inspec_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful