Merge lp:~gz/juju-ci-tools/gate_feature_branch_rego into lp:juju-ci-tools

Proposed by Martin Packman on 2015-12-12
Status: Merged
Merged at revision: 1190
Proposed branch: lp:~gz/juju-ci-tools/gate_feature_branch_rego
Merge into: lp:juju-ci-tools
Diff against target: 203 lines (+81/-22)
2 files modified
git_gate.py (+12/-5)
tests/test_git_gate.py (+69/-17)
To merge this branch: bzr merge lp:~gz/juju-ci-tools/gate_feature_branch_rego
Reviewer Review Type Date Requested Status
Juju QA Engineering 2015-12-12 Pending
Review via email: mp+280377@code.launchpad.net

Description of the Change

Second pass at making subproject feature branches sane

Mostly just cleanup to Nate's existing change, adds new argument to explictly turn on the behaviour.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'git_gate.py'
2--- git_gate.py 2015-12-11 22:10:05 +0000
3+++ git_gate.py 2015-12-12 01:33:22 +0000
4@@ -50,9 +50,12 @@
5 go = SubcommandRunner("go", goenv)
6 git = SubcommandRunner("git")
7
8- project_dir = from_feature_dir(args.project)
9- project_ellipsis = project_dir + "/..."
10- directory = os.path.join(gopath, "src", project_dir)
11+ final_project = args.project
12+ if args.feature_branch:
13+ final_project = from_feature_dir(args.project)
14+
15+ project_ellipsis = final_project + "/..."
16+ directory = os.path.join(gopath, "src", final_project)
17
18 if args.tsv_path:
19 print_now("Getting and installing godeps")
20@@ -60,8 +63,7 @@
21 go("install", "launchpad.net/godeps/...")
22 if args.project_url:
23 reldir = os.path.relpath(directory, gopath)
24- print_now("Cloning {} from {} to {}".format(args.project,
25- args.project_url, reldir))
26+ print_now("Cloning {} from {}".format(final_project, args.project_url))
27 git("clone", args.project_url, directory)
28 if args.go_get_all and not (args.project_url and args.merge_url):
29 print_now("Getting {} and dependencies using go".format(args.project))
30@@ -124,6 +126,9 @@
31 "--project-url", help="URL to git repository of package.")
32 project_group.add_argument(
33 "--project-ref", help="Branch name or tag to use as basis.")
34+ project_group.add_argument(
35+ "--feature-branch", action="store_true",
36+ help="Use special handling for pending feature branches.")
37 merge_group = parser.add_argument_group()
38 merge_group.add_argument(
39 "--merge-url", help="URL to git repository to merge before testing.")
40@@ -143,6 +148,8 @@
41 args = parser.parse_args(args)
42 if args.project_url is None and not args.go_get_all:
43 parser.error("Must supply either --project-url or --go-get-all")
44+ if args.feature_branch and args.go_get_all:
45+ parser.error("Cannot use --feature-branch and --go-get-all together")
46 return args
47
48
49
50=== modified file 'tests/test_git_gate.py'
51--- tests/test_git_gate.py 2015-12-11 22:10:05 +0000
52+++ tests/test_git_gate.py 2015-12-12 01:33:22 +0000
53@@ -1,12 +1,12 @@
54 import argparse
55 import mock
56 import subprocess
57-import unittest
58
59 import git_gate
60-
61-
62-class TestParseArgs(unittest.TestCase):
63+import tests
64+
65+
66+class TestParseArgs(tests.TestCase):
67
68 def test_project_and_url(self):
69 args = git_gate.parse_args(
70@@ -77,8 +77,25 @@
71 self.assertEqual(args.go_get_all, False)
72 self.assertEqual(args.tsv_path, "/a/file.tsv")
73
74-
75-class TestSubcommandError(unittest.TestCase):
76+ def test_error_on_project_url_missing(self):
77+ with tests.parse_error(self) as stderr:
78+ git_gate.parse_args(["--project", "git.testing/project"])
79+ self.assertIn(
80+ "Must supply either --project-url or --go-get-all",
81+ stderr.getvalue())
82+
83+ def test_error_go_get_feature_branch(self):
84+ with tests.parse_error(self) as stderr:
85+ git_gate.parse_args(
86+ ["--project", "git.testing/project",
87+ "--project-url", "https://git.testing/project",
88+ "--go-get-all", "--feature-branch"])
89+ self.assertIn(
90+ "Cannot use --feature-branch and --go-get-all together",
91+ stderr.getvalue())
92+
93+
94+class TestSubcommandError(tests.TestCase):
95
96 def test_subcommand_error(self):
97 proc_error = subprocess.CalledProcessError(1, ["git"])
98@@ -86,7 +103,7 @@
99 self.assertEqual(str(err), "Subprocess git clone failed with code 1")
100
101
102-class TestGoTest(unittest.TestCase):
103+class TestGoTest(tests.TestCase):
104 """
105 Tests for go_test function.
106
107@@ -99,6 +116,7 @@
108 maxDiff = None
109
110 def setUp(self):
111+ super(TestGoTest, self).setUp()
112 # Patch out and record actions run as part of go_test()
113 self.actions = []
114 self.patch_action("git_gate.print_now", lambda s: ("print", s))
115@@ -127,8 +145,8 @@
116 patcher.start()
117 self.addCleanup(patcher.stop)
118
119- args = frozenset("project project_url project_ref merge_url merge_ref"
120- " go_get_all dependencies tsv_path".split())
121+ args = frozenset("project project_url project_ref feature_branch merge_url"
122+ " merge_ref go_get_all dependencies tsv_path".split())
123
124 @classmethod
125 def make_args(cls, project, **kwargs):
126@@ -176,7 +194,7 @@
127 git_gate.go_test(args, "/tmp/fake")
128 self.assertEqual(self.actions, [
129 ('print', 'Cloning git.testing/project from'
130- ' https://git.testing/project to src/git.testing/project'),
131+ ' https://git.testing/project'),
132 ('git', 'clone', 'https://git.testing/project',
133 '/tmp/fake/src/git.testing/project'),
134 ('chdir', '/tmp/fake/src/git.testing/project'),
135@@ -198,7 +216,7 @@
136 git_gate.go_test(args, "/tmp/fake")
137 self.assertEqual(self.actions, [
138 ('print', 'Cloning git.testing/project from'
139- ' https://git.testing/project to src/git.testing/project'),
140+ ' https://git.testing/project'),
141 ('git', 'clone', 'https://git.testing/project',
142 '/tmp/fake/src/git.testing/project'),
143 ('chdir', '/tmp/fake/src/git.testing/project'),
144@@ -220,7 +238,7 @@
145 ('go', 'get', '-v', '-d', 'launchpad.net/godeps/...'),
146 ('go', 'install', 'launchpad.net/godeps/...'),
147 ('print', 'Cloning git.testing/project from'
148- ' https://git.testing/project to src/git.testing/project'),
149+ ' https://git.testing/project'),
150 ('git', 'clone', 'https://git.testing/project',
151 '/tmp/fake/src/git.testing/project'),
152 ('chdir', '/tmp/fake/src/git.testing/project'),
153@@ -232,11 +250,45 @@
154 ('go', 'test', 'git.testing/project/...')
155 ])
156
157-
158-class TestFromFeatureDir(unittest.TestCase):
159- """
160- Tests for from_feature_dir function.
161- """
162+ def test_feature_branch(self):
163+ args = self.make_args("vgo.testing/project.v2.feature",
164+ project_url="https://git.testing/project",
165+ project_ref="v2.feature",
166+ feature_branch=True, dependencies=[])
167+ git_gate.go_test(args, "/tmp/fake")
168+ self.assertEqual(self.actions, [
169+ ('print', 'Cloning vgo.testing/project.v2 from'
170+ ' https://git.testing/project'),
171+ ('git', 'clone', 'https://git.testing/project',
172+ '/tmp/fake/src/vgo.testing/project.v2'),
173+ ('chdir', '/tmp/fake/src/vgo.testing/project.v2'),
174+ ('print', 'Switching repository to v2.feature'),
175+ ('git', 'checkout', 'v2.feature'),
176+ ('go', 'build', 'vgo.testing/project.v2/...'),
177+ ('go', 'test', 'vgo.testing/project.v2/...')
178+ ])
179+
180+ def test_no_magic_dots(self):
181+ args = self.make_args("vgo.testing/project.dot.love",
182+ project_url="https://git.testing/project",
183+ project_ref="dot.love", dependencies=[])
184+ git_gate.go_test(args, "/tmp/fake")
185+ self.assertEqual(self.actions, [
186+ ('print', 'Cloning vgo.testing/project.dot.love from'
187+ ' https://git.testing/project'),
188+ ('git', 'clone', 'https://git.testing/project',
189+ '/tmp/fake/src/vgo.testing/project.dot.love'),
190+ ('chdir', '/tmp/fake/src/vgo.testing/project.dot.love'),
191+ ('print', 'Switching repository to dot.love'),
192+ ('git', 'checkout', 'dot.love'),
193+ ('go', 'build', 'vgo.testing/project.dot.love/...'),
194+ ('go', 'test', 'vgo.testing/project.dot.love/...')
195+ ])
196+
197+
198+class TestFromFeatureDir(tests.TestCase):
199+ """Tests for from_feature_dir function."""
200+
201 def test_boring(self):
202 directory = git_gate.from_feature_dir("github.com/juju/juju")
203 self.assertEqual(directory, "github.com/juju/juju")

Subscribers

People subscribed via source and target branches