Skip to content

Commit

Permalink
(SIMP-9883) Generalize simpkv acceptance tests (#63)
Browse files Browse the repository at this point in the history
Rewrote simpkv acceptance tests used by the file plugin
so that the test infrastructure can be used by any plugin
or any combination of plugins. Also, addressed test
deficiencies such as the absence of global key testing and
test infrastructure design flaws such as the confusing,
unnecessary coupling of test data and the simpkv_test module.

This test infrastructure is required for the ldap plugin.
  • Loading branch information
lnemsick-simp authored Sep 23, 2021
1 parent b8b584e commit 4708811
Show file tree
Hide file tree
Showing 76 changed files with 3,890 additions and 746 deletions.
42 changes: 42 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,30 @@ pup6.pe:
pup6.pe-fips:
<<: *pup_6_pe
<<: *acceptance_base
<<: *with_SIMP_ACCEPTANCE_MATRIX_LEVEL_3
script:
- 'BEAKER_fips=yes bundle exec rake beaker:suites[default,default]'

pup6.x.centos7:
<<: *pup_6_x
<<: *acceptance_base
script:
- 'bundle exec rake beaker:suites[default,centos7]'

pup6.x.centos7-fips:
<<: *pup_6_x
<<: *acceptance_base
<<: *with_SIMP_ACCEPTANCE_MATRIX_LEVEL_3
script:
- 'BEAKER_fips=yes bundle exec rake beaker:suites[default,centos7]'

pup6.pe.centos7:
<<: *pup_6_pe
<<: *acceptance_base
<<: *with_SIMP_ACCEPTANCE_MATRIX_LEVEL_3
script:
- 'bundle exec rake beaker:suites[default,centos7]'

pup6.pe-oel:
<<: *pup_6_pe
<<: *acceptance_base
Expand All @@ -369,8 +390,29 @@ pup6.pe-oel-fips:
script:
- 'BEAKER_fips=yes bundle exec rake beaker:suites[default,oel]'

pup6.pe.centos7-oel:
<<: *pup_6_pe
<<: *acceptance_base
<<: *with_SIMP_ACCEPTANCE_MATRIX_LEVEL_3
script:
- 'bundle exec rake beaker:suites[default,oel7]'

pup6.pe.centos7-oel-fips:
<<: *pup_6_pe
<<: *acceptance_base
<<: *with_SIMP_ACCEPTANCE_MATRIX_LEVEL_3
script:
- 'BEAKER_fips=yes bundle exec rake beaker:suites[default,oel7]'

pup7.x:
<<: *pup_7_x
<<: *acceptance_base
script:
- 'bundle exec rake beaker:suites[default,default]'

pup7.x.centos7:
<<: *pup_7_x
<<: *acceptance_base
<<: *with_SIMP_ACCEPTANCE_MATRIX_LEVEL_3
script:
- 'bundle exec rake beaker:suites[default,centos7]'
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,10 @@ To create your own plugin
test shows you how to instantiate an object of your plugin for testing
purposes.
* Write acceptance tests for your plugin, using the acceptance tests for
simpkv's file plugin, `spec/acceptances/suites/default/file_plugin_spec.rb`,
as an example. That test uses a test module, `spec/support/simpkv_test` to
exercise the the simpkv API and verify its operation.
simpkv's file plugin in `spec/acceptances/suites/default/`,
as an example. That test uses a test module, `spec/support/simpkv_test`
and a plugin-specific validator to exercise the the simpkv API and verify its
operation with the file plugin.
* Document your plugin's type and configuration parameters in the README.md for
your store plugin module.

Expand Down
2 changes: 2 additions & 0 deletions spec/acceptance/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rb_files = File.expand_path( 'helpers/**/*.rb', __dir__)
Dir.glob( rb_files ).sort_by(&:to_s).each { |file| require file }
119 changes: 119 additions & 0 deletions spec/acceptance/helpers/files/initial_key_info.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
# NOTES FOR TEST MAINTAINERS:
# This file specifies test key information in a data structure corresponding to
# the Simpkv_test::KeyInfo type alias. This data or data derived from it will be
# used to stimulate simpkv_test manifests to test simpkv functions.
#
# ** Please take time to understand how the simpkv_test module works! **
#
# Important details about this key information are as follows:
# * The keys are designed to cover a wide variety of keys types a user could
# specify. This includes:
# - Keys with simple values (Boolean, Integer, Float, String)
# - Keys with complex values (Hash, Array)
# - Keys that have to be handled with special Puppet code (Binary values)
# - Puppet-environment-specific keys
# - Global keys
# - Keys with/without metadata
# - Keys with/without path elements in their key names
# * The keys are explicitly designed to test that key uniqueness is
# appropriately handled.
# - Keys are supposed to be uniquely specified by their
# {key path, global status, and backend} triples.
# - This data and the tests **ASSUME** a one-to-one mapping of app_id
# to backend, and so a key is uniquely specified by its
# {key path, global status, and app_id} triple.
# - This file contains multiple keys with the same key path, but different
# content and different combinations of app_id and global status.
# * The key info is also designed to test different folder configurations
# - Folders with keys and sub-folders
# - Folders with only keys
# - Folders with only sub-folders
#
# Also of note:
# - This file currently only supports 3 different app_ids.
# - Binary data is loaded with the Puppet binary_file() method, so the
# 'file' specification must match what that function requires.
# - Validation logic elsewhere assumes the Binary value of a key will be found
# in a file in the simpkv_test module.
#
"<%= appid1 %>":
env:
boolean:
value: true
integer:
value: 1234567890
metadata:
verified: true
float:
value: 0.123
string:
value: "test string1"
metadata:
author: "Sally Smith"
complex/array_integers:
value:
- 8
- 9
- 10
metadata:
normalized: true
complex/array_strings:
value:
- 'test string2'
complex/hash:
value:
attr1: "test string2"
attr2: 11.0
attr3: false
attr4:
part1: "test string3"
part2: true
part3:
- 12
- 13
empty/string:
value: ""
empty/complex/array:
value: []
empty/complex/hash:
value: {}
global:
boolean:
value: false
string:
value: "global test string1"
metadata:
auditor: "Jill Jones"
binary/keytabs/test_krb5.keytab:
file: "simpkv_test/test_krb5.keytab"
metadata:
comment: "from simp/krb5 test"
"<%= appid2 %>":
# list will have no sub-folders
env:
integer:
value: 123
float:
value: 45.678
metadata:
origin: sensor
version: 3
global:
integer:
value: 901
metadata:
truncated: true
string:
value: "global test string2"

"<%= appid3 %>":
env:
# list will have only sub-folders
complex/hash:
value:
location: rack1
slot: 10
metadata:
last_reviewed: "2021-08-30"
# global list will be empty
25 changes: 25 additions & 0 deletions spec/acceptance/helpers/manifest_utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Acceptance
module Helpers
module ManifestUtils

def print_test_config(hieradata, manifest)
puts '>'*80
if hieradata.is_a?(Hash)
puts "Hieradata:\n#{hieradata.to_yaml}"
else
puts "Hieradata:\n#{hieradata}"
end
puts '-'*80
puts "Manifest:\n#{manifest}"
puts '<'*80
end

def set_hiera_and_apply_on(host, hieradata, manifest, apply_opts = {}, verbose = true )
print_test_config(hieradata, manifest) if verbose
set_hieradata_on(host, hieradata)
apply_manifest_on(host, manifest, apply_opts)
end

end
end
end
Loading

0 comments on commit 4708811

Please sign in to comment.