aboutsummaryrefslogtreecommitdiffstats
path: root/tools/archiver/tests/test.py
blob: b92d58f6a9853244607e967ca1c9fa7d5dd353b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import logging
from yatest import common as ytc

logger = logging.getLogger("test_logger")


class TestArchiver(object):
    @classmethod
    def setup_class(cls):
        cls.archiver_path = ytc.binary_path("tools/archiver/archiver")

    def test_recursive(self):
        assert 'archiver' == os.path.basename(self.archiver_path)
        assert os.path.exists(self.archiver_path)
        contents = ytc.source_path("tools/archiver/tests/directory")
        ytc.execute(
            command=[
                self.archiver_path,
                "--output", "archive",
                "--recursive",
                contents,
            ]
        )
        with open('result', 'w') as archive_list:
            ytc.execute(
                command=[
                    self.archiver_path,
                    "--list",
                    "archive",
                ],
                stdout=archive_list,
                stderr=None,
            )
        archive_list = sorted(open('result').read().strip().split('\n'))
        assert len(archive_list) == 3
        assert archive_list[0] == 'file1'
        assert archive_list[1] == 'file2'
        assert archive_list[2] == 'file3'

    def test_deduplicate(self):
        assert 'archiver' == os.path.basename(self.archiver_path)
        assert os.path.exists(self.archiver_path)
        contents = ytc.source_path("tools/archiver/tests/directory")
        ytc.execute(
            command=[
                self.archiver_path,
                "--output", "result_dedup",
                "--recursive",
                "--deduplicate",
                "--plain",
                contents,
            ]
        )
        ytc.execute(
            command=[
                self.archiver_path,
                "--output", "result_no_dedup",
                "--recursive",
                "--plain",
                contents,
            ]
        )
        with open('result_dedup', 'rb') as f_dedup, open('result_no_dedup', 'rb') as f_no_dedup:
            archive_dedup = f_dedup.read()
            archive_no_dedup = f_no_dedup.read()
        assert len(archive_dedup) == 58
        assert len(archive_no_dedup) == 75