How to use resolve method of Fetchers Package

Best Inspec_ruby code snippet using Fetchers.resolve

url_test.rb

Source:url_test.rb Github

copy

Full Screen

...26 @mock_logger.verify27 end28 it 'handles a http url' do29 url = 'http://chef.io/some.tar.gz'30 res = Fetchers::Url.resolve(url)31 res.expects(:open).returns(mock_open)32 _(res).must_be_kind_of Fetchers::Url33 _(res.resolved_source).must_equal({url: 'http://chef.io/some.tar.gz', sha256: expected_shasum})34 end35 it 'handles a https url' do36 url = 'https://chef.io/some.tar.gz'37 res = Fetchers::Url.resolve(url)38 res.expects(:open).returns(mock_open)39 _(res).must_be_kind_of Fetchers::Url40 _(res.resolved_source).must_equal({url: 'https://chef.io/some.tar.gz', sha256: expected_shasum})41 end42 it 'handles an https URI' do43 uri = URI.parse('https://chef.io/some.tar.gz')44 res = Fetchers::Url.resolve(uri)45 res.expects(:open).returns(mock_open)46 _(res).must_be_kind_of Fetchers::Url47 _(res.resolved_source).must_equal({url: 'https://chef.io/some.tar.gz', sha256: expected_shasum})48 end49 it 'doesnt handle other schemas' do50 Fetchers::Url.resolve('gopher://chef.io/some.tar.gz').must_be_nil51 end52 it 'only handles URLs' do53 Fetchers::Url.resolve(__FILE__).must_be_nil54 end55 %w{https://github.com/chef/inspec56 https://github.com/chef/inspec.git57 https://www.github.com/chef/inspec.git58 http://github.com/chef/inspec59 http://github.com/chef/inspec.git60 http://www.github.com/chef/inspec.git}.each do |github|61 it "resolves a github url #{github}" do62 expect_url_transform do63 res = Fetchers::Url.resolve(github)64 res.expects(:open).returns(mock_open)65 _(res).wont_be_nil66 _(res.resolved_source).must_equal({url: 'https://github.com/chef/inspec/archive/master.tar.gz', sha256: expected_shasum})67 end68 end69 end70 it "resolves a github branch url" do71 expect_url_transform do72 github = 'https://github.com/hardening-io/tests-os-hardening/tree/2.0'73 res = Fetchers::Url.resolve(github)74 res.expects(:open).returns(mock_open)75 _(res).wont_be_nil76 _(res.resolved_source).must_equal({url: 'https://github.com/hardening-io/tests-os-hardening/archive/2.0.tar.gz', sha256: expected_shasum})77 end78 end79 it "resolves a github commit url" do80 expect_url_transform do81 github = 'https://github.com/hardening-io/tests-os-hardening/tree/48bd4388ddffde68badd83aefa654e7af3231876'82 res = Fetchers::Url.resolve(github)83 res.expects(:open).returns(mock_open)84 _(res).wont_be_nil85 _(res.resolved_source).must_equal({url: 'https://github.com/hardening-io/tests-os-hardening/archive/48bd4388ddffde68badd83aefa654e7af3231876.tar.gz',86 sha256: expected_shasum})87 end88 end89 %w{https://bitbucket.org/chef/inspec90 https://bitbucket.org/chef/inspec.git91 https://www.bitbucket.org/chef/inspec.git92 http://bitbucket.org/chef/inspec93 http://bitbucket.org/chef/inspec.git94 http://www.bitbucket.org/chef/inspec.git}.each do |bitbucket|95 it "resolves a bitbucket url #{bitbucket}" do96 expect_url_transform do97 res = Fetchers::Url.resolve(bitbucket)98 res.expects(:open).returns(mock_open)99 _(res).wont_be_nil100 _(res.resolved_source).must_equal({url: 'https://bitbucket.org/chef/inspec/get/master.tar.gz', sha256: expected_shasum})101 end102 end103 end104 it "resolves a bitbucket branch url" do105 expect_url_transform do106 bitbucket = 'https://bitbucket.org/chef/inspec/branch/newbranch'107 res = Fetchers::Url.resolve(bitbucket)108 res.expects(:open).returns(mock_open)109 _(res).wont_be_nil110 _(res.resolved_source).must_equal({url: 'https://bitbucket.org/chef/inspec/get/newbranch.tar.gz', sha256: expected_shasum})111 end112 end113 it "resolves a bitbucket commit url" do114 expect_url_transform do115 bitbucket = 'https://bitbucket.org/chef/inspec/commits/48bd4388ddffde68badd83aefa654e7af3231876'116 res = Fetchers::Url.resolve(bitbucket)117 res.expects(:open).returns(mock_open)118 _(res).wont_be_nil119 _(res.resolved_source).must_equal({url: 'https://bitbucket.org/chef/inspec/get/48bd4388ddffde68badd83aefa654e7af3231876.tar.gz', sha256: expected_shasum})120 end121 end122 end123 describe 'download_automate2_archive_to_temp' do124 let(:target) { 'https://myurl/file.tar.gz' }125 let(:options) do126 {127 'automate' => {128 'ent' => 'automate',129 'token_type' => 'dctoken',130 },131 'token' => '1234abcd',132 'server_type' => 'automate2',133 'profile' => ['admin', 'ssh-baseline', '2.0']134 }135 end136 let(:subject) { Fetchers::Url.resolve(target, options) }137 it "downloads tar to tmp file" do138 mock = Object.new139 mock.stubs(:body).returns('this is the body')140 Net::HTTP.expects(:start)141 .returns(mock)142 path = subject.send(:download_automate2_archive_to_temp)143 File.read(path).must_equal 'this is the body'144 end145 it "sets default http options" do146 mock = Object.new147 mock.stubs(:body).returns('this is the body')148 opts = {"chef-delivery-enterprise"=>"automate", "x-data-collector-token"=>"1234abcd", :use_ssl=>true, :verify_mode=>1}149 Net::HTTP.expects(:start)150 .with('myurl', 443, opts)151 .returns(mock)152 subject.send(:download_automate2_archive_to_temp)153 end154 it "sets insecure http options" do155 options['insecure'] = true156 mock = Object.new157 mock.stubs(:body).returns('this is the body')158 opts = {:ssl_verify_mode => 0, "chef-delivery-enterprise"=>"automate", "x-data-collector-token"=>"1234abcd", :use_ssl=>true, :verify_mode=>0}159 Net::HTTP.expects(:start)160 .with('myurl', 443, opts)161 .returns(mock)162 subject.send(:download_automate2_archive_to_temp)163 end164 end165 describe 'applied to a valid url (mocked tar.gz)' do166 let(:mock_file) { MockLoader.profile_tgz('complete-profile') }167 let(:target) { 'http://myurl/file.tar.gz' }168 let(:subject) { Fetchers::Url.resolve(target) }169 let(:mock_open) {170 m = Minitest::Mock.new171 m.expect :meta, {'content-type' => 'application/gzip'}172 m.expect :read, File.open(mock_file, 'rb').read173 m174 }175 let(:mock_dest) {176 f = Tempfile.new("url-fetch-test")177 f.path178 }179 it 'tries to fetch the file' do180 subject.expects(:open).returns(mock_open)181 subject.fetch(mock_dest)182 end183 it "returns the resolved_source hash" do184 subject.expects(:open).returns(mock_open)185 subject.resolved_source[:url].must_equal(target)186 end187 end188 describe '#http_opts' do189 let(:subject) { Fetchers::Url.new('fake_url', config) }190 describe 'when username and password is specified' do191 let(:config) { { :username => 'dummy', :password => 'dummy' } }192 it 'returns a hash containing http_basic_authentication setting' do193 subject.send(:http_opts)[:http_basic_authentication].must_equal ["dummy", "dummy"]194 end195 end196 describe 'when only password is specified' do197 let(:config) { { :password => 'dummy'} }198 it 'returns a hash containing http_basic_authentication setting as nil' do199 subject.send(:http_opts)[:http_basic_authentication].must_be_nil...

Full Screen

Full Screen

fetchers_test.rb

Source:fetchers_test.rb Github

copy

Full Screen

...5require 'bundles/inspec-supermarket/target'6require 'bundles/inspec-supermarket/api'7describe Inspec::Fetcher do8 it 'loads the local fetcher for this file' do9 res = Inspec::Fetcher.resolve(__FILE__)10 res.must_be_kind_of Fetchers::Local11 end12 describe "without a source specified" do13 let(:mock_open) {14 m = Minitest::Mock.new15 m.expect :meta, {'content-type' => 'application/gzip'}16 m.expect :read, "fake content"17 m18 }19 before do20 Supermarket::API.expects(:exist?).returns(true)21 Supermarket::API.expects(:find).returns({'tool_source_url' => "http://mock-url" })22 end23 it "defaults to supermarket if only a name is given" do24 res = Inspec::Fetcher.resolve({:name => "mock/test-profile"})25 res.expects(:open).returns(mock_open)26 res.must_be_kind_of Fetchers::Url27 res.resolved_source[:url].must_equal("http://mock-url")28 end29 it "ignores keys that might have come along for the ride" do30 res = Inspec::Fetcher.resolve({:name => "mock/test-profile", cwd: "/tmp/inspec-test", cache: "ancache", backend: "test-backend"})31 res.must_be_kind_of Fetchers::Url32 end33 end34 it 'is able to handle Windows paths' do35 # simulate a local windows path36 file = __FILE__37 file.tr!('/', '\\')38 res = Inspec::Fetcher.resolve(file)39 res.must_be_kind_of Fetchers::Local40 res.target.must_equal __FILE__41 end42end...

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1fetchers.resolve('http://www.google.com')2 def resolve(url)3 @fetcher.fetch(url)4 def fetch(url)

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1puts Fetchers.resolve('http://www.rubyinside.com/test.txt')2puts Fetchers.resolve('http://www.rubyinside.com/test2.txt')3 def self.resolve(url)4 Net::HTTP.get URI(url)

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1puts Fetchers.resolve('1.rb')2puts Fetchers.resolve('2.rb')3puts Fetchers.resolve('3.rb')4puts Fetchers.resolve('4.rb')5puts Fetchers.resolve('5.rb')6puts Fetchers.resolve('6.rb')7puts Fetchers.resolve('7.rb')8puts Fetchers.resolve('8.rb')9puts Fetchers.resolve('9.rb')10puts Fetchers.resolve('10.rb')11puts Fetchers.resolve('11.rb')12puts Fetchers.resolve('12.rb')13puts Fetchers.resolve('13.rb')14puts Fetchers.resolve('14.rb')15puts Fetchers.resolve('15.rb')16puts Fetchers.resolve('16.rb')17puts Fetchers.resolve('17.rb')18puts Fetchers.resolve('18.rb')19puts Fetchers.resolve('19.rb')20puts Fetchers.resolve('20.rb')21puts Fetchers.resolve('21.rb')22puts Fetchers.resolve('22.rb')23puts Fetchers.resolve('23.rb')

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful