How to use load_inputs method of Inspec Package

Best Inspec_ruby code snippet using Inspec.load_inputs

runner.rb

Source:runner.rb Github

copy

Full Screen

...51 RunnerRspec.new(@conf)52 end53 # list of profile inputs54 @inputs = {}55 load_inputs(@conf)56 configure_transport57 end58 def tests59 @test_collector.tests60 end61 def configure_transport62 @backend = Inspec::Backend.create(@conf)63 @test_collector.backend = @backend64 end65 def reset66 @test_collector.reset67 @target_profiles.each do |profile|68 profile.runner_context.rules = {}69 end70 @rules = []71 end72 def load73 all_controls = []74 @target_profiles.each do |profile|75 @test_collector.add_profile(profile)76 next unless profile.supports_platform?77 write_lockfile(profile) if @create_lockfile78 profile.locked_dependencies79 profile_context = profile.load_libraries80 profile_context.dependencies.list.values.each do |requirement|81 unless requirement.profile.supports_platform?82 Inspec::Log.warn "Skipping profile: '#{requirement.profile.name}'" \83 " on unsupported platform: '#{@backend.platform.name}/#{@backend.platform.release}'."84 next85 end86 @test_collector.add_profile(requirement.profile)87 end88 @inputs = profile.runner_context.inputs if @inputs.empty?89 tests = profile.collect_tests90 all_controls += tests unless tests.nil?91 end92 all_controls.each do |rule|93 register_rule(rule) unless rule.nil?94 end95 end96 def run(with = nil)97 Inspec::Log.debug "Starting run with targets: #{@target_profiles.map(&:to_s)}"98 load99 run_tests(with)100 end101 def render_output(run_data)102 return if @conf['reporter'].nil?103 @conf['reporter'].each do |reporter|104 result = Inspec::Reporters.render(reporter, run_data)105 raise Inspec::ReporterError, "Error generating reporter '#{reporter[0]}'" if result == false106 end107 end108 def report109 Inspec::Reporters.report(@conf['reporter'].first, @run_data)110 end111 def write_lockfile(profile)112 return false if !profile.writable?113 if profile.lockfile_exists?114 Inspec::Log.debug "Using existing lockfile #{profile.lockfile_path}"115 else116 Inspec::Log.debug "Creating lockfile: #{profile.lockfile_path}"117 lockfile = profile.generate_lockfile118 File.write(profile.lockfile_path, lockfile.to_yaml)119 end120 end121 def run_tests(with = nil)122 @run_data = @test_collector.run(with)123 # dont output anything if we want a report124 render_output(@run_data) unless @conf['report']125 @test_collector.exit_code126 end127 # determine all inputs before the execution, fetch data from secrets backend128 def load_inputs(options)129 # TODO: - rename :attributes - it is user-visible130 options[:attributes] ||= {}131 if options.key?(:attrs)132 Inspec.deprecate(:rename_attributes_to_inputs, 'Use --input-file on the command line instead of --attrs.')133 options[:input_file] = options.delete(:attrs)134 end135 secrets_targets = options[:input_file]136 return options[:attributes] if secrets_targets.nil?137 secrets_targets.each do |target|138 validate_inputs_file_readability!(target)139 secrets = Inspec::SecretsBackend.resolve(target)140 if secrets.nil?141 raise Inspec::Exceptions::SecretsBackendNotFound,142 "Cannot find parser for inputs file '#{target}'. " \...

Full Screen

Full Screen

runner_test.rb

Source:runner_test.rb Github

copy

Full Screen

