From 6853284e31279763f84a2ce0214969f752b23130 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Wed, 16 Mar 2016 19:41:29 +0100 Subject: [PATCH] validate inspec json generation --- test/functional/command_test.rb | 57 ++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/test/functional/command_test.rb b/test/functional/command_test.rb index ff805894e..0be3cc344 100644 --- a/test/functional/command_test.rb +++ b/test/functional/command_test.rb @@ -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