1import os
2import shutil
3
4import infra
5
6
7class GitforgeTestBase(infra.basetest.BRConfigTest):
8    config = \
9        """
10        BR2_BACKUP_SITE=""
11        """
12
13    def setUp(self):
14        super(GitforgeTestBase, self).setUp()
15
16    def tearDown(self):
17        self.show_msg("Cleaning up")
18        if self.b and not self.keepbuilds:
19            self.b.delete()
20
21    def check_download(self, package):
22        # store downloaded tarball inside the output dir so the test infra
23        # cleans it up at the end
24        dl_dir = os.path.join(self.builddir, "dl")
25        # enforce we test the download
26        if os.path.exists(dl_dir):
27            shutil.rmtree(dl_dir)
28        env = {"BR2_DL_DIR": dl_dir}
29        self.b.build(["{}-dirclean".format(package),
30                      "{}-legal-info".format(package)],
31                     env)
32
33
34class TestGitHub(GitforgeTestBase):
35    br2_external = [infra.filepath("tests/download/br2-external/github")]
36
37    def test_run(self):
38        self.check_download("github-helper-tag")
39        self.check_download("github-helper-hash")
40        self.check_download("github-release")
41
42
43class TestGitLab(GitforgeTestBase):
44    br2_external = [infra.filepath("tests/download/br2-external/gitlab")]
45
46    def test_run(self):
47        self.check_download("gitlab-helper-hash")
48        self.check_download("gitlab-helper-tag")
49        self.check_download("gitlab-release")
50