Skip to content

Commit 7673b6d

Browse files
authored
Merge pull request saltstack-formulas#63 from myii/test/manage-map.jinja-verification
test(map): verify `map.jinja` dump using `_mapdata` state
2 parents af49850 + 2b9a968 commit 7673b6d

File tree

18 files changed

+230
-0
lines changed

18 files changed

+230
-0
lines changed

CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
/docs/AUTHORS.rst @saltstack-formulas/ssf
2020
/docs/CHANGELOG.rst @saltstack-formulas/ssf
2121
/docs/TOFS_pattern.rst @saltstack-formulas/ssf
22+
/*/_mapdata/ @saltstack-formulas/ssf
2223
/*/libsaltcli.jinja @saltstack-formulas/ssf
2324
/*/libtofs.jinja @saltstack-formulas/ssf
25+
/test/integration/**/_mapdata_spec.rb @saltstack-formulas/ssf
26+
/test/integration/**/libraries/system.rb @saltstack-formulas/ssf
2427
/test/integration/**/inspec.yml @saltstack-formulas/ssf
2528
/test/integration/**/README.md @saltstack-formulas/ssf
2629
/.gitignore @saltstack-formulas/ssf

kitchen.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ suites:
156156
state_top:
157157
base:
158158
'*':
159+
- rabbitmq._mapdata
159160
- states.files
160161
- rabbitmq
161162
- rabbitmq.config_files
@@ -179,6 +180,7 @@ suites:
179180
state_top:
180181
base:
181182
'*':
183+
- rabbitmq._mapdata
182184
- states.files
183185
- rabbitmq.latest
184186
- rabbitmq.config_files

rabbitmq/_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+
}}

rabbitmq/_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 ~ "/package-map.jinja" import pkgs 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
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# yamllint disable rule:indentation rule:line-length
2+
# CentOS Linux-7
3+
---
4+
rabbitmq-server: rabbitmq-server
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# yamllint disable rule:indentation rule:line-length
2+
# CentOS Linux-8
3+
---
4+
rabbitmq-server: rabbitmq-server
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# yamllint disable rule:indentation rule:line-length
2+
# Debian-10
3+
---
4+
rabbitmq-server: rabbitmq-server
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# yamllint disable rule:indentation rule:line-length
2+
# Debian-9
3+
---
4+
rabbitmq-server: rabbitmq-server
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# yamllint disable rule:indentation rule:line-length
2+
# Fedora-30
3+
---
4+
rabbitmq-server: rabbitmq-server

0 commit comments

Comments
 (0)