예제 #1
0
def test_get_ref(hgfs_setup_and_teardown):
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
        },
    ):
        repo = hgfs.init()[0]
        hgfs.update()
        repo["repo"].open()
        ref = hgfs._get_ref(repo, "base")
        assert isinstance(ref, tuple)
        assert len(ref) == 3
        assert ref[0] == "default"
        assert ref[1] == 1
        assert isinstance(ref[2], str)

    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "bookmark_test"
                }]
            }],
            "hgfs_branch_method":
            "bookmarks",
        },
    ):
        repo = hgfs.init()[0]
        hgfs.update()
        repo["repo"].open()
        ref = hgfs._get_ref(repo, "base")
        assert isinstance(ref, tuple)
        assert len(ref) == 3
        assert ref[0] in "bookmark_test"
        assert ref[1] == 2
        assert isinstance(ref[2], str)

    # Fail test
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
        },
    ):
        repo = hgfs.init()[0]
        hgfs.update()
        repo["repo"].open()
        ref = hgfs._get_ref(repo, "fake")
        assert ref is False
예제 #2
0
def test_env_is_exposed_whitelist():
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_saltenv_whitelist": "base",
            "hgfs_saltenv_blacklist": ""
        },
    ):
        hgfs.init()
        hgfs.update()
        assert hgfs._env_is_exposed("base") is True
        assert hgfs._env_is_exposed("test") is False
        assert hgfs._env_is_exposed("unset") is False
예제 #3
0
def test_dir_list(hgfs_setup_and_teardown):
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
        },
    ):
        hgfs.init()
        hgfs.update()
        load = {"saltenv": "base", "loc": 0, "path": "test.sls"}
        data = hgfs.dir_list(load)
        assert data == ["subdir"]
예제 #4
0
def test_get_manifest(hgfs_setup_and_teardown):
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
        },
    ):
        repo = hgfs.init()[0]
        hgfs.update()
        repo["repo"].open()
        ref = hgfs._get_ref(repo, "base")
        manifest = hgfs._get_manifest(repo["repo"], ref=ref)
        assert isinstance(manifest, list)
        for value in manifest:
            assert len(value) == 5
            assert isinstance(value[0], str)
            assert value[1] == "644"
            assert value[2] is False
            assert value[3] is False
            assert value[4] in [
                "test.sls",
                "test2.sls",
                ".hgtags",
                "subdir/test.sls",
                "subdir/test2.sls",
            ]
예제 #5
0
def test_get_tag(hgfs_setup_and_teardown):
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
        },
    ):
        repo = hgfs.init()
        hgfs.update()
        repo[0]["repo"].open()
        tag = hgfs._get_tag(repo[0]["repo"], "test")
        assert isinstance(tag, tuple)
        assert len(tag) == 4
        assert tag[0] in "test"
        assert tag[1] == 0
        assert isinstance(tag[2], str)

        # Fail test
        tag = hgfs._get_tag(repo[0]["repo"], "fake")
        assert tag is False

        # real tag that should fail
        tag = hgfs._get_tag(repo[0]["repo"], "tip")
        assert tag is False
예제 #6
0
def test_all_tags(hgfs_setup_and_teardown):
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
        },
    ):
        repos = hgfs.init()
        hgfs.update()
        for repo in repos:
            repo["repo"].open()
            tags = hgfs._all_tags(repo["repo"])
            assert isinstance(tags, list)
            if isinstance(tags, list):
                for value in tags:
                    assert isinstance(value, tuple)
                    assert len(value) == 4
                    assert value[0] in ["test"]
                    assert value[0] not in ["tip"]
                    assert value[1] == 0
                    assert isinstance(value[2], str)
                    assert value[3] is False
예제 #7
0
def test_find_file(hgfs_setup_and_teardown):
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
        },
    ):
        hgfs.init()
        hgfs.update()
        file = hgfs.find_file(path="test.sls", tgt_env="base")
        assert file[
            "path"] == hgfs.__opts__["cachedir"] + "/hgfs/refs/base/test.sls"
        assert file["rel"] == "test.sls"
        assert isinstance(file["stat"], list)
        for i in file["stat"]:
            assert isinstance(i, int)
