From b8cce5d3c7c6cf8c81a740aac449795ad9cdd65b Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Wed, 17 Feb 2016 12:02:28 +0100 Subject: [PATCH] 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 --- test/helper.rb | 7 ++++++- test/unit/targets/url_test.rb | 12 ++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index c8f48e789..484de5631 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -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 diff --git a/test/unit/targets/url_test.rb b/test/unit/targets/url_test.rb index 282b560bb..85c933779 100644 --- a/test/unit/targets/url_test.rb +++ b/test/unit/targets/url_test.rb @@ -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