From 7a6ebb0ad31e79ff7b156617e83cf38ef1571eea Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Thu, 7 Feb 2019 09:48:17 -0800 Subject: [PATCH] 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 c26477a63caffce9df8baae7f52d0ca7349fd0e9) (cherry picked from commit bdf5572bc60f50eda61d074162dc85c7e2fdba0e) --- tests/pylorax/results/repos-git.dict | 2 +- tests/pylorax/results/repos-git.toml | 8 +++++++ tests/pylorax/test_recipes.py | 36 ++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/tests/pylorax/results/repos-git.dict b/tests/pylorax/results/repos-git.dict index 7ae43135..cf180a6c 100644 --- a/tests/pylorax/results/repos-git.dict +++ b/tests/pylorax/results/repos-git.dict @@ -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/"}]}} diff --git a/tests/pylorax/results/repos-git.toml b/tests/pylorax/results/repos-git.toml index 832dc948..f6f9634e 100644 --- a/tests/pylorax/results/repos-git.toml +++ b/tests/pylorax/results/repos-git.toml @@ -2,6 +2,14 @@ name = "http-server" description = "An example http server with PHP and MySQL support." version = "0.0.1" +[[modules]] +name = "httpd" +version = "2.4.*" + +[[modules]] +name = "php" +version = "5.4.*" + [[repos.git]] rpmname="server-config-files" rpmversion="1.0" diff --git a/tests/pylorax/test_recipes.py b/tests/pylorax/test_recipes.py index a5b7df0c..26e3d4d0 100644 --- a/tests/pylorax/test_recipes.py +++ b/tests/pylorax/test_recipes.py @@ -40,13 +40,13 @@ class BasicRecipeTest(unittest.TestCase): ("custom-base.toml", "custom-base.dict"), ("repos-git.toml", "repos-git.dict")] results_path = "./tests/pylorax/results/" - self.input_toml = [] + self.input_toml = {} for (recipe_toml, recipe_dict) in input_recipes: with open(joinpaths(results_path, recipe_toml)) as f_toml: with open(joinpaths(results_path, recipe_dict)) as f_dict: # XXX Warning, can run arbitrary code 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"), recipes.RecipeModule("bash", "4.*"), @@ -80,7 +80,7 @@ class BasicRecipeTest(unittest.TestCase): def toml_to_recipe_test(self): """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) self.assertEqual(result, recipe_dict) @@ -96,7 +96,7 @@ class BasicRecipeTest(unittest.TestCase): """Test converting a Recipe object to a TOML string""" # In order to avoid problems from matching strings we convert to TOML and # 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 recipe_1 = recipes.recipe_from_toml(toml_str) # 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}] 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): @classmethod def setUpClass(self):