def test_instance_to_be_created_with_root_pass(default_args, mock_linode,
                                               capfd, access_token):
    default_args.update({
        'type': 'foo',
        'region': 'bar',
        'image': 'baz',
        'root_pass': '******',
    })
    set_module_args(default_args)

    target = 'linode_api4.linode_client.LinodeGroup.instances'
    with mock.patch(target, return_value=[]):
        with pytest.raises(SystemExit) as sys_exit_exc:
            target = 'linode_api4.linode_client.LinodeGroup.instance_create'
            with mock.patch(target, return_value=mock_linode):
                linode_v4.main()

    assert sys_exit_exc.value.code == 0

    out, err = capfd.readouterr()
    results = json.loads(out)

    assert results['changed'] is True
    assert (results['instance']['label'] == mock_linode._raw_json['label'])
    assert 'root_pass' not in results['instance']
def test_instance_already_deleted_no_change(default_args, mock_linode, capfd,
                                            access_token):
    default_args.update({'state': 'absent'})
    set_module_args(default_args)

    target = 'linode_api4.linode_client.LinodeGroup.instances'
    with mock.patch(target, return_value=[]):
        with pytest.raises(SystemExit) as sys_exit_exc:
            linode_v4.main()

    assert sys_exit_exc.value.code == 0

    out, err = capfd.readouterr()
    results = json.loads(out)

    assert results['changed'] is False
    assert results['instance'] == {}