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