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
|
|
|
|
|
|
|
|
it 'archive is successful' do
|
|
|
|
out = inspec('archive ' + example_profile + ' --overwrite')
|
|
|
|
out.exit_status.must_equal 0
|
2016-12-14 16:07:09 +00:00
|
|
|
out.stdout.must_match(/Generate archive [^ ]*profile-1.0.0.tar.gz/)
|
2016-03-25 00:31:19 +00:00
|
|
|
out.stdout.must_include 'Finished archive generation.'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'archives to output file' do
|
|
|
|
out = inspec('archive ' + example_profile + ' --output ' + dst.path)
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.stdout.must_include 'Generate archive '+dst.path
|
|
|
|
out.stdout.must_include 'Finished archive generation.'
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
File.exist?(dst.path).must_equal true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'auto-archives when no --output is given' do
|
2016-12-14 16:07:09 +00:00
|
|
|
auto_dst = File.join(repo_path, 'profile-1.0.0.tar.gz')
|
2016-03-25 00:31:19 +00:00
|
|
|
out = inspec('archive ' + example_profile + ' --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
|
|
|
|
|
|
|
|
it 'archive on invalid archive' do
|
2016-08-26 12:25:17 +00:00
|
|
|
Dir.tmpdir do |target_dir|
|
|
|
|
out = inspec('archive #{target_dir} --output ' + dst.path)
|
|
|
|
# out.stdout.must_equal '' => we have partial stdout output right now
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'archive wont overwrite existing files' do
|
|
|
|
x = rand.to_s
|
|
|
|
File.write(dst.path, x)
|
|
|
|
out = inspec('archive ' + example_profile + ' --output ' + dst.path)
|
|
|
|
out.stderr.must_equal '' # uh...
|
|
|
|
out.stdout.must_include "Archive #{dst.path} exists already. Use --overwrite."
|
|
|
|
out.exit_status.must_equal 1
|
|
|
|
File.read(dst.path).must_equal x
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'archive will overwrite files if necessary' do
|
|
|
|
x = rand.to_s
|
|
|
|
File.write(dst.path, x)
|
|
|
|
out = inspec('archive ' + example_profile + ' --output ' + dst.path + ' --overwrite')
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'creates valid tar.gz archives' do
|
|
|
|
out = inspec('archive ' + example_profile + ' --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
|
|
|
|
|
|
|
|
it 'creates valid zip archives' do
|
|
|
|
out = inspec('archive ' + example_profile + ' --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
|
2018-09-07 03:28:08 +00:00
|
|
|
|
|
|
|
it 'vendors dependencies by default' do
|
|
|
|
out = inspec('archive ' + meta_profile + ' --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
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|