mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
No global variables, fix tests.
This commit is contained in:
parent
3ddd6539c7
commit
5852d60dbf
1 changed files with 42 additions and 57 deletions
|
@ -1,31 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.pillar.saltclass as saltclass
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
base_path = os.path.dirname(os.path.realpath(__file__))
|
||||
fake_minion_id = "fake_id"
|
||||
fake_pillar = {}
|
||||
fake_args = {
|
||||
"path": os.path.abspath(
|
||||
os.path.join(
|
||||
base_path, "..", "..", "integration", "files", "saltclass", "examples"
|
||||
)
|
||||
)
|
||||
}
|
||||
fake_opts = {}
|
||||
fake_salt = {}
|
||||
fake_grains = {}
|
||||
|
||||
|
||||
class SaltclassPillarTestCase(TestCase, LoaderModuleMockMixin):
|
||||
"""
|
||||
|
@ -33,15 +16,16 @@ class SaltclassPillarTestCase(TestCase, LoaderModuleMockMixin):
|
|||
"""
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
saltclass: {
|
||||
"__opts__": fake_opts,
|
||||
"__salt__": fake_salt,
|
||||
"__grains__": fake_grains,
|
||||
}
|
||||
}
|
||||
return {saltclass: {}}
|
||||
|
||||
def _runner(self, expected_ret):
|
||||
fake_args = {
|
||||
"path": os.path.abspath(
|
||||
os.path.join(RUNTIME_VARS.FILES, "saltclass", "examples")
|
||||
)
|
||||
}
|
||||
fake_pillar = {}
|
||||
fake_minion_id = "fake_id"
|
||||
try:
|
||||
full_ret = saltclass.ext_pillar(fake_minion_id, fake_pillar, fake_args)
|
||||
parsed_ret = full_ret["__saltclass__"]["classes"]
|
||||
|
@ -49,38 +33,7 @@ class SaltclassPillarTestCase(TestCase, LoaderModuleMockMixin):
|
|||
except TypeError as err:
|
||||
self.fail(err)
|
||||
# Else give the parsed content result
|
||||
self.assertListEqual(parsed_ret, expected_ret)
|
||||
|
||||
def test_succeeds(self):
|
||||
ret = ["default.users", "default.motd", "default.empty", "default", "roles.app"]
|
||||
self._runner(ret)
|
||||
|
||||
|
||||
class SaltclassPillarTestCaseListExpansion(TestCase, LoaderModuleMockMixin):
|
||||
"""
|
||||
Tests for salt.pillar.saltclass variable expansion in list
|
||||
"""
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
saltclass: {
|
||||
"__opts__": fake_opts,
|
||||
"__salt__": fake_salt,
|
||||
"__grains__": fake_grains,
|
||||
}
|
||||
}
|
||||
|
||||
def _runner(self, expected_ret):
|
||||
full_ret = {}
|
||||
parsed_ret = []
|
||||
try:
|
||||
full_ret = saltclass.ext_pillar(fake_minion_id, fake_pillar, fake_args)
|
||||
parsed_ret = full_ret["test_list"]
|
||||
# Fail the test if we hit our NoneType error
|
||||
except TypeError as err:
|
||||
self.fail(err)
|
||||
# Else give the parsed content result
|
||||
self.assertListEqual(parsed_ret, expected_ret)
|
||||
self.assertListEqual(expected_ret, parsed_ret)
|
||||
|
||||
def test_succeeds(self):
|
||||
ret = [
|
||||
|
@ -92,3 +45,35 @@ class SaltclassPillarTestCaseListExpansion(TestCase, LoaderModuleMockMixin):
|
|||
"roles.nginx",
|
||||
]
|
||||
self._runner(ret)
|
||||
|
||||
|
||||
class SaltclassPillarTestCaseListExpansion(TestCase, LoaderModuleMockMixin):
|
||||
"""
|
||||
Tests for salt.pillar.saltclass variable expansion in list
|
||||
"""
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {saltclass: {}}
|
||||
|
||||
def _runner(self, expected_ret):
|
||||
full_ret = {}
|
||||
parsed_ret = []
|
||||
fake_args = {
|
||||
"path": os.path.abspath(
|
||||
os.path.join(RUNTIME_VARS.FILES, "saltclass", "examples")
|
||||
)
|
||||
}
|
||||
fake_pillar = {}
|
||||
fake_minion_id = "fake_id"
|
||||
try:
|
||||
full_ret = saltclass.ext_pillar(fake_minion_id, fake_pillar, fake_args)
|
||||
parsed_ret = full_ret["test_list"]
|
||||
# Fail the test if we hit our NoneType error
|
||||
except TypeError as err:
|
||||
self.fail(err)
|
||||
# Else give the parsed content result
|
||||
self.assertListEqual(expected_ret, parsed_ret)
|
||||
|
||||
def test_succeeds(self):
|
||||
ret = [{"a": "192.168.10.10"}, "192.168.10.20"]
|
||||
self._runner(ret)
|
||||
|
|
Loading…
Add table
Reference in a new issue