xref: /OK3568_Linux_fs/buildroot/support/testing/tests/download/test_git.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1import os
2import shutil
3
4from tests.download.gitremote import GitRemote
5
6import infra
7
8
9class GitTestBase(infra.basetest.BRConfigTest):
10    config = \
11        """
12        BR2_BACKUP_SITE=""
13        """
14    gitremotedir = infra.filepath("tests/download/git-remote")
15    gitremote = None
16
17    def setUp(self):
18        super(GitTestBase, self).setUp()
19        self.gitremote = GitRemote(self.builddir, self.gitremotedir, self.logtofile)
20
21    def tearDown(self):
22        self.show_msg("Cleaning up")
23        if self.gitremote:
24            self.gitremote.stop()
25        if self.b and not self.keepbuilds:
26            self.b.delete()
27
28    def check_hash(self, package):
29        # store downloaded tarball inside the output dir so the test infra
30        # cleans it up at the end
31        env = {"BR2_DL_DIR": os.path.join(self.builddir, "dl"),
32               "GITREMOTE_PORT_NUMBER": str(self.gitremote.port)}
33        self.b.build(["{}-dirclean".format(package),
34                      "{}-source".format(package)],
35                     env)
36
37    def check_download(self, package):
38        # store downloaded tarball inside the output dir so the test infra
39        # cleans it up at the end
40        dl_dir = os.path.join(self.builddir, "dl")
41        # enforce we test the download
42        if os.path.exists(dl_dir):
43            shutil.rmtree(dl_dir)
44        env = {"BR2_DL_DIR": dl_dir,
45               "GITREMOTE_PORT_NUMBER": str(self.gitremote.port)}
46        self.b.build(["{}-dirclean".format(package),
47                      "{}-legal-info".format(package)],
48                     env)
49
50
51class TestGitHash(GitTestBase):
52    br2_external = [infra.filepath("tests/download/br2-external/git-hash")]
53
54    def test_run(self):
55        with self.assertRaises(SystemError):
56            self.check_hash("bad")
57        self.check_hash("good")
58        self.check_hash("nohash")
59
60
61class TestGitRefs(GitTestBase):
62    br2_external = [infra.filepath("tests/download/br2-external/git-refs")]
63
64    def test_run(self):
65        with self.assertRaises(SystemError):
66            self.check_download("git-wrong-content")
67        with self.assertRaises(SystemError):
68            self.check_download("git-wrong-sha1")
69        self.check_download("git-partial-sha1-branch-head")
70        self.check_download("git-partial-sha1-reachable-by-branch")
71        self.check_download("git-partial-sha1-reachable-by-tag")
72        self.check_download("git-partial-sha1-tag-itself")
73        self.check_download("git-partial-sha1-tag-points-to")
74        self.check_download("git-sha1-branch-head")
75        self.check_download("git-sha1-reachable-by-branch")
76        self.check_download("git-sha1-reachable-by-tag")
77        self.check_download("git-sha1-tag-itself")
78        self.check_download("git-sha1-tag-points-to")
79        self.check_download("git-submodule-disabled")
80        self.check_download("git-submodule-enabled")
81        self.check_download("git-tag")
82