Skip to content

Commit

Permalink
test(_mapdata_spec): perform comparison using describe yaml instead
Browse files Browse the repository at this point in the history
  • Loading branch information
myii committed Dec 21, 2020
1 parent 7af3bf2 commit 65e82f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions openssh/_mapdata/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import mapdata with context %}
{%- set output_file = '/tmp/salt_mapdata_dump.yaml' %}
{%- set map = mapdata %}
{%- do salt['log.debug']('### MAP.JINJA DUMP ###\n' ~ map | yaml(False)) %}
{%- do salt['log.debug']( mapdata | yaml(False) ) %}
{%- set output_file = '/tmp/salt_mapdata_dump.yaml' %}
{{ tplroot }}-mapdata-dump:
file.managed:
- name: {{ output_file }}
- source: salt://{{ tplroot }}/_mapdata/_mapdata.jinja
- template: jinja
- context:
map: {{ mapdata | yaml }}
map: {{ map | yaml }}
18 changes: 12 additions & 6 deletions test/integration/default/controls/_mapdata_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# frozen_string_literal: true

mapdata_file = "_mapdata/#{system.platform[:finger].split('.').first}.yaml"
mapdata_dump = inspec.profile.file(mapdata_file)
require 'yaml'

# Replace per minion strings
replacement = {
hostname: system.hostname
}

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

mapdata_file = "_mapdata/#{system.platform[:finger].split('.').first}.yaml"
mapdata_dump = YAML.safe_load(inspec.profile.file(mapdata_file) % replacement)

describe file('/tmp/salt_mapdata_dump.yaml') do
it { should exist }
its('content') { should eq mapdata_dump }
describe yaml('/tmp/salt_mapdata_dump.yaml').params do
it { should eq mapdata_dump }
end
end

0 comments on commit 65e82f6

Please sign in to comment.