def test_main_list(monkeypatch, capsys, mocked_sysexit, mocked_configure):
server_id = pytest.faux.gen_uuid()
host = pytest.faux.gen_alphanumeric()
username = pytest.faux.gen_alphanumeric()
initiator_id = pytest.faux.gen_uuid()
tsk = task.ServerDiscoveryTask(server_id, host, username, initiator_id)
tsk = tsk.create()
monkeypatch.setenv(process.ENV_ENTRY_POINT, "server_discovery")
monkeypatch.setenv(process.ENV_TASK_ID, str(tsk._id))
monkeypatch.setattr("sys.argv", ["progname", "--list"])
assert inventory.main() == os.EX_OK
mocked_sysexit.assert_not_called()
out, _ = capsys.readouterr()
arg = json.loads(out)
assert arg["new"]["hosts"] == [host]
assert arg["_meta"]["hostvars"][host]["ansible_user"] == username
评论列表
文章目录