Example #1
0
def test_grep_query_exists_with_opt(multiline_file):
    result = filemod.grep(multiline_file, "Lorem ipsum", "-i")

    assert result, None
    assert result["retcode"] == 0
    assert result["stdout"] == "Lorem ipsum dolor sit amet, consectetur"
    assert result["stderr"] == ""
Example #2
0
def test_grep_query_exists_wildcard(multiline_file):
    _file = "{}*".format(multiline_file)
    result = filemod.grep(_file, "Lorem ipsum")

    assert result, None
    assert result["retcode"] == 0
    assert result["stdout"] == "Lorem ipsum dolor sit amet, consectetur"
    assert result["stderr"] == ""
Example #3
0
def test_grep_file_not_exists_wildcard(multiline_file):
    _file = "{}-junk*".format(multiline_file)
    result = filemod.grep(_file, "Lorem ipsum")

    assert result, None
    assert not result["retcode"] == 0
    assert not result["stdout"] == "Lorem ipsum dolor sit amet, consectetur"
    _expected_stderr = "grep: {}-junk*: No such file or directory".format(
        multiline_file)
    assert result["stderr"] == _expected_stderr
Example #4
0
def test_mod_repo(revert_repo_file):
    """
    Test aptpkg.mod_repo when the repo exists.
    """
    test_repo, comps = get_current_repo()
    msg = "This is a test"
    with patch.dict(aptpkg.__salt__, {"config.option": Mock()}):
        ret = aptpkg.mod_repo(repo=test_repo, comments=msg)
    assert sorted(ret[list(ret.keys())[0]]["comps"]) == sorted(comps)
    ret = file.grep("/etc/apt/sources.list", msg)
    assert "#{}".format(msg) in ret["stdout"]
Example #5
0
def test_grep_query_not_exists(multiline_file):
    result = filemod.grep(multiline_file, "Lorem Lorem")

    assert result["retcode"] == 1
    assert result["stdout"] == ""
    assert result["stderr"] == ""
Example #6
0
def test_grep_query_too_many_opts(multiline_file):
    with pytest.raises(SaltInvocationError,
                       match="^Passing multiple command line arg") as cm:
        result = filemod.grep(multiline_file, "Lorem Lorem", "-i -b2")
Example #7
0
def test_grep_query_not_exists_opt(multiline_file, multiline_string):
    result = filemod.grep(multiline_file, "Lorem Lorem", "-v")

    assert result["retcode"] == 0
    assert result["stdout"] == multiline_string
    assert result["stderr"] == ""