Update tests

This commit is contained in:
Stephan Renatus 2016-02-03 15:42:33 +01:00
parent cc60fa1e23
commit 1c76d723ff

View file

@ -6,6 +6,7 @@ require 'helper'
require 'inspec/profile_context'
require 'inspec/runner'
require 'inspec/runner_mock'
require 'fileutils'
describe Inspec::Profile do
let(:logger) { Minitest::Mock.new }
@ -16,6 +17,20 @@ describe Inspec::Profile do
Inspec::Profile.from_path("#{home}/mock/profiles/#{name}", opts)
end
def load_profile_tgz(name, opts = {})
path = "#{home}/mock/profiles/#{name}"
`tar zcvf #{path}.tgz #{path}`
load_profile("#{name}.tgz", opts)
FileUtils.rm("#{path}.tgz")
end
def load_profile_zip(name, opts = {})
path = "#{home}/mock/profiles/#{name}"
`zip #{path}.zip #{path}`
load_profile("#{name}.zip", opts)
FileUtils.rm("#{path}.zip")
end
describe 'with an empty profile' do
let(:profile) { load_profile('empty-metadata') }
@ -76,13 +91,14 @@ describe Inspec::Profile do
let(:profile_id) { 'empty-metadata' }
it 'prints loads of warnings' do
inspec_yml = "#{home}/mock/profiles/#{profile_id}/inspec.yml"
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
logger.expect :error, nil, ['Missing profile name in inspec.yml']
logger.expect :error, nil, ['Missing profile version in inspec.yml']
logger.expect :warn, nil, ['Missing profile title in inspec.yml']
logger.expect :warn, nil, ['Missing profile summary in inspec.yml']
logger.expect :warn, nil, ['Missing profile maintainer in inspec.yml']
logger.expect :warn, nil, ['Missing profile copyright in inspec.yml']
logger.expect :error, nil, ["Missing profile name in #{inspec_yml}"]
logger.expect :error, nil, ["Missing profile version in #{inspec_yml}"]
logger.expect :warn, nil, ["Missing profile title in #{inspec_yml}"]
logger.expect :warn, nil, ["Missing profile summary in #{inspec_yml}"]
logger.expect :warn, nil, ["Missing profile maintainer in #{inspec_yml}"]
logger.expect :warn, nil, ["Missing profile copyright in #{inspec_yml}"]
logger.expect :warn, nil, ['No controls or tests were defined.']
load_profile(profile_id, {logger: logger}).check
@ -94,14 +110,15 @@ describe Inspec::Profile do
let(:profile_id) { 'legacy-empty-metadata' }
it 'prints loads of warnings' do
metadata_rb = "#{home}/mock/profiles/#{profile_id}/metadata.rb"
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
logger.expect :warn, nil, ['The use of `metadata.rb` is deprecated. Use `inspec.yml`.']
logger.expect :error, nil, ['Missing profile name in metadata.rb']
logger.expect :error, nil, ['Missing profile version in metadata.rb']
logger.expect :warn, nil, ['Missing profile title in metadata.rb']
logger.expect :warn, nil, ['Missing profile summary in metadata.rb']
logger.expect :warn, nil, ['Missing profile maintainer in metadata.rb']
logger.expect :warn, nil, ['Missing profile copyright in metadata.rb']
logger.expect :error, nil, ["Missing profile name in #{metadata_rb}"]
logger.expect :error, nil, ["Missing profile version in #{metadata_rb}"]
logger.expect :warn, nil, ["Missing profile title in #{metadata_rb}"]
logger.expect :warn, nil, ["Missing profile summary in #{metadata_rb}"]
logger.expect :warn, nil, ["Missing profile maintainer in #{metadata_rb}"]
logger.expect :warn, nil, ["Missing profile copyright in #{metadata_rb}"]
logger.expect :warn, nil, ['No controls or tests were defined.']
load_profile(profile_id, {logger: logger}).check
@ -131,7 +148,8 @@ describe Inspec::Profile do
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
logger.expect :warn, nil, ['The use of `metadata.rb` is deprecated. Use `inspec.yml`.']
logger.expect :info, nil, ['Metadata OK.']
logger.expect :warn, nil, ["Profile uses deprecated `test` directory, rename it to `controls`."]
# NB we only look at content that is loaded, i.e., there're no empty directories anymore
# logger.expect :warn, nil, ["Profile uses deprecated `test` directory, rename it to `controls`."]
logger.expect :warn, nil, ['No controls or tests were defined.']
profile.check
@ -157,5 +175,37 @@ describe Inspec::Profile do
logger.verify
end
end
describe 'a complete metadata profile with controls in a tarball' do
let(:profile_id) { 'complete-profile' }
let(:profile) { load_profile_tgz(profile_id, {logger: logger}) }
it 'prints ok messages and counts the rules' do
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
logger.expect :info, nil, ['Metadata OK.']
logger.expect :info, nil, ['Found 1 rules.']
logger.expect :debug, nil, ["Verify all rules in #{home}/mock/profiles/#{profile_id}/controls/filesystem_spec.rb"]
logger.expect :info, nil, ['Rule definitions OK.']
load_profile(profile_id, {logger: logger, ignore_supports: true}).check
logger.verify
end
end
describe 'a complete metadata profile with controls in zipfile' do
let(:profile_id) { 'complete-profile' }
let(:profile) { load_profile_zip(profile_id, {logger: logger}) }
it 'prints ok messages and counts the rules' do
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
logger.expect :info, nil, ['Metadata OK.']
logger.expect :info, nil, ['Found 1 rules.']
logger.expect :debug, nil, ["Verify all rules in #{home}/mock/profiles/#{profile_id}/controls/filesystem_spec.rb"]
logger.expect :info, nil, ['Rule definitions OK.']
load_profile(profile_id, {logger: logger, ignore_supports: true}).check
logger.verify
end
end
end
end