Skip to content

Commit 18a3370

Browse files
authored
Merge pull request #221 from myii/test/manage-map.jinja-verification
test(map): verify `map.jinja` dump using `_mapdata` state
2 parents 6ea8950 + 1a4d208 commit 18a3370

23 files changed

+3983
-9
lines changed

CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
/docs/AUTHORS.rst @saltstack-formulas/ssf
1616
/docs/CHANGELOG.rst @saltstack-formulas/ssf
1717
/docs/TOFS_pattern.rst @saltstack-formulas/ssf
18+
/*/_mapdata/ @saltstack-formulas/ssf
1819
/*/libsaltcli.jinja @saltstack-formulas/ssf
1920
/*/libtofs.jinja @saltstack-formulas/ssf
21+
/test/integration/**/_mapdata_spec.rb @saltstack-formulas/ssf
22+
/test/integration/**/libraries/system.rb @saltstack-formulas/ssf
2023
/test/integration/**/inspec.yml @saltstack-formulas/ssf
2124
/test/integration/**/README.md @saltstack-formulas/ssf
2225
/.gitignore @saltstack-formulas/ssf

kitchen.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ suites:
162162
state_top:
163163
base:
164164
'*':
165+
- php._mapdata
165166
- php.repo
166167
- php.fpm.install
167168
- php.fpm.config
@@ -188,6 +189,7 @@ suites:
188189
state_top:
189190
base:
190191
'*':
192+
- php._mapdata
191193
- php.repo
192194
- php.fpm.install
193195
- php.fpm.config
@@ -225,6 +227,7 @@ suites:
225227
state_top:
226228
base:
227229
'*':
230+
- php._mapdata
228231
- php
229232
pillars:
230233
top.sls:
@@ -246,6 +249,7 @@ suites:
246249
state_top:
247250
base:
248251
'*':
252+
- php._mapdata
249253
- php
250254
pillars:
251255
top.sls:

php/_mapdata/_mapdata.jinja

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# yamllint disable rule:indentation rule:line-length
2+
# {{ grains.get('osfinger', grains.os) }}
3+
---
4+
{#- use salt.slsutil.serialize to avoid encoding errors on some platforms #}
5+
{{ salt['slsutil.serialize'](
6+
'yaml',
7+
map,
8+
default_flow_style=False,
9+
allow_unicode=True,
10+
)
11+
| regex_replace("^\s+'$", "'", multiline=True)
12+
| trim
13+
}}

php/_mapdata/init.sls

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
---
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- from tplroot ~ "/map.jinja" import php as mapdata with context %}
7+
8+
{%- do salt['log.debug']('### MAP.JINJA DUMP ###\n' ~ mapdata | yaml(False)) %}
9+
10+
{%- set output_dir = '/temp' if grains.os_family == 'Windows' else '/tmp' %}
11+
{%- set output_file = output_dir ~ '/salt_mapdata_dump.yaml' %}
12+
13+
{{ tplroot }}-mapdata-dump:
14+
file.managed:
15+
- name: {{ output_file }}
16+
- source: salt://{{ tplroot }}/_mapdata/_mapdata.jinja
17+
- template: jinja
18+
- context:
19+
map: {{ mapdata | yaml }}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
require 'yaml'
4+
5+
control '`map.jinja` YAML dump' do
6+
title 'should match the comparison file'
7+
8+
# Strip the `platform[:finger]` version number down to the "OS major release"
9+
mapdata_file = "_mapdata/#{system.platform[:finger].split('.').first}.yaml"
10+
11+
# Load the mapdata from profile https://docs.chef.io/inspec/profiles/#profile-files
12+
mapdata_dump = YAML.safe_load(inspec.profile.file(mapdata_file))
13+
14+
# Derive the location of the dumped mapdata
15+
output_dir = platform[:family] == 'windows' ? '/temp' : '/tmp'
16+
output_file = "#{output_dir}/salt_mapdata_dump.yaml"
17+
18+
describe 'File content' do
19+
it 'should match profile map data exactly' do
20+
expect(yaml(output_file).params).to eq(mapdata_dump)
21+
end
22+
end
23+
end

test/integration/default/controls/config_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
# frozen_string_literal: true
2+
13
control 'Php configuration' do
24
title 'should match desired lines'
35

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

24-
def test_redhat
25-
end
28+
def test_redhat; end
2629

27-
def test_suse
28-
end
30+
def test_suse; end
2931

3032
case os[:family]
3133
when 'debian'

test/integration/default/controls/package_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
# frozen_string_literal: true
2+
13
control 'Php package' do
24
title 'should be installed'
35

6+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
47
def test_debian
58
describe package('php-imagick') do
69
it { should be_installed }
@@ -18,7 +21,6 @@ def test_debian
1821
bz2 cli curl fpm gd imap intl mbstring
1922
mysql readline xml zip
2023
].each do |pkg|
21-
2224
describe package("php5.6-#{pkg}") do
2325
it { should be_installed }
2426
end
@@ -28,6 +30,7 @@ def test_debian
2830
end
2931
end
3032
end
33+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
3134

3235
def test_redhat
3336
describe package('php') do

test/integration/default/controls/service_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
control 'Php service' do
24
title 'should be running and enabled'
35

@@ -13,11 +15,9 @@ def test_debian
1315
end
1416
end
1517

16-
def test_redhat
17-
end
18+
def test_redhat; end
1819

19-
def test_suse
20-
end
20+
def test_suse; end
2121

2222
case os[:family]
2323
when 'debian'

0 commit comments

Comments
 (0)