2016-03-25 00:31:19 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
|
|
|
|
require 'functional/helper'
|
2016-08-26 12:25:17 +00:00
|
|
|
require 'tmpdir'
|
2016-03-25 00:31:19 +00:00
|
|
|
|
|
|
|
describe 'inspec archive' do
|
|
|
|
include FunctionalHelper
|
2018-11-08 17:00:14 +00:00
|
|
|
let(:auto_dst) { File.expand_path(File.join(repo_path, 'profile-1.0.0.tar.gz')) }
|
2016-03-25 00:31:19 +00:00
|
|
|
|
|
|
|
it 'archive is successful' do
|
2018-11-02 16:52:54 +00:00
|
|
|
prepare_examples('profile') do |dir|
|
|
|
|
out = inspec('archive ' + dir + ' --overwrite')
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
out.stdout.must_match(/Generate archive [^ ]*profile-1.0.0.tar.gz/)
|
|
|
|
out.stdout.must_include 'Finished archive generation.'
|
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'archives to output file' do
|
2018-11-02 16:52:54 +00:00
|
|
|
prepare_examples('profile') do |dir|
|
|
|
|
out = inspec('archive ' + dir + ' --output ' + dst.path)
|
|
|
|
out.stderr.must_equal ''
|
2018-11-08 17:00:14 +00:00
|
|
|
out.stdout.must_include 'Generate archive ' + dst.path
|
2018-11-02 16:52:54 +00:00
|
|
|
out.stdout.must_include 'Finished archive generation.'
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
File.exist?(dst.path).must_equal true
|
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'auto-archives when no --output is given' do
|
2018-11-02 16:52:54 +00:00
|
|
|
prepare_examples('profile') do |dir|
|
|
|
|
out = inspec('archive ' + dir + ' --overwrite')
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.stdout.must_include 'Generate archive ' + auto_dst
|
|
|
|
out.stdout.must_include 'Finished archive generation.'
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
File.exist?(auto_dst).must_equal true
|
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'archive on invalid archive' do
|
2016-08-26 12:25:17 +00:00
|
|
|
Dir.tmpdir do |target_dir|
|
2018-11-08 17:00:14 +00:00
|
|
|
out = inspec("archive #{target_dir} --output " + dst.path)
|
2016-08-26 12:25:17 +00:00
|
|
|
out.stderr.must_include "Don't understand inspec profile in \"#{target_dir}\""
|
|
|
|
out.exit_status.must_equal 1
|
|
|
|
File.exist?(dst.path).must_equal false
|
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
2019-01-08 22:12:42 +00:00
|
|
|
it 'archive will overwrite existing files even without --overwrite' do
|
2018-11-02 16:52:54 +00:00
|
|
|
prepare_examples('profile') do |dir|
|
|
|
|
x = rand.to_s
|
|
|
|
File.write(dst.path, x)
|
|
|
|
out = inspec('archive ' + dir + ' --output ' + dst.path)
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.stdout.must_include 'Generate archive ' + dst.path
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
File.read(dst.path).wont_equal x
|
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates valid tar.gz archives' do
|
2018-11-02 16:52:54 +00:00
|
|
|
prepare_examples('profile') do |dir|
|
|
|
|
out = inspec('archive ' + dir + ' --output ' + dst.path + ' --tar')
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.stdout.must_include 'Generate archive ' + dst.path
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
t = Zlib::GzipReader.open(dst.path)
|
|
|
|
Gem::Package::TarReader.new(t).entries.map(&:header).map(&:name).must_include 'inspec.yml'
|
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates valid zip archives' do
|
2018-11-02 16:52:54 +00:00
|
|
|
prepare_examples('profile') do |dir|
|
|
|
|
out = inspec('archive ' + dir + ' --output ' + dst.path + ' --zip')
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.stdout.must_include 'Generate archive ' + dst.path
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
Zip::File.new(dst.path).entries.map(&:name).must_include 'inspec.yml'
|
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
2018-09-07 03:28:08 +00:00
|
|
|
|
|
|
|
it 'vendors dependencies by default' do
|
2018-11-02 16:52:54 +00:00
|
|
|
prepare_examples('meta-profile') do |dir|
|
|
|
|
out = inspec('archive ' + dir + ' --output ' + dst.path)
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.stdout.must_include 'Generate archive ' + dst.path
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
t = Zlib::GzipReader.open(dst.path)
|
|
|
|
files = Gem::Package::TarReader.new(t).entries.map(&:header).map(&:name)
|
|
|
|
files.must_include 'inspec.lock'
|
|
|
|
files.select { |f| f =~ /vendor/ }.count.must_be :>, 1
|
|
|
|
end
|
2018-09-07 03:28:08 +00:00
|
|
|
end
|
2018-10-05 20:24:26 +00:00
|
|
|
|
|
|
|
it 'can archive a profile with required attributes' do
|
2019-02-08 23:23:01 +00:00
|
|
|
archive_depends_path = File.join(profile_path, 'profile-with-required-inputs')
|
2018-10-05 20:24:26 +00:00
|
|
|
|
|
|
|
Dir.mktmpdir do |tmpdir|
|
|
|
|
FileUtils.cp_r(archive_depends_path + '/.', tmpdir)
|
|
|
|
|
2018-11-02 16:52:54 +00:00
|
|
|
out = inspec('archive ' + tmpdir + ' --output ' + dst.path)
|
2018-10-05 20:24:26 +00:00
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|