Skip to content

Instantly share code, notes, and snippets.

@jquast
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jquast/038c5400535a1276430d to your computer and use it in GitHub Desktop.
Save jquast/038c5400535a1276430d to your computer and use it in GitHub Desktop.
./proj/tests/unit/test_pillars_yaml.py
"""
Ensure all pillar references and files are found, and parse successfully.
"""
# std imports
import itertools
import os
# local
from ..accessories import (
PILLARS_TOP,
walk_pillar,
walk_sls,
)
# 3rd-party
import pytest
import salt.config
@pytest.mark.parametrize("path", list(walk_pillar()))
def test_verify_pillar(path):
"""
Verify parsing of tree of files defined by pillars/top.sls
"""
# given, exercise
assert os.path.exists(path)
contents = salt.config.load_config(path=path, env_var=None)
# verify
assert isinstance(contents, dict)
def test_no_duplicated_pillars():
"""
Ensure a given pillar is only referenced once per top.sls
"""
# given
all_pillars = list(walk_pillar())
# verify:
for sls in all_pillars:
num = all_pillars.count(sls)
assert 1 == num, ('file {0} referenced too many times in {1}'
.format(sls, PILLARS_TOP))
def test_pillars_all_referenced():
""" Ensure all pillar files are referenced. """
all_sls = list(walk_sls(root=os.path.dirname(PILLARS_TOP)))
for discovered in itertools.chain(walk_pillar()):
assert discovered in all_sls, (discovered, all_sls)
all_sls.remove(discovered)
assert all_sls == []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment