Skip to content

test(map): verify map.jinja dump using _mapdata state #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
/docs/AUTHORS.rst @saltstack-formulas/ssf
/docs/CHANGELOG.rst @saltstack-formulas/ssf
/docs/TOFS_pattern.rst @saltstack-formulas/ssf
/*/_mapdata/ @saltstack-formulas/ssf
/*/libsaltcli.jinja @saltstack-formulas/ssf
/*/libtofs.jinja @saltstack-formulas/ssf
/test/integration/**/_mapdata_spec.rb @saltstack-formulas/ssf
/test/integration/**/libraries/system.rb @saltstack-formulas/ssf
/test/integration/**/inspec.yml @saltstack-formulas/ssf
/test/integration/**/README.md @saltstack-formulas/ssf
/.gitignore @saltstack-formulas/ssf
Expand Down
4 changes: 4 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ suites:
state_top:
base:
'*':
- php._mapdata
- php.repo
- php.fpm.install
- php.fpm.config
Expand All @@ -188,6 +189,7 @@ suites:
state_top:
base:
'*':
- php._mapdata
- php.repo
- php.fpm.install
- php.fpm.config
Expand Down Expand Up @@ -225,6 +227,7 @@ suites:
state_top:
base:
'*':
- php._mapdata
- php
pillars:
top.sls:
Expand All @@ -246,6 +249,7 @@ suites:
state_top:
base:
'*':
- php._mapdata
- php
pillars:
top.sls:
Expand Down
13 changes: 13 additions & 0 deletions php/_mapdata/_mapdata.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# yamllint disable rule:indentation rule:line-length
# {{ grains.get('osfinger', grains.os) }}
---
{#- use salt.slsutil.serialize to avoid encoding errors on some platforms #}
{{ salt['slsutil.serialize'](
'yaml',
map,
default_flow_style=False,
allow_unicode=True,
)
| regex_replace("^\s+'$", "'", multiline=True)
| trim
}}
19 changes: 19 additions & 0 deletions php/_mapdata/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
---
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import php as mapdata with context %}

{%- do salt['log.debug']('### MAP.JINJA DUMP ###\n' ~ mapdata | yaml(False)) %}

{%- 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: {{ mapdata | yaml }}
23 changes: 23 additions & 0 deletions test/integration/default/controls/_mapdata_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'yaml'

control '`map.jinja` YAML dump' do
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))

# 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
10 changes: 6 additions & 4 deletions test/integration/default/controls/config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

control 'Php configuration' do
title 'should match desired lines'

# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def test_debian
describe file('/etc/php/5.6/fpm/pool.d/radius-admin.conf') do
its('content') { should include '[radius-admin]' }
Expand All @@ -20,12 +23,11 @@ def test_debian
its('content') { should include 'date.timezone = Europe/Paris' }
end
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize

def test_redhat
end
def test_redhat; end

def test_suse
end
def test_suse; end

case os[:family]
when 'debian'
Expand Down
5 changes: 4 additions & 1 deletion test/integration/default/controls/package_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

control 'Php package' do
title 'should be installed'

# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def test_debian
describe package('php-imagick') do
it { should be_installed }
Expand All @@ -18,7 +21,6 @@ def test_debian
bz2 cli curl fpm gd imap intl mbstring
mysql readline xml zip
].each do |pkg|

describe package("php5.6-#{pkg}") do
it { should be_installed }
end
Expand All @@ -28,6 +30,7 @@ def test_debian
end
end
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize

def test_redhat
describe package('php') do
Expand Down
8 changes: 4 additions & 4 deletions test/integration/default/controls/service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

control 'Php service' do
title 'should be running and enabled'

Expand All @@ -13,11 +15,9 @@ def test_debian
end
end

def test_redhat
end
def test_redhat; end

def test_suse
end
def test_suse; end

case os[:family]
when 'debian'
Expand Down
Loading