예제 #8
0
def test_serve_file(hgfs_setup_and_teardown):
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
        },
    ):
        hgfs.init()
        hgfs.update()
        file = hgfs.find_file(path="test.sls", tgt_env="base")
        load = {"saltenv": "base", "loc": 0, "path": "test.sls"}
        data = hgfs.serve_file(load, file)
        assert data == {
            "data":
            "always-passes:\n  test.succeed_without_changes:\n    - name: foo\n",
            "dest": "test.sls",
        }
예제 #9
0
def test_file_hash(hgfs_setup_and_teardown):
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
        },
    ):
        hgfs.init()
        hgfs.update()
        file = hgfs.find_file(path="test.sls", tgt_env="base")
        load = {"saltenv": "base", "loc": 0, "path": "test.sls"}
        data = hgfs.file_hash(load, file)
        assert data == {
            "hash_type":
            "sha256",
            "hsum":
            "a6a48d90dce9c9b580efb2ed308af100a8328913dcf9441705125866551c7d8d",
        }
예제 #10
0
def test_envs(hgfs_setup_and_teardown):
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
            "hgfs_branch_method": "branches",
        },
    ):
        hgfs.init()
        hgfs.update()
        envs = hgfs.envs(ignore_cache=True)
        assert isinstance(envs, list)
        assert envs == ["base", "test"]
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "bookmark_test"
                }]
            }],
            "hgfs_branch_method":
            "bookmarks",
        },
    ):
        hgfs.init()
        hgfs.update()
        envs = hgfs.envs(ignore_cache=True)
        assert isinstance(envs, list)

        # apperently test is coming from the tags which will always be included in the envs unless blacklisted.
        # Do we really want that behavior?
        assert envs == ["base", "test"]
예제 #11
0
 def test_fix_58852(self):
     """
     test to make sure python 3 can init hgfs
     """
     with patch.dict(
         hgfs.__opts__,
         {
             "cachedir": "/tmp/barf",
             "hgfs_base": "fnord",
             "hgfs_branch_method": "fnord",
             "hgfs_mountpoint": "fnord",
             "hgfs_root": "fnord",
             "hgfs_remotes": "fnord",
         },
     ):
         self.assertIsInstance(hgfs.init(), list)
예제 #12
0
def test_fix_58852(hgfs_setup_and_teardown):
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
        },
    ):
        repo = hgfs.init()
        assert isinstance(repo, list)
        if isinstance(repo, list):
            for value in repo:
                assert isinstance(value, dict)
                for key, value in value.items():
                    if key != "repo":
                        assert isinstance(value, str)
예제 #13
0
def test_all_branches(hgfs_setup_and_teardown):
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
        },
    ):
        repos = hgfs.init()
        hgfs.update()
        for repo in repos:
            repo["repo"].open()
            branches = hgfs._all_branches(repo["repo"])
            assert isinstance(branches, list)
            if isinstance(branches, list):
                for value in branches:
                    assert isinstance(value, tuple)
                    assert len(value) == 3
                    assert value[0] in ["default", "test"]
                    assert isinstance(value[1], int)
                    assert isinstance(value[2], str)
예제 #14
0
def test_get_bookmark(hgfs_setup_and_teardown):
    with patch.dict(
            hgfs.__opts__,
        {
            "hgfs_remotes": [{
                str(hgfs_setup_and_teardown): [{
                    "base": "default"
                }]
            }],
        },
    ):
        repo = hgfs.init()
        hgfs.update()
        repo[0]["repo"].open()
        bookmark = hgfs._get_bookmark(repo[0]["repo"], "bookmark_test")
        assert isinstance(bookmark, tuple)
        assert len(bookmark) == 3
        assert bookmark[0] in "bookmark_test"
        assert bookmark[1] == 2
        assert isinstance(bookmark[2], str)

        # Fail test
        bookmark = hgfs._get_bookmark(repo[0]["repo"], "fake")
        assert bookmark is False