Skip to content

Commit

Permalink
test(map): verify map.jinja dump using _mapdata state [skip ci]
Browse files Browse the repository at this point in the history
* Automated using myii/ssf-formula#275
  • Loading branch information
myii committed Dec 21, 2020
1 parent 37eaca3 commit d34d850
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
12 changes: 5 additions & 7 deletions sudoers/_mapdata/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
---
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import sudoers with context %}
{%- from tplroot ~ "/map.jinja" import sudoers as mapdata with context %}
{%- set map = {
'sudoers': sudoers,
} %}
{%- do salt['log.debug']('### MAP.JINJA DUMP ###\n' ~ map | yaml(False)) %}
{%- do salt['log.debug']('### MAP.JINJA DUMP ###\n' ~ mapdata | yaml(False)) %}
{%- set output_file = '/tmp/salt_mapdata_dump.yaml' %}
{%- set output_dir = '/temp' if grains.os_family == 'Windows' else '/tmp' %}
{%- set output_file = output_dir ~ '/salt_mapdata_dump.yaml' %}
{{ tplroot }}-mapdata-dump:
file.managed:
- name: {{ output_file }}
- source: salt://{{ tplroot }}/_mapdata/_mapdata.jinja
- template: jinja
- context:
map: {{ map | yaml }}
map: {{ mapdata | yaml }}
15 changes: 12 additions & 3 deletions test/integration/default/controls/_mapdata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
require 'yaml'

control '`map.jinja` YAML dump' do
title 'should contain exactly the same data as the comparison file'
title 'should match the comparison file'

# Strip the `platform[:finger]` version number down to the "OS major release"
mapdata_file = "_mapdata/#{system.platform[:finger].split('.').first}.yaml"

# Load the mapdata from profile https://docs.chef.io/inspec/profiles/#profile-files
mapdata_dump = YAML.safe_load(inspec.profile.file(mapdata_file))

describe yaml('/tmp/salt_mapdata_dump.yaml').params do
it { should eq mapdata_dump }
# Derive the location of the dumped mapdata
output_dir = platform[:family] == 'windows' ? '/temp' : '/tmp'
output_file = "#{output_dir}/salt_mapdata_dump.yaml"

describe 'File content' do
it 'should match profile map data exactly' do
expect(yaml(output_file).params).to eq(mapdata_dump)
end
end
end
19 changes: 19 additions & 0 deletions test/integration/share/libraries/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ def build_platform_name
case inspec.platform[:name]
when 'amazon'
'amazonlinux'
when 'windows_8.1_pro'
'windows'
when 'windows_server_2019_datacenter'
'windows-server'
else
inspec.platform[:name]
end
end

# rubocop:disable Metrics/MethodLength
def build_platform_release
case inspec.platform[:name]
when 'amazon'
Expand All @@ -52,10 +57,24 @@ def build_platform_release
'base-latest'
when 'gentoo'
"#{inspec.platform[:release].split('.')[0]}-#{derive_gentoo_init_system}"
when 'windows_8.1_pro'
'8.1'
when 'windows_server_2019_datacenter'
'2019'
else
inspec.platform[:release]
end
end
# rubocop:enable Metrics/MethodLength

def derive_gentoo_init_system
case inspec.command('systemctl').exist?
when true
'sysd'
else
'sysv'
end
end

def derive_gentoo_init_system
case inspec.command('systemctl').exist?
Expand Down

0 comments on commit d34d850

Please sign in to comment.