~andrewjbeach/juju-ci-tools/make-local-patcher

897.2.1 by Martin Packman
Simple build and test script for merge gating go projects using git
1
import subprocess
2
import unittest
3
4
import git_gate
5
6
7
class TestParseArgs(unittest.TestCase):
8
913.1.1 by Martin Packman
Fix git gate arg tests given added restriction
9
    def test_project_and_url(self):
10
        args = git_gate.parse_args(
11
            ["--project", "git.testing/project",
12
             "--project-url", "https://git.testing/project"])
897.2.1 by Martin Packman
Simple build and test script for merge gating go projects using git
13
        self.assertEqual(args.project, "git.testing/project")
913.1.1 by Martin Packman
Fix git gate arg tests given added restriction
14
        self.assertEqual(args.project_url, "https://git.testing/project")
897.2.1 by Martin Packman
Simple build and test script for merge gating go projects using git
15
16
    def test_project_and_ref(self):
906.2.3 by John George
Drive-by lint cleanup.
17
        args = git_gate.parse_args(
913.1.1 by Martin Packman
Fix git gate arg tests given added restriction
18
            ["--project", "git.testing/project", "--go-get-all",
906.2.3 by John George
Drive-by lint cleanup.
19
             "--project-ref", "v1"])
897.2.1 by Martin Packman
Simple build and test script for merge gating go projects using git
20
        self.assertEqual(args.project, "git.testing/project")
21
        self.assertEqual(args.project_ref, "v1")
22
23
    def test_merging_other(self):
906.2.3 by John George
Drive-by lint cleanup.
24
        args = git_gate.parse_args(
913.1.1 by Martin Packman
Fix git gate arg tests given added restriction
25
            ["--project", "git.testing/project", "--go-get-all",
906.2.3 by John George
Drive-by lint cleanup.
26
             "--merge-url", "git.testing/proposed"])
897.2.1 by Martin Packman
Simple build and test script for merge gating go projects using git
27
        self.assertEqual(args.project, "git.testing/project")
28
        self.assertEqual(args.merge_url, "git.testing/proposed")
29
        self.assertEqual(args.merge_ref, "HEAD")
30
31
    def test_merging_other_ref(self):
906.2.3 by John George
Drive-by lint cleanup.
32
        args = git_gate.parse_args(
913.1.1 by Martin Packman
Fix git gate arg tests given added restriction
33
            ["--project", "git.testing/project", "--go-get-all",
906.2.3 by John George
Drive-by lint cleanup.
34
             "--merge-url", "git.testing/proposed", "--merge-ref", "feature"])
897.2.1 by Martin Packman
Simple build and test script for merge gating go projects using git
35
        self.assertEqual(args.project, "git.testing/project")
36
        self.assertEqual(args.merge_url, "git.testing/proposed")
37
        self.assertEqual(args.merge_ref, "feature")
38
39
    def test_project_with_deps(self):
906.2.3 by John George
Drive-by lint cleanup.
40
        args = git_gate.parse_args(
41
            ["--project", "git.testing/project",
913.1.1 by Martin Packman
Fix git gate arg tests given added restriction
42
             "--project-url", "https://git.testing/project",
909.1.2 by Martin Packman
Clean up argument handling and behaviours
43
             "--dependencies", "git.testing/a", "git.testing/b"])
44
        self.assertEqual(args.project, "git.testing/project")
913.1.1 by Martin Packman
Fix git gate arg tests given added restriction
45
        self.assertEqual(args.project_url, "https://git.testing/project")
909.1.2 by Martin Packman
Clean up argument handling and behaviours
46
        self.assertEqual(args.dependencies, ["git.testing/a", "git.testing/b"])
47
        self.assertEqual(args.go_get_all, False)
48
49
    def test_project_with_go_deps(self):
50
        args = git_gate.parse_args(
51
            ["--project", "git.testing/project", "--go-get-all"])
52
        self.assertEqual(args.project, "git.testing/project")
53
        self.assertEqual(args.dependencies, None)
54
        self.assertEqual(args.go_get_all, True)
897.2.1 by Martin Packman
Simple build and test script for merge gating go projects using git
55
56
57
class TestSubcommandError(unittest.TestCase):
58
59
    def test_subcommand_error(self):
60
        proc_error = subprocess.CalledProcessError(1, ["git"])
61
        err = git_gate.SubcommandError("git", "clone", proc_error)
62
        self.assertEqual(str(err), "Subprocess git clone failed with code 1")