Esempio n. 1
0
def test_update_package_code(conf_dir, cmk_dir):
    if not cmk_dir.exists():
        pytest.skip("cmk_dir '{}' is not good".format(cmk_dir))
    src = cmk_dir / u"agents/wnx/test_files/msibuild/msi/check_mk_agent.msi"
    if not src.exists():
        pytest.skip("Path '{}' with MSI doesn't exist".format(src))
    # prepare file to tests
    tgt = conf_dir / "check_mk_agent.msi"
    try:
        src = cmk_dir / u"agents/wnx/test_files/msibuild/msi/check_mk_agent.msi"
        assert src.exists()
        content = src.read_bytes()
        pos_initial = content.find(b"BAEBF560-7308-4")
        assert pos_initial != -1
        if tgt.exists():
            tgt.unlink()

        # random uuid
        assert not tgt.exists()
        assert msi_update.copy_file_safe(src, tgt)
        msi_update.update_package_code(tgt)
        tgt_content = tgt.read_bytes()
        assert tgt_content.find(b"BAEBF560-7308-4") == -1

        if tgt.exists():
            tgt.unlink()

        # case for the uuid in command line
        assert not tgt.exists()
        assert msi_update.copy_file_safe(src, tgt)
        msi_update.update_package_code(
            tgt, "{01234567-1234-1234-1234-012345678901}")
        tgt_content = tgt.read_bytes()
        pos = tgt_content.find(b"01234567-1234-1234")
        assert pos == pos_initial

        if tgt.exists():
            tgt.unlink()

        # case for the hash
        assert not tgt.exists()
        assert msi_update.copy_file_safe(src, tgt)
        msi_update.update_package_code(tgt, "012")
        tgt_content = tgt.read_bytes()
        pos = tgt_content.find(b"21FAC8EF-8042-50CA-8C85-FBCA566E726E")

        assert pos == pos_initial
    finally:
        if tgt.exists():
            tgt.unlink()
Esempio n. 2
0
def test_update_package_code(conf_dir, cmk_dir):
    if not cmk_dir.exists():
        pytest.skip("cmk_dir '{}' is not good".format(cmk_dir))
    src = cmk_dir.joinpath(
        u"agents/wnx/test_files/msibuild/msi/check_mk_agent.msi")
    if not src.exists():
        pytest.skip("Path '{}' with MSI doesn't exist".format(src))
    # prepare file to tests
    tgt = conf_dir.joinpath("check_mk_agent.msi")
    try:
        src = cmk_dir.joinpath(
            u"agents/wnx/test_files/msibuild/msi/check_mk_agent.msi")
        assert src.exists()
        content = src.read_bytes()
        assert content.find(b"BAEBF560-7308-4") != -1
        if tgt.exists():
            tgt.unlink()

        assert not tgt.exists()
        assert msi_update.copy_file_safe(src, tgt)
        msi_update.update_package_code(src.name, tgt.__fspath__())
        content = tgt.read_bytes()
        assert content.find(b"BAEBF560-7308-4") == -1
    finally:
        if tgt.exists():
            tgt.unlink()
Esempio n. 3
0
def test_make_msi_copy(conf_dir):
    src_file = Path(conf_dir, "temp.in")
    with src_file.open('w') as s:
        s.write("+++".decode("utf8"))
    dst_file = Path(conf_dir, "temp.out")
    assert msi_update.copy_file_safe(src_file, dst_file)
    assert dst_file.exists()
    with dst_file.open('r') as d:
        content = d.read()
    assert content == "+++"