summaryrefslogtreecommitdiffstats
path: root/support/testing/tests/download/test_git.py
blob: 83fb6fe3cd564cda6c5516b4b905a418cfbd4557 (plain)
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
69
70
71
72
import os
import shutil

from gitremote import GitRemote

import infra


class GitTestBase(infra.basetest.BRTest):
    config = \
        """
        BR2_BACKUP_SITE=""
        """
    gitremotedir = infra.filepath("tests/download/git-remote")
    gitremote = None

    def setUp(self):
        super(GitTestBase, self).setUp()
        self.gitremote = GitRemote(self.builddir, self.gitremotedir, self.logtofile)

    def tearDown(self):
        self.show_msg("Cleaning up")
        if self.gitremote:
            self.gitremote.stop()
        if self.b and not self.keepbuilds:
            self.b.delete()

    def check_hash(self, package):
        # store downloaded tarball inside the output dir so the test infra
        # cleans it up at the end
        env = {"BR2_DL_DIR": os.path.join(self.builddir, "dl"),
               "GITREMOTE_PORT_NUMBER": str(self.gitremote.port)}
        self.b.build(["{}-dirclean".format(package),
                      "{}-source".format(package)],
                     env)

    def check_download(self, package):
        # store downloaded tarball inside the output dir so the test infra
        # cleans it up at the end
        dl_dir = os.path.join(self.builddir, "dl")
        # enforce we test the download
        if os.path.exists(dl_dir):
            shutil.rmtree(dl_dir)
        env = {"BR2_DL_DIR": dl_dir,
               "GITREMOTE_PORT_NUMBER": str(self.gitremote.port)}
        self.b.build(["{}-dirclean".format(package),
                      "{}-legal-info".format(package)],
                     env)


class TestGitHash(GitTestBase):
    br2_external = [infra.filepath("tests/download/br2-external/git-hash")]

    def test_run(self):
        with self.assertRaises(SystemError):
            self.check_hash("bad")
        self.check_hash("good")
        self.check_hash("nohash")


class TestGitRefs(GitTestBase):
    br2_external = [infra.filepath("tests/download/br2-external/git-refs")]

    def test_run(self):
        with self.assertRaises(SystemError):
            self.check_download("git-wrong-content")
        with self.assertRaises(SystemError):
            self.check_download("git-wrong-sha1")
        self.check_download("git-partial-sha1-branch-head")
        self.check_download("git-partial-sha1-reachable-by-branch")
        self.check_download("git-sha1-branch-head")
        self.check_download("git-sha1-reachable-by-branch")
OpenPOWER on IntegriCloud