Skip to content

Commit

Permalink
add profile tests (non-legacy)
Browse files Browse the repository at this point in the history
  • Loading branch information
arlimus committed Jan 20, 2016
1 parent 4192ded commit f4c6e7a
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 7 deletions.
6 changes: 2 additions & 4 deletions lib/inspec/targets/dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ module DirsHelper
# TODO: remove `test` support for InSpec 1.0
class ProfileDir
def handles?(paths)
return true if paths.include?('inspec.yml')
(
!paths.grep(/^controls/).empty? ||
!paths.grep(/^test/).empty?
) && (
paths.include?('inspec.yml') ||
paths.include?('metadata.rb')
)
) && paths.include?('metadata.rb')
end

def get_libraries(paths)
Expand Down
7 changes: 7 additions & 0 deletions test/unit/mock/profiles/complete-metadata/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: name
version: 1.2.3
maintainer: bob
title: title
copyright: left
summary: nothing
supports: linux
Empty file.
1 change: 1 addition & 0 deletions test/unit/mock/profiles/simple-metadata/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: yumyum profile
62 changes: 59 additions & 3 deletions test/unit/profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ def load_profile(name, opts = {})
Inspec::Profile.from_path("#{home}/mock/profiles/#{name}", opts)
end

describe 'with empty profile (legacy mode)' do
describe 'with an empty profile' do
let(:profile) { load_profile('empty-metadata') }

it 'has no metadata' do
profile.params[:name].must_be_nil
end

it 'has no rules' do
profile.params[:rules].must_equal({})
end
end

describe 'with an empty profile (legacy mode)' do
let(:profile) { load_profile('legacy-empty-metadata') }

it 'has no metadata' do
Expand All @@ -28,8 +40,20 @@ def load_profile(name, opts = {})
end
end

describe 'with normal metadata in profile (legacy mode)' do
let(:profile) { load_profile('legacy-metadata') }
describe 'with simple metadata in profile' do
let(:profile) { load_profile('simple-metadata') }

it 'has metadata' do
profile.params[:name].must_equal 'yumyum profile'
end

it 'has no rules' do
profile.params[:rules].must_equal({})
end
end

describe 'with simple metadata in profile (legacy mode)' do
let(:profile) { load_profile('legacy-simple-metadata') }

it 'has metadata' do
profile.params[:name].must_equal 'metadata profile'
Expand All @@ -41,6 +65,24 @@ def load_profile(name, opts = {})
end

describe 'when checking' do
describe 'an empty profile' do
let(:profile_id) { 'empty-metadata' }

it 'prints loads of warnings' do
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 :warn, nil, ['No controls or tests were defined.']

load_profile(profile_id, {logger: logger}).check
logger.verify
end
end

describe 'an empty profile (legacy mode)' do
let(:profile_id) { 'legacy-empty-metadata' }

Expand All @@ -60,6 +102,20 @@ def load_profile(name, opts = {})
end
end

describe 'a complete metadata profile' do
let(:profile_id) { 'complete-metadata' }
let(:profile) { load_profile(profile_id, {logger: logger}) }

it 'prints ok messages' do
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
logger.expect :info, nil, ['Metadata OK.']
logger.expect :warn, nil, ['No controls or tests were defined.']

profile.check
logger.verify
end
end

describe 'a complete metadata profile (legacy mode)' do
let(:profile_id) { 'legacy-complete-metadata' }
let(:profile) { load_profile(profile_id, {logger: logger}) }
Expand Down

0 comments on commit f4c6e7a

Please sign in to comment.