1# encoding: utf-82# copyright: 2017, Chef Software Inc.3require 'helper'4describe Inspec::Runner do5 describe '#load_inputs' do6 let(:runner) { Inspec::Runner.new({ command_runner: :generic }) }7 before do8 Inspec::Runner.any_instance.stubs(:validate_inputs_file_readability!)9 end10 describe 'confirm reporter defaults to cli' do11 it 'defaults to cli when format and reporter not set' do12 opts = { command_runner: :generic, backend_cache: true }13 runner = Inspec::Runner.new(opts)14 config = runner.instance_variable_get(:"@conf")15 expected = { 'cli' => { 'stdout' => true } }16 config['reporter'].must_equal expected17 end18 it 'does not default when format is set' do19 opts = { command_runner: :generic, backend_cache: true, 'reporter' => ['json'] }20 runner = Inspec::Runner.new(opts)21 config = runner.instance_variable_get(:"@conf")22 expected = { 'json' => { 'stdout' => true } }23 config['reporter'].must_equal expected24 end25 it 'delets format if set to a rspec format' do26 opts = { command_runner: :generic, backend_cache: true, 'reporter' => ['progress'] }27 runner = Inspec::Runner.new(opts)28 config = runner.instance_variable_get(:"@conf")29 config['reporter'].must_equal Hash.new30 end31 end32 describe 'testing runner.run exit codes' do33 it 'returns proper exit code when no profile is added' do34 proc { runner.run.must_equal 0 }35 end36 end37 describe 'when backend caching is enabled' do38 it 'returns a backend with caching' do39 opts = { command_runner: :generic, backend_cache: true }40 runner = Inspec::Runner.new(opts)41 backend = runner.instance_variable_get(:@backend)42 backend.backend.cache_enabled?(:command).must_equal true43 end44 end45 describe 'when backend caching is disabled' do46 it 'returns a backend without caching' do47 opts = { command_runner: :generic, backend_cache: false }48 runner = Inspec::Runner.new(opts)49 backend = runner.instance_variable_get(:@backend)50 backend.backend.cache_enabled?(:command).must_equal false51 end52 it 'returns a backend without caching as default' do53 backend = runner.instance_variable_get(:@backend)54 backend.backend.cache_enabled?(:command).must_equal false55 end56 end57 describe 'when no input files are specified' do58 it 'returns an empty hash' do59 options = {}60 runner.load_inputs(options).must_equal({})61 end62 end63 describe 'when an input file is provided and does not resolve' do64 it 'raises an exception' do65 options = { input_file: ['nope.jpg'] }66 Inspec::SecretsBackend.expects(:resolve).with('nope.jpg').returns(nil)67 proc { runner.load_inputs(options) }.must_raise Inspec::Exceptions::SecretsBackendNotFound68 end69 end70 describe 'when an input file is provided and has no inputs' do71 it 'returns an empty hash' do72 secrets = mock73 secrets.stubs(:inputs).returns(nil)74 options = { input_file: ['empty.yaml'] }75 Inspec::SecretsBackend.expects(:resolve).with('empty.yaml').returns(secrets)76 runner.load_inputs(options).must_equal({})77 end78 end79 describe 'when an input file is provided and has inputs' do80 it 'returns a hash containing the inputs' do81 options = { input_file: ['file1.yaml'] }82 inputs = { foo: 'bar' }83 secrets = mock84 secrets.stubs(:inputs).returns(inputs)85 Inspec::SecretsBackend.expects(:resolve).with('file1.yaml').returns(secrets)86 runner.load_inputs(options).must_equal(inputs)87 end88 end89 describe 'when multiple input files are provided and one fails' do90 it 'raises an exception' do91 options = { input_file: ['file1.yaml', 'file2.yaml'] }92 secrets = mock93 secrets.stubs(:inputs).returns(nil)94 Inspec::SecretsBackend.expects(:resolve).with('file1.yaml').returns(secrets)95 Inspec::SecretsBackend.expects(:resolve).with('file2.yaml').returns(nil)96 proc { runner.load_inputs(options) }.must_raise Inspec::Exceptions::SecretsBackendNotFound97 end98 end99 describe 'when multiple input files are provided and one has no inputs' do100 it 'returns a hash containing the inputs from the valid files' do101 options = { input_file: ['file1.yaml', 'file2.yaml'] }102 inputs = { foo: 'bar' }103 secrets1 = mock104 secrets1.stubs(:inputs).returns(nil)105 secrets2 = mock106 secrets2.stubs(:inputs).returns(inputs)107 Inspec::SecretsBackend.expects(:resolve).with('file1.yaml').returns(secrets1)108 Inspec::SecretsBackend.expects(:resolve).with('file2.yaml').returns(secrets2)109 runner.load_inputs(options).must_equal(inputs)110 end111 end112 describe 'when multiple input files are provided and all have inputs' do113 it 'returns a hash containing all the inputs' do114 options = { input_file: ['file1.yaml', 'file2.yaml'] }115 secrets1 = mock116 secrets1.stubs(:inputs).returns({ key1: 'value1' })117 secrets2 = mock118 secrets2.stubs(:inputs).returns({ key2: 'value2' })119 Inspec::SecretsBackend.expects(:resolve).with('file1.yaml').returns(secrets1)120 Inspec::SecretsBackend.expects(:resolve).with('file2.yaml').returns(secrets2)121 runner.load_inputs(options).must_equal({ key1: 'value1', key2: 'value2' })122 end123 end124 end125end...

