Skip to content

Commit aa0f1e0

Browse files
authored
Merge pull request #80 from myii/test/manage-map.jinja-verification
test(map): verify `map.jinja` dump using `_mapdata` state
2 parents 901d706 + 96a1a03 commit aa0f1e0

26 files changed

Lines changed: 2445 additions & 0 deletions

kitchen.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ suites:
528528
provisioner:
529529
dependencies:
530530
- name: node
531+
branch: test-kitchen
531532
repo: git
532533
source: https://github.com/saltstack-formulas/node-formula.git
533534
state_top:
@@ -807,6 +808,7 @@ suites:
807808
state_top:
808809
base:
809810
'*':
811+
- packages._mapdata
810812
- packages.chocolatey
811813
pillars:
812814
top.sls:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
require 'yaml'
4+
5+
control 'packages._mapdata' do
6+
title '`map.jinja` should match the reference file'
7+
8+
### Method
9+
# The steps below for each file appear convoluted but they are both required
10+
# and similar in nature:
11+
# 1. The earliest method was to simply compare the files textually but this often
12+
# led to false positives due to inconsistencies (e.g. spacing, ordering)
13+
# 2. The next method was to load the files back into YAML structures and then
14+
# compare but InSpec provided block diffs this way, unusable by end users
15+
# 3. The final step was to dump the YAML structures back into a string to use
16+
# for the comparison; this both worked and provided human-friendly diffs
17+
18+
### Comparison file for the specific platform
19+
### Static, adjusted as part of code contributions, as map data is changed
20+
# Strip the `platform[:finger]` version number down to the "OS major release"
21+
platform_finger = system.platform[:finger].split('.').first.to_s
22+
# Use that to set the path to the file (relative to the InSpec suite directory)
23+
mapdata_file_path = "_mapdata/#{platform_finger}.yaml"
24+
# Load the mapdata from profile, into a YAML structure
25+
# https://docs.chef.io/inspec/profiles/#profile-files
26+
mapdata_file_yaml = YAML.load(inspec.profile.file(mapdata_file_path))
27+
# Dump the YAML back into a string for comparison
28+
mapdata_file_dump = YAML.dump(mapdata_file_yaml)
29+
30+
### Output file produced by running the `_mapdata` state
31+
### Dynamic, generated during Kitchen's `converge` phase
32+
# Derive the location of the dumped mapdata (differs for Windows)
33+
output_dir = platform[:family] == 'windows' ? '/temp' : '/tmp'
34+
# Use that to set the path to the file (absolute path, i.e. within the container)
35+
output_file_path = "#{output_dir}/salt_mapdata_dump.yaml"
36+
# Load the output into a YAML structure using InSpec's `yaml` resource
37+
# https://github.com/inspec/inspec/blob/49b7d10/lib/inspec/resources/yaml.rb#L29
38+
output_file_yaml = yaml(output_file_path).params
39+
# Dump the YAML back into a string for comparison
40+
output_file_dump = YAML.dump(output_file_yaml)
41+
42+
describe 'File content' do
43+
it 'should match profile map data exactly' do
44+
expect(output_file_dump).to eq(mapdata_file_dump)
45+
end
46+
end
47+
end
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# yamllint disable rule:indentation rule:line-length
2+
# AlmaLinux-8
3+
---
4+
values:
5+
archives:
6+
pkgs:
7+
required:
8+
- curl
9+
- bzip2
10+
- gzip
11+
required:
12+
archives: {}
13+
types:
14+
- tar
15+
- zip
16+
- rar
17+
unwanted: []
18+
wanted: {}
19+
chocolatey:
20+
required:
21+
pkgs: []
22+
states: []
23+
unwanted: []
24+
wanted: []
25+
gems:
26+
required:
27+
pkgs:
28+
- rubygems
29+
states: []
30+
unwanted:
31+
- diff-lcs
32+
- kitchen-vagrant
33+
- kwalify
34+
wanted:
35+
- progressbar
36+
golang:
37+
clean: []
38+
goget: []
39+
kernel: linux
40+
npms:
41+
required:
42+
pkgs: []
43+
states: []
44+
unwanted: []
45+
wanted: []
46+
pips:
47+
config: []
48+
required:
49+
pkgs:
50+
- gcc
51+
- python3-pip
52+
states: []
53+
unwanted:
54+
- campbel
55+
- reverse_geocode
56+
- indy-crypto
57+
wanted:
58+
- attrs
59+
pkgs:
60+
held:
61+
- iotop
62+
required:
63+
pkgs:
64+
- git
65+
- python3-dnf-plugin-versionlock
66+
states: []
67+
unwanted:
68+
- avahi-daemon
69+
wanted:
70+
- git
71+
- less
72+
- bc
73+
- curl
74+
- fail2ban
75+
remote_pkgs:
76+
zoom: https://zoom.us/client/latest/zoom_x86_64.rpm
77+
retry_options:
78+
attempts: 1
79+
interval: 60
80+
splay: 10
81+
until: true
82+
rootuser: root
83+
snaps:
84+
classic: []
85+
collides: []
86+
packages: []
87+
required:
88+
pkgs: []
89+
states: []
90+
service:
91+
- snapd
92+
symlink: false
93+
unwanted: []
94+
wanted: []
95+
tmpdir: /tmp/saltstack-packages-formula-archives
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# yamllint disable rule:indentation rule:line-length
2+
# Amazon Linux-2
3+
---
4+
values:
5+
archives:
6+
pkgs:
7+
required:
8+
- curl
9+
- bzip2
10+
- gzip
11+
required:
12+
archives: {}
13+
types:
14+
- tar
15+
- zip
16+
- rar
17+
unwanted: []
18+
wanted: {}
19+
chocolatey:
20+
required:
21+
pkgs: []
22+
states: []
23+
unwanted: []
24+
wanted: []
25+
gems:
26+
required:
27+
pkgs:
28+
- rubygems
29+
states: []
30+
unwanted:
31+
- diff-lcs
32+
- kitchen-vagrant
33+
- kwalify
34+
wanted:
35+
- progressbar
36+
golang:
37+
clean: []
38+
goget: []
39+
kernel: linux
40+
npms:
41+
required:
42+
pkgs: []
43+
states: []
44+
unwanted: []
45+
wanted: []
46+
pips:
47+
config: []
48+
required:
49+
pkgs:
50+
- gcc
51+
- python3-pip
52+
states: []
53+
unwanted:
54+
- campbel
55+
- reverse_geocode
56+
- indy-crypto
57+
wanted:
58+
- attrs
59+
pkgs:
60+
held: {}
61+
required:
62+
pkgs:
63+
- git
64+
- yum-plugin-versionlock
65+
states: []
66+
unwanted:
67+
- avahi-daemon
68+
wanted:
69+
- git
70+
- less
71+
- bc
72+
- curl
73+
- fail2ban
74+
remote_pkgs:
75+
zoom: https://zoom.us/client/latest/zoom_x86_64.rpm
76+
retry_options:
77+
attempts: 1
78+
interval: 60
79+
splay: 10
80+
until: true
81+
rootuser: root
82+
snaps:
83+
classic: []
84+
collides: []
85+
packages:
86+
- snapd
87+
- fuse
88+
required:
89+
pkgs: []
90+
states: []
91+
service:
92+
- snapd
93+
symlink: false
94+
unwanted: []
95+
wanted: []
96+
tmpdir: /tmp/saltstack-packages-formula-archives
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# yamllint disable rule:indentation rule:line-length
2+
# Arch
3+
---
4+
values:
5+
archives:
6+
pkgs:
7+
required:
8+
- curl
9+
- bzip2
10+
- gzip
11+
required:
12+
archives: {}
13+
types:
14+
- tar
15+
- zip
16+
- rar
17+
unwanted: []
18+
wanted: {}
19+
chocolatey:
20+
required:
21+
pkgs: []
22+
states: []
23+
unwanted: []
24+
wanted: []
25+
gems:
26+
required:
27+
pkgs: []
28+
states: []
29+
unwanted:
30+
- diff-lcs
31+
- kitchen-vagrant
32+
- kwalify
33+
wanted:
34+
- progressbar
35+
- minitest
36+
golang:
37+
clean: []
38+
goget: []
39+
kernel: linux
40+
npms:
41+
required:
42+
pkgs: []
43+
states: []
44+
unwanted: []
45+
wanted: []
46+
pips:
47+
config: []
48+
required:
49+
pkgs: []
50+
states: []
51+
unwanted:
52+
- campbel
53+
- reverse_geocode
54+
- indy-crypto
55+
wanted:
56+
- attrs
57+
pkgs:
58+
held:
59+
- iotop
60+
required:
61+
pkgs:
62+
- git
63+
states: []
64+
unwanted:
65+
- avahi-daemon
66+
wanted:
67+
- ruby
68+
- git
69+
- less
70+
- bc
71+
- curl
72+
- fail2ban
73+
remote_pkgs: {}
74+
retry_options:
75+
attempts: 1
76+
interval: 60
77+
splay: 10
78+
until: true
79+
rootuser: root
80+
snaps:
81+
classic: []
82+
collides: []
83+
packages:
84+
- snapd
85+
- fuse
86+
required:
87+
pkgs: []
88+
states: []
89+
service:
90+
- snapd
91+
symlink: false
92+
unwanted: []
93+
wanted: []
94+
tmpdir: /tmp/saltstack-packages-formula-archives

0 commit comments

Comments
 (0)