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:
Dominik Richter 2016-02-17 12:02:28 +01:00 committed by Christoph Hartmann
parent b872c04616
commit b8cce5d3c7
2 changed files with 12 additions and 7 deletions

View file

@ -15,6 +15,7 @@ SimpleCov.start do
end end
require 'fileutils' require 'fileutils'
require 'zip'
require 'utils/base_cli' require 'utils/base_cli'
require 'inspec/targets' require 'inspec/targets'
@ -265,7 +266,11 @@ class MockLoader
path = "#{home}/mock/profiles/#{name}" path = "#{home}/mock/profiles/#{name}"
dst = "#{path}.zip" dst = "#{path}.zip"
FileUtils.rm(dst) if File.file?(dst) 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 dst
end end
end end

View file

@ -92,7 +92,7 @@ describe Inspec::Targets::UrlHelper do
describe 'with a tar.gz archive' do describe 'with a tar.gz archive' do
let (:url) { 'https://github.com/chef/inspec/archive/master.tar.gz' } let (:url) { 'https://github.com/chef/inspec/archive/master.tar.gz' }
let (:profile_path) { MockLoader.profile_tgz('complete-profile') } 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 it 'resolves the url' do
url_helper.expects(:download_archive).returns([File.new(profile_path), 'application/x-gzip']) 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][:type].must_equal :test
res[0][:content].wont_be_empty 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][:type].must_equal :metadata
res[1][:content].wont_be_empty 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 end
describe 'with a zip archive' do describe 'with a zip archive' do
let (:url) { 'https://github.com/chef/inspec/archive/master.zip' } let (:url) { 'https://github.com/chef/inspec/archive/master.zip' }
let (:profile_path) { MockLoader.profile_zip('complete-profile') } 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 it 'resolves the url' do
url_helper.expects(:download_archive).returns([File.new(profile_path), 'application/zip']) 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][:type].must_equal :test
res[0][:content].wont_be_empty 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][:type].must_equal :metadata
res[1][:content].wont_be_empty 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 end
end end