validate inspec json generation

This commit is contained in:
Dominik Richter 2016-03-16 19:41:29 +01:00
parent bfd88df27a
commit 6853284e31

View file

@ -93,7 +93,7 @@ describe 'Inspec::InspecCLI' do
File.read(dst.path).wont_equal x
end
it 'creates valid tar.gz files' do
it 'creates valid tar.gz archives' do
out = inspec('archive ' + path + ' --output ' + dst.path + ' --tar')
out.stderr.must_equal ''
out.stdout.must_include 'Generate archive '+dst.path
@ -102,23 +102,48 @@ describe 'Inspec::InspecCLI' do
Gem::Package::TarReader.new(t).entries.map(&:header).map(&:name).must_include 'inspec.yml'
end
it 'creates valid zip files' do
it 'creates valid zip archives' do
out = inspec('archive ' + path + ' --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
it 'read the profile json' do
out = inspec('json ' + path)
out.stderr.must_equal ''
out.exit_status.must_equal 0
s = out.stdout
hm = JSON.load(s)
hm['name'].must_equal 'profile'
hm['rules'].length.must_equal 2 # TODO: flatten out or search deeper!
end
it 'writes json to file' do
out = inspec('json ' + path + ' --output ' + dst.path)
out.stderr.must_equal ''
out.exit_status.must_equal 0
hm = JSON.load(File.read(dst.path))
hm['name'].must_equal 'profile'
hm['rules'].length.must_equal 2 # TODO: flatten out or search deeper!
end
end
describe 'example inheritance profile' do
let(:path) { File.join(examples_path, 'inheritance') }
it 'check fails without --profiles-path' do
out = inspec('check ' + path)
out.stderr.must_include 'You must supply a --profiles-path to inherit'
out.stdout.must_equal ''
out.exit_status.must_equal 1
[
'archive %s --overwrite',
'check %s',
'json %s',
].each do |cmd|
it cmd[/^\w/] + ' fails without --profiles-path' do
out = inspec(format(cmd, path))
out.stderr.must_include 'You must supply a --profiles-path to inherit'
# out.stdout.must_equal '' => we still get partial output
out.exit_status.must_equal 1
end
end
it 'check succeeds with --profiles-path' do
@ -128,14 +153,6 @@ describe 'Inspec::InspecCLI' do
out.exit_status.must_equal 0
end
it 'archive fails without --profiles-path' do
out = inspec('archive ' + path + ' --output ' + dst.path)
# out.stdout.must_equal '' => we have partial stdout output right now
out.stderr.must_include 'You must supply a --profiles-path to inherit'
out.exit_status.must_equal 1
File.exist?(dst.path).must_equal false
end
it 'archive is successful with --profiles-path' do
out = inspec('archive ' + path + ' --output ' + dst.path + ' --profiles-path ' + examples_path)
out.stderr.must_equal ''
@ -144,5 +161,15 @@ describe 'Inspec::InspecCLI' do
out.exit_status.must_equal 0
File.exist?(dst.path).must_equal true
end
it 'read the profile json with --profiles-path' do
out = inspec('json ' + path + ' --profiles-path '+examples_path)
out.stderr.must_equal ''
out.exit_status.must_equal 0
s = out.stdout
hm = JSON.load(s)
hm['name'].must_equal 'inheritance'
hm['rules'].length.must_equal 1 # TODO: flatten out or search deeper!
end
end
end