diff options
author | zdc <zdc@users.noreply.github.com> | 2022-04-07 20:24:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-07 20:24:57 +0300 |
commit | 45c1d42e15f4a5fe5e176e1516b2da9d21e7837a (patch) | |
tree | 0535c3cf76b60dbf585416b4490c5bd9c9c99359 /tests/unittests/test_helpers.py | |
parent | 96226f37cdbdaef2fbc51de7b9ca75b61a16792b (diff) | |
parent | aa60d48c2711cdcd9f88a4e5c77379adb0408231 (diff) | |
download | vyos-cloud-init-45c1d42e15f4a5fe5e176e1516b2da9d21e7837a.tar.gz vyos-cloud-init-45c1d42e15f4a5fe5e176e1516b2da9d21e7837a.zip |
Merge pull request #52 from vyos/current
T2117: Backport Cloud-init 22.1 with our changes to VyOS 1.3
Diffstat (limited to 'tests/unittests/test_helpers.py')
-rw-r--r-- | tests/unittests/test_helpers.py | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/tests/unittests/test_helpers.py b/tests/unittests/test_helpers.py index 2e4582a0..69291597 100644 --- a/tests/unittests/test_helpers.py +++ b/tests/unittests/test_helpers.py @@ -3,10 +3,10 @@ """Tests of the built-in user data handlers.""" import os - -from cloudinit.tests import helpers as test_helpers +from pathlib import Path from cloudinit import sources +from tests.unittests import helpers as test_helpers class MyDataSource(sources.DataSource): @@ -24,8 +24,9 @@ class TestPaths(test_helpers.ResourceUsingTestCase): mypaths = self.getCloudPaths(myds) self.assertEqual( - os.path.join(mypaths.cloud_dir, 'instances', safe_iid), - mypaths.get_ipath()) + os.path.join(mypaths.cloud_dir, "instances", safe_iid), + mypaths.get_ipath(), + ) def test_get_ipath_and_empty_instance_id_returns_none(self): myds = MyDataSource(sys_cfg={}, distro=None, paths={}) @@ -34,4 +35,35 @@ class TestPaths(test_helpers.ResourceUsingTestCase): self.assertIsNone(mypaths.get_ipath()) + +class Testcloud_init_project_dir: + top_dir = test_helpers.get_top_level_dir() + + @staticmethod + def _get_top_level_dir_alt_implementation(): + """Alternative implementation for comparing against. + + Note: Recursively searching for .git/ fails during build tests due to + .git not existing. This implementation assumes that ../../../ is the + relative path to the cloud-init project directory form this file. + """ + out = Path(__file__).parent.parent.parent.resolve() + return out + + def test_top_level_dir(self): + """Assert the location of the top project directory is correct""" + assert self.top_dir == self._get_top_level_dir_alt_implementation() + + def test_cloud_init_project_dir(self): + """Assert cloud_init_project_dir produces an expected location + + Compare the returned value to an alternate (naive) implementation + """ + assert ( + str(Path(self.top_dir, "test")) + == test_helpers.cloud_init_project_dir("test") + == str(Path(self._get_top_level_dir_alt_implementation(), "test")) + ) + + # vi: ts=4 expandtab |