|
| 1 | +"""unit test for faas list module""" |
| 2 | + |
| 3 | +__metaclass__ = type |
| 4 | + |
| 5 | + |
| 6 | +import json |
| 7 | +import pytest |
| 8 | +from mschuchard.general.tests.unit.plugins.modules import utils |
| 9 | +from mschuchard.general.plugins.modules import faas_list |
| 10 | + |
| 11 | + |
| 12 | +def test_faas_list_defaults(capfd): |
| 13 | + """test faas list with defaults""" |
| 14 | + utils.set_module_args({'config_file': f'{str(utils.fixtures_dir())}/stack.yaml'}) |
| 15 | + with pytest.raises(SystemExit, match='1'): |
| 16 | + faas_list.main() |
| 17 | + |
| 18 | + stdout, stderr = capfd.readouterr() |
| 19 | + assert not stderr |
| 20 | + |
| 21 | + info = json.loads(stdout) |
| 22 | + assert 'faas-cli' in info['cmd'] |
| 23 | + assert 'list' in info['cmd'] |
| 24 | + assert '-f' in info['cmd'] |
| 25 | + assert f'{str(utils.fixtures_dir())}/stack.yaml' in info['cmd'] |
| 26 | + assert '[\'openfaas\'] is the only valid "provider.name" for the OpenFaaS CLI, but you gave: \n' == info['stdout'] |
| 27 | + |
| 28 | + |
| 29 | +def test_faas_list_config_file(capfd): |
| 30 | + """test faas list with config file""" |
| 31 | + utils.set_module_args({'config_file': f'{str(utils.fixtures_dir())}/stack.yaml', 'filter': '*gif*', 'regex': 'fn[0-9]_.*'}) |
| 32 | + with pytest.raises(SystemExit, match='1'): |
| 33 | + faas_list.main() |
| 34 | + |
| 35 | + stdout, stderr = capfd.readouterr() |
| 36 | + assert not stderr |
| 37 | + |
| 38 | + info = json.loads(stdout) |
| 39 | + assert 'faas-cli' in info['cmd'] |
| 40 | + assert 'list' in info['cmd'] |
| 41 | + assert '-f' in info['cmd'] |
| 42 | + assert '--filter' in info['cmd'] |
| 43 | + assert '*gif*' in info['cmd'] |
| 44 | + assert '--regex' in info['cmd'] |
| 45 | + assert 'fn[0-9]_.*' in info['cmd'] |
| 46 | + assert f'{str(utils.fixtures_dir())}/stack.yaml' in info['cmd'] |
| 47 | + assert '[\'openfaas\'] is the only valid "provider.name" for the OpenFaaS CLI, but you gave: \n' == info['stdout'] |
| 48 | + |
| 49 | + |
| 50 | +def test_faas_list_sort_invocations_verbose(capfd): |
| 51 | + """test faas list sorted by invocations""" |
| 52 | + utils.set_module_args({'config_file': f'{str(utils.fixtures_dir())}/stack.yaml', 'sort': 'invocations', 'verbose': True}) |
| 53 | + with pytest.raises(SystemExit, match='1'): |
| 54 | + faas_list.main() |
| 55 | + |
| 56 | + stdout, stderr = capfd.readouterr() |
| 57 | + assert not stderr |
| 58 | + |
| 59 | + info = json.loads(stdout) |
| 60 | + assert 'faas-cli' in info['cmd'] |
| 61 | + assert 'list' in info['cmd'] |
| 62 | + assert '--sort' in info['cmd'] |
| 63 | + assert 'invocations' in info['cmd'] |
| 64 | + assert '-v' in info['cmd'] |
| 65 | + assert f'{str(utils.fixtures_dir())}/stack.yaml' in info['cmd'] |
| 66 | + assert '[\'openfaas\'] is the only valid "provider.name" for the OpenFaaS CLI, but you gave: \n' == info['stdout'] |
0 commit comments