tests: Add test for Recipe.freeze() function
The freeze function was not being tested. Add a test for it using the
repos.git test recipe.
(cherry picked from commit c26477a63c
)
This commit is contained in:
parent
2e596010d3
commit
bdf5572bc6
@ -1 +1 @@
|
|||||||
{'description': u'An example http server with PHP and MySQL support.', 'packages': [], 'groups': [], 'modules': [], 'version': u'0.0.1', 'name': u'http-server', 'repos': {'git': [{"rpmname": "server-config-files", "rpmversion": "1.0", "rpmrelease": "1", "summary": "Setup files for server deployment", "repo": "https://github.com/bcl/server-config-files", "ref": "v3.0", "destination": "/srv/config/"}]}}
|
{'description': u'An example http server with PHP and MySQL support.', 'packages': [], 'groups': [], 'modules': [{'version': u'2.4.*', 'name': u'httpd'}, {'version': u'5.4.*', 'name': u'php'}], 'version': u'0.0.1', 'name': u'http-server', 'repos': {'git': [{"rpmname": "server-config-files", "rpmversion": "1.0", "rpmrelease": "1", "summary": "Setup files for server deployment", "repo": "https://github.com/bcl/server-config-files", "ref": "v3.0", "destination": "/srv/config/"}]}}
|
||||||
|
@ -2,6 +2,14 @@ name = "http-server"
|
|||||||
description = "An example http server with PHP and MySQL support."
|
description = "An example http server with PHP and MySQL support."
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
|
|
||||||
|
[[modules]]
|
||||||
|
name = "httpd"
|
||||||
|
version = "2.4.*"
|
||||||
|
|
||||||
|
[[modules]]
|
||||||
|
name = "php"
|
||||||
|
version = "5.4.*"
|
||||||
|
|
||||||
[[repos.git]]
|
[[repos.git]]
|
||||||
rpmname="server-config-files"
|
rpmname="server-config-files"
|
||||||
rpmversion="1.0"
|
rpmversion="1.0"
|
||||||
|
@ -40,13 +40,13 @@ class BasicRecipeTest(unittest.TestCase):
|
|||||||
("custom-base.toml", "custom-base.dict"),
|
("custom-base.toml", "custom-base.dict"),
|
||||||
("repos-git.toml", "repos-git.dict")]
|
("repos-git.toml", "repos-git.dict")]
|
||||||
results_path = "./tests/pylorax/results/"
|
results_path = "./tests/pylorax/results/"
|
||||||
self.input_toml = []
|
self.input_toml = {}
|
||||||
for (recipe_toml, recipe_dict) in input_recipes:
|
for (recipe_toml, recipe_dict) in input_recipes:
|
||||||
with open(joinpaths(results_path, recipe_toml)) as f_toml:
|
with open(joinpaths(results_path, recipe_toml)) as f_toml:
|
||||||
with open(joinpaths(results_path, recipe_dict)) as f_dict:
|
with open(joinpaths(results_path, recipe_dict)) as f_dict:
|
||||||
# XXX Warning, can run arbitrary code
|
# XXX Warning, can run arbitrary code
|
||||||
result_dict = eval(f_dict.read())
|
result_dict = eval(f_dict.read())
|
||||||
self.input_toml.append((f_toml.read(), result_dict))
|
self.input_toml[recipe_toml] = (f_toml.read(), result_dict)
|
||||||
|
|
||||||
self.old_modules = [recipes.RecipeModule("toml", "2.1"),
|
self.old_modules = [recipes.RecipeModule("toml", "2.1"),
|
||||||
recipes.RecipeModule("bash", "5.*"),
|
recipes.RecipeModule("bash", "5.*"),
|
||||||
@ -80,7 +80,7 @@ class BasicRecipeTest(unittest.TestCase):
|
|||||||
|
|
||||||
def toml_to_recipe_test(self):
|
def toml_to_recipe_test(self):
|
||||||
"""Test converting the TOML string to a Recipe object"""
|
"""Test converting the TOML string to a Recipe object"""
|
||||||
for (toml_str, recipe_dict) in self.input_toml:
|
for (toml_str, recipe_dict) in self.input_toml.values():
|
||||||
result = recipes.recipe_from_toml(toml_str)
|
result = recipes.recipe_from_toml(toml_str)
|
||||||
self.assertEqual(result, recipe_dict)
|
self.assertEqual(result, recipe_dict)
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ class BasicRecipeTest(unittest.TestCase):
|
|||||||
"""Test converting a Recipe object to a TOML string"""
|
"""Test converting a Recipe object to a TOML string"""
|
||||||
# In order to avoid problems from matching strings we convert to TOML and
|
# In order to avoid problems from matching strings we convert to TOML and
|
||||||
# then back so compare the Recipes.
|
# then back so compare the Recipes.
|
||||||
for (toml_str, _recipe_dict) in self.input_toml:
|
for (toml_str, _recipe_dict) in self.input_toml.values():
|
||||||
# This is tested in toml_to_recipe
|
# This is tested in toml_to_recipe
|
||||||
recipe_1 = recipes.recipe_from_toml(toml_str)
|
recipe_1 = recipes.recipe_from_toml(toml_str)
|
||||||
# Convert the Recipe to TOML and then back to a Recipe
|
# Convert the Recipe to TOML and then back to a Recipe
|
||||||
@ -160,6 +160,34 @@ class BasicRecipeTest(unittest.TestCase):
|
|||||||
{'new': {'Package': {'name': 'git', 'version': '2.13.*'}}, 'old': None}]
|
{'new': {'Package': {'name': 'git', 'version': '2.13.*'}}, 'old': None}]
|
||||||
self.assertEqual(recipes.recipe_diff(old_recipe, new_recipe), result)
|
self.assertEqual(recipes.recipe_diff(old_recipe, new_recipe), result)
|
||||||
|
|
||||||
|
def recipe_freeze_test(self):
|
||||||
|
"""Test the recipe freeze() function"""
|
||||||
|
# Use the repos-git.toml test, it only has http and php in it
|
||||||
|
deps = [{"arch": "x86_64",
|
||||||
|
"epoch": 0,
|
||||||
|
"name": "httpd",
|
||||||
|
"release": "1.el7",
|
||||||
|
"version": "2.4.11"},
|
||||||
|
{"arch": "x86_64",
|
||||||
|
"epoch": 0,
|
||||||
|
"name": "php",
|
||||||
|
"release": "1.el7",
|
||||||
|
"version": "5.4.2"}]
|
||||||
|
result = recipes.recipe_from_toml(self.input_toml["repos-git.toml"][0])
|
||||||
|
self.assertEqual(result, self.input_toml["repos-git.toml"][1])
|
||||||
|
|
||||||
|
# Freeze the recipe with our fake deps
|
||||||
|
frozen = result.freeze(deps)
|
||||||
|
self.assertTrue(frozen is not None)
|
||||||
|
http_module = recipes.find_name("httpd", frozen["modules"])
|
||||||
|
self.assertTrue(http_module is not None)
|
||||||
|
self.assertEqual(http_module["version"], "2.4.11-1.el7.x86_64")
|
||||||
|
|
||||||
|
php_module = recipes.find_name("php", frozen["modules"])
|
||||||
|
self.assertTrue(php_module is not None)
|
||||||
|
self.assertEqual(php_module["version"], "5.4.2-1.el7.x86_64")
|
||||||
|
|
||||||
|
|
||||||
class GitRecipesTest(unittest.TestCase):
|
class GitRecipesTest(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(self):
|
def setUpClass(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user