Merge lp:~fgimenez/snappy-tests-job/build-from-branch-flag into lp:~fgimenez/snappy-tests-job/trunk

Proposed by Federico Gimenez
Status: Merged
Merged at revision: 54
Proposed branch: lp:~fgimenez/snappy-tests-job/build-from-branch-flag
Merge into: lp:~fgimenez/snappy-tests-job/trunk
Diff against target: 191 lines (+47/-27)
3 files modified
runner/runner.go (+10/-5)
runner/runner_test.go (+29/-14)
snappy-tests-job/main.go (+8/-8)
To merge this branch: bzr merge lp:~fgimenez/snappy-tests-job/build-from-branch-flag
Reviewer Review Type Date Requested Status
Federico Gimenez Pending
Review via email: mp+267312@code.launchpad.net

Commit message

Build from branch flag

Description of the change

Build from branch flag

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 'runner/runner.go'
2--- runner/runner.go 2015-07-24 16:37:47 +0000
3+++ runner/runner.go 2015-08-07 09:30:24 +0000
4@@ -35,7 +35,7 @@
5
6 // Runner is the test runner type
7 type Runner interface {
8- RunTests(path, cmdTpl, ip string) error
9+ RunTests(path, cmdTpl, ip string, fromBranch bool) error
10 }
11
12 // BasicRunnerHandler is a basic type implementing Runner
13@@ -51,7 +51,7 @@
14 // RunTests executes the given command in the given path. The command is formed
15 // by interpolating the ip in the cmdTpl; before it installs godeps and the
16 // required dependencies
17-func (r *BasicRunnerHandler) RunTests(path, cmdTpl, ip string) (err error) {
18+func (r *BasicRunnerHandler) RunTests(path, cmdTpl, ip string, fromBranch bool) (err error) {
19 goPath := determineGoPath(path)
20
21 log.Print("*** Installing godeps ***")
22@@ -68,11 +68,16 @@
23 return
24 }
25
26- return r.runTests(path, goPath, cmdTpl, ip)
27+ return r.runTests(path, goPath, cmdTpl, ip, fromBranch)
28 }
29
30-func (r *BasicRunnerHandler) runTests(path, goPath, cmdTpl, ip string) (err error) {
31- cmd := fmt.Sprintf(cmdTpl, ip)
32+func (r *BasicRunnerHandler) runTests(path, goPath, cmdTpl, ip string, fromBranch bool) (err error) {
33+ var snappyFromBranch string
34+ if fromBranch {
35+ snappyFromBranch = "-snappy-from-branch"
36+ }
37+
38+ cmd := fmt.Sprintf(cmdTpl, ip, snappyFromBranch)
39
40 log.Printf("*** Running tests with command %s in %s ***", cmd, path)
41
42
43=== modified file 'runner/runner_test.go'
44--- runner/runner_test.go 2015-07-24 16:37:47 +0000
45+++ runner/runner_test.go 2015-08-07 09:30:24 +0000
46@@ -34,12 +34,13 @@
47 var _ = check.Suite(&runnerSuite{})
48
49 type runnerSuite struct {
50- fakeUtil *testhelpers.FakeUtils
51- subject Runner
52- ip string
53- path string
54- goPath string
55- cmdTpl string
56+ fakeUtil *testhelpers.FakeUtils
57+ subject Runner
58+ ip string
59+ path string
60+ goPath string
61+ cmdTpl string
62+ fromBranch bool
63 }
64
65 func Test(t *testing.T) { check.TestingT(t) }
66@@ -52,7 +53,7 @@
67 s.ip = "2.2.2.2"
68 s.goPath = "/some/path/with/a/pakage/name/in/it"
69 s.path = filepath.Join(s.goPath, goPkg)
70- s.cmdTpl = "go run %s"
71+ s.cmdTpl = "go run %s %s"
72 }
73
74 func (s *runnerSuite) TestNewRunner(c *check.C) {
75@@ -62,15 +63,15 @@
76 }
77
78 func (s *runnerSuite) TestRunCallRunTestsCommand(c *check.C) {
79- s.subject.RunTests(s.path, s.cmdTpl, s.ip)
80+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.fromBranch)
81
82- runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.goPath)
83+ runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.goPath, false)
84 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
85 check.Commentf("The command %s was not called", runCmd))
86 }
87
88 func (s *runnerSuite) TestRunCallInstallGodepsCommand(c *check.C) {
89- s.subject.RunTests(s.path, s.cmdTpl, s.ip)
90+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.fromBranch)
91
92 installGodepCmd := installGodepCmd(s.path, s.goPath)
93 c.Assert(s.fakeUtil.ExecCalls[installGodepCmd], check.Equals, 1,
94@@ -78,7 +79,7 @@
95 }
96
97 func (s *runnerSuite) TestRunCallInstallDependenciesCommand(c *check.C) {
98- s.subject.RunTests(s.path, s.cmdTpl, s.ip)
99+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.fromBranch)
100
101 installDepCmd := installDepCmd(s.path, s.goPath)
102 c.Assert(s.fakeUtil.ExecCalls[installDepCmd], check.Equals, 1,
103@@ -88,13 +89,27 @@
104 func (s *runnerSuite) TestRunReturnError(c *check.C) {
105 s.fakeUtil.FailExec = true
106
107- err := s.subject.RunTests(s.path, s.cmdTpl, s.ip)
108+ err := s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.fromBranch)
109
110 c.Assert(err, check.NotNil, check.Commentf("Expected error not returned by Runner.RunTests"))
111 }
112
113-func runCmd(path, cmdTpl, ip, goPath string) string {
114- cmd := fmt.Sprintf(cmdTpl, ip)
115+func (s *runnerSuite) TestRunCallRunTestsFromBranchCommand(c *check.C) {
116+ fromBranch := true
117+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, fromBranch)
118+
119+ runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.goPath, fromBranch)
120+ c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
121+ check.Commentf("The command %s was not called", runCmd))
122+}
123+
124+func runCmd(path, cmdTpl, ip, goPath string, fromBranch bool) string {
125+ var snappyFromBranch string
126+ if fromBranch {
127+ snappyFromBranch = "-snappy-from-branch"
128+ }
129+
130+ cmd := fmt.Sprintf(cmdTpl, ip, snappyFromBranch)
131 params := utils.NewExecCommandParams(path, strings.Fields(cmd), true)
132 params.AppendEnv(fmt.Sprintf("GOPATH=%s", goPath))
133 return params.String()
134
135=== modified file 'snappy-tests-job/main.go'
136--- snappy-tests-job/main.go 2015-08-03 15:01:03 +0000
137+++ snappy-tests-job/main.go 2015-08-07 09:30:24 +0000
138@@ -33,7 +33,7 @@
139
140 const (
141 defaultCloudProvider = "canonistack"
142- defaultCommandTpl = "go run ./_integration-tests/main.go -ip %s"
143+ defaultCommandTpl = "go run ./_integration-tests/main.go -ip %s %s"
144 defaultSrc = "lp:snappy"
145 defaultRelease = "15.04"
146 defaultChannel = "edge"
147@@ -41,6 +41,8 @@
148
149 func main() {
150 var (
151+ useSnappyFromBranch = flag.Bool("snappy-from-branch", false,
152+ "If this flag is used, snappy will be compiled from this branch, copied to the testbed and used for the tests. Otherwise, the snappy installed with the image will be used.")
153 cloudProvider = flag.String("cloud", defaultCloudProvider,
154 "Cloud provider to use, defaults to "+defaultCloudProvider)
155 release = flag.String("release", defaultRelease,
156@@ -56,13 +58,12 @@
157
158 flag.Parse()
159
160- // TODO: we need a waitGroup here to make thinks more efficiently
161+ // TODO: we need a waitGroup here to run things more efficiently
162 utilHandler := utils.NewBasicHandler()
163 sourceHandler := source.NewBzrHandler(utilHandler)
164 sourcePath, err := sourceHandler.Run(*src)
165 if err != nil {
166- log.Printf("Error getting %s into %s", *src, sourcePath)
167- panic("")
168+ log.Panicf("Error getting %s into %s", *src, sourcePath)
169 }
170 defer os.RemoveAll(sourcePath)
171
172@@ -71,8 +72,7 @@
173 defer cloudClient.KillInstance()
174
175 if err != nil {
176- log.Printf("Error creating image for release %s and channel %s, %s", *release, *channel, err)
177- panic("")
178+ log.Panicf("Error creating image for release %s and channel %s, %s", *release, *channel, err)
179 }
180
181 // give time for the instance to finish booting
182@@ -81,7 +81,7 @@
183 time.Sleep(3 * time.Minute)
184
185 testRunner := runner.NewBasicRunnerHandler(utilHandler)
186- if err := testRunner.RunTests(sourcePath, *commandTpl, ip); err != nil {
187- panic("")
188+ if err := testRunner.RunTests(sourcePath, *commandTpl, ip, *useSnappyFromBranch); err != nil {
189+ log.Panic("Error from test runner")
190 }
191 }

Subscribers

People subscribed via source and target branches

to all changes: