diff options
author | Scott Moser <smoser@ubuntu.com> | 2017-02-10 22:08:03 -0500 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2017-05-10 10:43:09 -0400 |
commit | 370a04e8d7b530c1ef8280e15eb628ff6880c736 (patch) | |
tree | 4c94b8064391ffde56ea908cd049a9c745440026 /tests/unittests/helpers.py | |
parent | 4f0f171c29bb9abb5cbb6f9adbe68015089aeed9 (diff) | |
download | vyos-cloud-init-370a04e8d7b530c1ef8280e15eb628ff6880c736.tar.gz vyos-cloud-init-370a04e8d7b530c1ef8280e15eb628ff6880c736.zip |
Add unit tests for ds-identify, fix Ec2 bug found.
This adds several unit tests for ds-identify, and fixes a bug
in Ec2 detection that I found while writing these tests.
The method of testing is to use the ds-identify code as a shell
library. The TestDsIdentify:call basically does:
* populate a (temp) directory with files that represent what
ds-identify would see in /sys or other locations it reads.
* create a file '_shwrap' that replaces the 3 programs that are executed
in ds-identify code path. It supports setting their stdout, stderr,
and exit code.
* set the default policies explicitly (DI_DEFAULT_POLICY) so we can
support testing different builtins. This is necessary because the
Ubuntu branches patch the builtin value. If we did not explicilty set
it, then testing there would fail.
* execute sh to source the script and call its main.
Diffstat (limited to 'tests/unittests/helpers.py')
-rw-r--r-- | tests/unittests/helpers.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py index 90e2431f..a711404c 100644 --- a/tests/unittests/helpers.py +++ b/tests/unittests/helpers.py @@ -3,6 +3,7 @@ from __future__ import print_function import functools +import json import os import shutil import sys @@ -280,6 +281,12 @@ def dir2dict(startdir, prefix=None): return flist +def json_dumps(data): + # print data in nicely formatted json. + return json.dumps(data, indent=1, sort_keys=True, + separators=(',', ': ')) + + def wrap_and_call(prefix, mocks, func, *args, **kwargs): """ call func(args, **kwargs) with mocks applied, then unapplies mocks |