mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
Fix functional tests. (#3572)
Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
parent
1ac865388a
commit
0fc83871a1
4 changed files with 90 additions and 78 deletions
|
@ -16,28 +16,35 @@ describe 'example inheritance profile' do
|
|||
end
|
||||
|
||||
it 'check succeeds without --profiles-path using inspec.yml' do
|
||||
out = inspec('check ' + path)
|
||||
out.stderr.must_equal ''
|
||||
out.stdout.must_match(/Valid.*true/)
|
||||
out.exit_status.must_equal 0
|
||||
prepare_examples('inheritance') do |dir|
|
||||
out = inspec('vendor ' + dir)
|
||||
out = inspec('check ' + dir)
|
||||
out.stderr.must_equal ''
|
||||
out.stdout.must_match(/Valid.*true/)
|
||||
out.exit_status.must_equal 0
|
||||
end
|
||||
end
|
||||
|
||||
it 'archive is successful with --profiles-path' do
|
||||
out = inspec('archive ' + path + ' --output ' + dst.path + ' --profiles-path ' + examples_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
|
||||
prepare_examples('inheritance') do |dir|
|
||||
out = inspec('archive ' + dir + ' --output ' + dst.path + ' --profiles-path ' + examples_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
|
||||
end
|
||||
|
||||
it 'archive is successful without --profiles-path using inspec.yml' do
|
||||
out = inspec('archive ' + path + ' --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
|
||||
prepare_examples('inheritance') do |dir|
|
||||
out = inspec('archive ' + dir + ' --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
|
||||
end
|
||||
|
||||
it 'read the profile json with --profiles-path' do
|
||||
|
|
|
@ -9,35 +9,40 @@ describe 'inspec archive' do
|
|||
include FunctionalHelper
|
||||
|
||||
it 'archive is successful' do
|
||||
out = inspec('archive ' + example_profile + ' --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.'
|
||||
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
|
||||
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
|
||||
prepare_examples('profile') do |dir|
|
||||
out = inspec('archive ' + dir + ' --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
|
||||
end
|
||||
|
||||
it 'auto-archives when no --output is given' do
|
||||
auto_dst = File.join(repo_path, 'profile-1.0.0.tar.gz')
|
||||
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
|
||||
prepare_examples('profile') do |dir|
|
||||
auto_dst = File.join(repo_path, 'profile-1.0.0.tar.gz')
|
||||
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
|
||||
end
|
||||
|
||||
it 'archive on invalid archive' do
|
||||
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
|
||||
|
@ -45,51 +50,61 @@ describe 'inspec archive' do
|
|||
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
|
||||
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 '' # 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
|
||||
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
|
||||
prepare_examples('profile') do |dir|
|
||||
x = rand.to_s
|
||||
File.write(dst.path, x)
|
||||
out = inspec('archive ' + dir + ' --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
|
||||
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'
|
||||
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
|
||||
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'
|
||||
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
|
||||
end
|
||||
|
||||
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
|
||||
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
|
||||
end
|
||||
|
||||
it 'can archive a profile with required attributes' do
|
||||
|
@ -98,7 +113,7 @@ describe 'inspec archive' do
|
|||
Dir.mktmpdir do |tmpdir|
|
||||
FileUtils.cp_r(archive_depends_path + '/.', tmpdir)
|
||||
|
||||
out = inspec('archive ' + tmpdir)
|
||||
out = inspec('archive ' + tmpdir + ' --output ' + dst.path)
|
||||
out.stderr.must_equal ''
|
||||
out.exit_status.must_equal 0
|
||||
end
|
||||
|
|
|
@ -153,14 +153,6 @@ Test Summary: 0 successful, 0 failures, 0 skipped
|
|||
|
||||
it 'does not vendor profiles when using the a local path dependecy' do
|
||||
Dir.mktmpdir do |tmpdir|
|
||||
# Other commands (e.g. vendor) might create a vendor directory on this
|
||||
# shared profile during functional testing. We remove `vendor/` here if
|
||||
# it exists to avoid surprises when checking cache contents later.
|
||||
vendor_dir = File.join(inheritance_profile, 'vendor')
|
||||
FileUtils.remove_dir(vendor_dir) if File.exist?(vendor_dir)
|
||||
lock_file = File.join(inheritance_profile, 'inspec.lock')
|
||||
File.delete(lock_file) if File.exist?(lock_file)
|
||||
|
||||
command = 'exec ' + inheritance_profile + ' --no-create-lockfile'
|
||||
out = inspec_with_env(command, INSPEC_CONFIG_DIR: tmpdir)
|
||||
out.stderr.must_equal ''
|
||||
|
|
|
@ -5,8 +5,6 @@ require 'tmpdir'
|
|||
|
||||
describe 'example inheritance profile' do
|
||||
include FunctionalHelper
|
||||
let(:inheritance_path) { File.join(examples_path, 'inheritance') }
|
||||
let(:meta_path) { File.join(examples_path, 'meta-profile') }
|
||||
|
||||
it 'can vendor profile dependencies' do
|
||||
prepare_examples('inheritance') do |dir|
|
||||
|
|
Loading…
Reference in a new issue