mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
create zip for test helper in ruby
The zip command is not always there. (e.g. i dont have it on my box). just use the available zip library
This commit is contained in:
parent
b872c04616
commit
b8cce5d3c7
2 changed files with 12 additions and 7 deletions
|
@ -15,6 +15,7 @@ SimpleCov.start do
|
|||
end
|
||||
|
||||
require 'fileutils'
|
||||
require 'zip'
|
||||
|
||||
require 'utils/base_cli'
|
||||
require 'inspec/targets'
|
||||
|
@ -265,7 +266,11 @@ class MockLoader
|
|||
path = "#{home}/mock/profiles/#{name}"
|
||||
dst = "#{path}.zip"
|
||||
FileUtils.rm(dst) if File.file?(dst)
|
||||
`zip #{dst} #{path}`
|
||||
Zip::File.open(dst, 'w') do |zipfile|
|
||||
Dir["#{path}/**/**"].reject { |f| f == dst }.each do |file|
|
||||
zipfile.add(file.sub(path+'/', ''), file)
|
||||
end
|
||||
end
|
||||
dst
|
||||
end
|
||||
end
|
||||
|
|
|
@ -92,7 +92,7 @@ describe Inspec::Targets::UrlHelper do
|
|||
describe 'with a tar.gz archive' do
|
||||
let (:url) { 'https://github.com/chef/inspec/archive/master.tar.gz' }
|
||||
let (:profile_path) { MockLoader.profile_tgz('complete-profile') }
|
||||
let (:archive_path) { profile_path.sub(/.tgz$/, '')[1..-1] }
|
||||
let (:archive_path) { profile_path.sub(/.tgz$/, '')[1..-1] + '/' }
|
||||
|
||||
it 'resolves the url' do
|
||||
url_helper.expects(:download_archive).returns([File.new(profile_path), 'application/x-gzip'])
|
||||
|
@ -105,18 +105,18 @@ describe Inspec::Targets::UrlHelper do
|
|||
|
||||
res[0][:type].must_equal :test
|
||||
res[0][:content].wont_be_empty
|
||||
res[0][:ref].must_equal "#{archive_path}/controls/filesystem_spec.rb"
|
||||
res[0][:ref].must_equal "#{archive_path}controls/filesystem_spec.rb"
|
||||
|
||||
res[1][:type].must_equal :metadata
|
||||
res[1][:content].wont_be_empty
|
||||
res[1][:ref].must_equal "#{archive_path}/inspec.yml"
|
||||
res[1][:ref].must_equal "#{archive_path}inspec.yml"
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with a zip archive' do
|
||||
let (:url) { 'https://github.com/chef/inspec/archive/master.zip' }
|
||||
let (:profile_path) { MockLoader.profile_zip('complete-profile') }
|
||||
let (:archive_path) { profile_path.sub(/.zip$/, '')[1..-1] }
|
||||
let (:archive_path) { '' }
|
||||
|
||||
it 'resolves the url' do
|
||||
url_helper.expects(:download_archive).returns([File.new(profile_path), 'application/zip'])
|
||||
|
@ -129,11 +129,11 @@ describe Inspec::Targets::UrlHelper do
|
|||
|
||||
res[0][:type].must_equal :test
|
||||
res[0][:content].wont_be_empty
|
||||
res[0][:ref].must_equal "#{archive_path}/controls/filesystem_spec.rb"
|
||||
res[0][:ref].must_equal "#{archive_path}controls/filesystem_spec.rb"
|
||||
|
||||
res[1][:type].must_equal :metadata
|
||||
res[1][:content].wont_be_empty
|
||||
res[1][:ref].must_equal "#{archive_path}/inspec.yml"
|
||||
res[1][:ref].must_equal "#{archive_path}inspec.yml"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue