Skip to content

Commit

Permalink
(SIMP-3685) Add test for null values (#28)
Browse files Browse the repository at this point in the history
Ensure that a test is in place that explicitly checks for null values
in the data.
  • Loading branch information
trevor-vaughan authored Sep 28, 2017
1 parent ee7b33e commit 8b8a0ce
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 60 deletions.
24 changes: 10 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,19 @@ before_install:
- rm -f Gemfile.lock

jobs:
allow_failures:
- env: STRICT_VARIABLES=yes TRUSTED_NODE_DATA=yes PUPPET_VERSION="~> 5.0"

include:
- stage: lint
rvm: 2.1.9
- stage: spec
rvm: 2.4.1
env: STRICT_VARIABLES=yes TRUSTED_NODE_DATA=yes PUPPET_VERSION="~> 5"
script:
- bundle exec rake check:dot_underscore
- bundle exec rake check:test_file
- bundle exec rake pkg:check_version
- bundle exec rake metadata_lint

- stage: compare_tag
rvm: 2.1.9
script:
- bundle exec rake compare_latest_tag

- stage: spec
rvm: 2.1.9
rvm: 2.4.1
env: STRICT_VARIABLES=yes TRUSTED_NODE_DATA=yes PUPPET_VERSION="~> 5.0"
script:
- bundle exec rake spec
Expand Down Expand Up @@ -74,10 +71,9 @@ jobs:

# This needs to be last since we have an acceptance test
- stage: deploy
rvm: 2.1.9
env: STRICT_VARIABLES=yes TRUSTED_NODE_DATA=yes PUPPET_VERSION="~> 4.8.2"
rvm: 2.4.1
script:
- bundle exec rake spec
- true
before_deploy:
- "export PUPMOD_METADATA_VERSION=`ruby -r json -e \"puts JSON.parse(File.read('metadata.json')).fetch('version')\"`"
- '[[ $TRAVIS_TAG =~ ^simp-${PUPMOD_METADATA_VERSION}$|^${PUPMOD_METADATA_VERSION}$ ]]'
Expand All @@ -95,5 +91,5 @@ jobs:
secure: "vL1MNFrE7aazh/rEsSaHugCYYWXrJmsBuhMIP27CQ/EpBQ6wfWZhukZdkikZrmkIiJHHLi1HaQycKdW2AzcqN932iXOdjYtEA9eE/hO1VtGMYVobZFS4sh2Wtt8saVOg0tMPq45hjFHUe8FmgyrsjHBB+kl/fdfLVr+TiFCmWGXtZkjMlJxqPp+fyZZDrMoKoB7eSm3edOtqX7gONP3MEJ/wcHgCUTyspxI8sSXGl8IPwWNxU4LSgCwbvr/JzmDmKiK2AbSc7Q2+g7NrvZV39CbcV0IH4Uy4A+3fBBli/nPaidm/dvIvcYDacWF0UiXZTMvqd8tL4Z3Sf4vvB6NZ328ml97w233fLSHdLGn8qaIjmkK5x1UN9BRmA/WZbmkSSLWqwr6Cz+c4unik1NeQF2shpNZw8cGyh6IFnpIUbBsXPgxiIbb1HfoQCRFocTgkqpsbH7n8WpJkEdPpVgtJh51xILlbZibsI9U1YsfDjpZWXxUUObsANbAK0Z0Ep0wkzv31+9fSD7FlGOJ//GjqFRjW4inekCeUNyRbXTGIlDMeZyRKs/JZVndKr9AFestwkiM7AWWNFUKfSX5RE0oRNwQDAKAa8HDPtErNhfoAtBCYEcBTB6GoXhnyX/1gwrDb8zeEtbc50PLBnJT6gJIp2M2IiAeXHgGuMLiDbNzgThQ="
on:
tags: true
rvm: 2.1.9
rvm: 2.4.1
condition: '($SKIP_FORGE_PUBLISH != true)'
54 changes: 34 additions & 20 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class auditd (
end
end
end

[ {
:profile_type => 'Array'
},
Expand All @@ -147,97 +148,98 @@ class auditd (
'#{profile_name}',
'other_profile'
]
class test1 (
$arg1_1 = 'foo1_1',
$arg1_2 = 'foo1_2'
){
notify { 'bar': message => $arg1_1 }
}
class test2 {
class test3 (
$arg3_1 = 'foo3_1'
) { }
}
define testdef1 (
$defarg1_1 = 'deffoo1_1'
) {
notify { 'testdef1': message => $defarg1_1}
}
define testdef2 (
$defarg1_2 = 'deffoo1_2',
$defarg2_2 = 'foo'
) {
notify { 'testdef2': message => $defarg1_2}
}
define one_off_inline {
compliance_map('other_profile', 'ONE_OFF', 'This is awesome')
notify { $name: }
}
include '::test1'
include '::test2::test3'
testdef1 { 'test_definition': }
testdef2 { 'test_definition': defarg1_2 => 'test_bad' }
one_off_inline { 'one off': }
compliance_map('other_profile', 'TOP_LEVEL', 'Top level call')
EOM
}
when 'String'
let(:pre_condition) {
<<-EOM
$compliance_profile = '#{profile_name}'
class test1 (
$arg1_1 = 'foo1_1',
$arg1_2 = 'foo1_2'
){
notify { 'bar': message => $arg1_1 }
}
class test2 {
class test3 (
$arg3_1 = 'foo3_1'
) { }
}
define testdef1 (
$defarg1_1 = 'deffoo1_1'
) {
notify { 'testdef1': message => $defarg1_1}
}
define testdef2 (
$defarg1_2 = 'deffoo1_2',
$defarg2_2 = 'foo'
) {
notify { 'testdef2': message => $defarg1_2}
}
define one_off_inline {
compliance_map('other_profile', 'ONE_OFF', 'This is awesome')
notify { $name: }
}
include '::test1'
include '::test2::test3'
testdef1 { 'test_definition': }
testdef2 { 'test_definition': defarg1_2 => 'test_bad' }
one_off_inline { 'one off': }
compliance_map('other_profile', 'TOP_LEVEL', 'Top level call')
EOM
}
end

let(:facts) { facts }

['yaml','json'].each do |report_format|
Expand Down Expand Up @@ -415,7 +417,7 @@ class test3 (
expect(entry['identifiers']).to_not be_empty
expect(entry['notes']).to_not be_empty
end
end
end
end

context 'when running with the default options' do
Expand Down Expand Up @@ -516,6 +518,18 @@ class test3 (
it { is_expected.to(compile.with_all_deps) }
end

context 'with undefined values in the compliance hash' do
let(:pre_condition) {
<<-EOM
include 'compliance_markup'
EOM
}

let(:hieradata) { 'undefined_values' }

it { is_expected.to(compile.with_all_deps) }
end

=begin
# Unknown why this does not work
xcontext 'without valid compliance data in Hiera' do
Expand All @@ -529,10 +543,10 @@ class test3 (
end
end
=end
end
end
end
end
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
if ['7'].include?(facts[:os][:release][:major])

profiles = [ 'disa', 'nist']
profiles.each do |profile|
profiles.each do |profile|
order = ([ profile ] + (profiles - [ profile ])).to_s
context "when order = #{order}" do
let(:facts) { facts }
Expand Down
37 changes: 37 additions & 0 deletions spec/fixtures/hieradata/undefined_values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# Some very basic compliance checks designed for the tests
#
# These should all pass

compliance_map :
version : '1.0.1'

test_profile :
test1::arg1_1 :
identifiers :
- 'ID1.1'
value : null
test2::test3::arg3_1 :
identifiers :
- 'ID1.2'
value : 're:foo3_.*'
test2::test3::ref_miss1 :
identifiers :
- 'MISS1'
value : missing1
testdef1:defarg1_1 :
identifiers :
- 'DEF1.1'
value : deffoo1_1
unmapped1::arg1_1 :
identifiers :
- 'UNK001'
value : um1_1
unmapped1::arg1_2 :
identifiers :
- 'UNK002'
value : um1_2
unmapped1::subclass::arg1_2 :
identifiers :
- 'UNK003'
value : um1_3
7 changes: 0 additions & 7 deletions tests/data/common.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions tests/hiera.yaml

This file was deleted.

1 change: 0 additions & 1 deletion tests/production

This file was deleted.

6 changes: 0 additions & 6 deletions tests/test.pp

This file was deleted.

0 comments on commit 8b8a0ce

Please sign in to comment.