Full Screen

Full Screen

load_inputs

Using AI Code Generation

copy

Full Screen

1Inspec::InputRegistry.load_inputs('inputs.yml')2 describe file('/etc/hosts') do3 it { should exist }4 describe file('/etc/hosts') do5 it { should exist }6 describe file('/etc/hosts') do7 it { should exist }8Inspec::InputRegistry.load_inputs('inputs.yml')9 describe file('/etc/hosts') do10 it { should exist }11 describe file('/etc/hosts') do12 it { should exist }13 describe file('/etc/hosts') do14 it { should exist }15Inspec::InputRegistry.load_inputs('inputs.yml')16 describe file('/etc/hosts') do17 it { should exist }

Full Screen

Full Screen

load_inputs

Using AI Code Generation

copy

Full Screen

1inputs = Inspec.load_inputs('inputs.yml')2 it { should eq 'redhat' }3inputs = Inspec.load('inputs.yml')4 it { should eq 'redhat' }

Full Screen

Full Screen

load_inputs

Using AI Code Generation

copy

Full Screen

1 describe input('input1') do2 it { should eq 'value1' }3 describe input('input2') do4 it { should eq 'value2' }

Full Screen

Full Screen

load_inputs

Using AI Code Generation

copy

Full Screen

1inputs = Inspec.load_inputs('inputs.yml')2inputs = Inspec.load_inputs({ 'my_input' => 'my_value', 'my_input2' => 'my_value2' })3inputs = Inspec.load_inputs('inputs.json')4{5 {6 },7 {8 }9}10inputs = Inspec.load_inputs('{"inputs": [{"name": "my_input", "value": "my_value"}, {"name": "my_input2", "value": "my_value2"}]}')11inputs = Inspec.load_inputs('inputs.json')12{13 {

Full Screen

Full Screen

load_inputs

Using AI Code Generation

copy

Full Screen

1 describe file('/etc/hosts') do2 describe file('/etc/hosts') do3 describe file('/etc/hosts') do4 describe file('/etc/hosts') do5 describe file('/etc/hosts') do6 describe file('/etc/hosts') do7 it { should exist }8 describe file('/etc/hosts') do9 it { should exist }10Inspec::InputRegistry.load_inputs('inputs.yml')11 describe file('/etc/hosts') do12 it { should exist }

Full Screen

Full Screen

load_inputs

Using AI Code Generation

copy

Full Screen

1 describe input('input1') do2 it { should eq 'value1' }3 describe input('input2') do4 it { should eq 'value2' }

Full Screen

Full Screen

load_inputs

Using AI Code Generation

copy

Full Screen

1inputs = Inspec.load_inputs('inputs.yml')2inputs = Inspec.load_inputs({ 'my_input' => 'my_value', 'my_input2' => 'my_value2' })3inputs = Inspec.load_inputs('inputs.json')4{5 {6 },7 {8 }9}10inputs = Inspec.load_inputs('{"inputs": [{"name": "my_input", "value": "my_value"}, {"name": "my_input2", "value": "my_value2"}]}')11inputs = Inspec.load_inputs('inputs.json')12{13 {

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.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful