Merge lp:~elopio/snappy-tests-job/output_dir into lp:snappy-tests-job

Proposed by Leo Arias
Status: Merged
Approved by: Federico Gimenez
Approved revision: 65
Merged at revision: 63
Proposed branch: lp:~elopio/snappy-tests-job/output_dir
Merge into: lp:snappy-tests-job
Diff against target: 162 lines (+38/-21)
3 files modified
runner/runner.go (+7/-4)
runner/runner_test.go (+28/-15)
snappy-tests-job/main.go (+3/-2)
To merge this branch: bzr merge lp:~elopio/snappy-tests-job/output_dir
Reviewer Review Type Date Requested Status
Federico Gimenez (community) Approve
Review via email: mp+269834@code.launchpad.net

Commit message

Added the output dir as an optional parameter.

Description of the change

To post a comment you must log in.
65. By Leo Arias

Added a test.

Revision history for this message
Federico Gimenez (fgimenez) wrote :

Works great, thanks! :)

review: Approve

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-08-13 15:56:06 +0000
3+++ runner/runner.go 2015-09-02 03:56:45 +0000
4@@ -35,7 +35,7 @@
5
6 // Runner is the test runner type
7 type Runner interface {
8- RunTests(path, cmdTpl, ip, arch string, fromBranch bool) error
9+ RunTests(path, cmdTpl, ip, arch, outputDir 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, arch string, fromBranch bool) (err error) {
18+func (r *BasicRunnerHandler) RunTests(path, cmdTpl, ip, arch, outputDir string, fromBranch bool) (err error) {
19 goPath := determineGoPath(path)
20
21 log.Print("*** Installing godeps ***")
22@@ -68,14 +68,17 @@
23 return
24 }
25
26- return r.runTests(path, goPath, cmdTpl, ip, arch, fromBranch)
27+ return r.runTests(path, goPath, cmdTpl, ip, arch, outputDir, fromBranch)
28 }
29
30-func (r *BasicRunnerHandler) runTests(path, goPath, cmdTpl, ip, arch string, fromBranch bool) (err error) {
31+func (r *BasicRunnerHandler) runTests(path, goPath, cmdTpl, ip, arch, outputDir string, fromBranch bool) (err error) {
32 var args []string
33 if arch != "" {
34 args = append(args, "-arch "+arch)
35 }
36+ if outputDir != "" {
37+ args = append(args, "-output-dir "+outputDir)
38+ }
39 if fromBranch {
40 args = append(args, "-snappy-from-branch")
41 }
42
43=== modified file 'runner/runner_test.go'
44--- runner/runner_test.go 2015-08-13 15:56:06 +0000
45+++ runner/runner_test.go 2015-09-02 03:56:45 +0000
46@@ -42,6 +42,7 @@
47 goPath string
48 cmdTpl string
49 fromBranch bool
50+ outputDir string
51 }
52
53 func Test(t *testing.T) { check.TestingT(t) }
54@@ -64,15 +65,15 @@
55 }
56
57 func (s *runnerSuite) TestRunCallRunTestsCommand(c *check.C) {
58- s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.fromBranch)
59+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.fromBranch)
60
61- runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, false)
62+ runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, s.outputDir, false)
63 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
64 check.Commentf("The command %s was not called", runCmd))
65 }
66
67 func (s *runnerSuite) TestRunCallInstallGodepsCommand(c *check.C) {
68- s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.fromBranch)
69+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.fromBranch)
70
71 installGodepCmd := installGodepCmd(s.path, s.goPath)
72 c.Assert(s.fakeUtil.ExecCalls[installGodepCmd], check.Equals, 1,
73@@ -80,7 +81,7 @@
74 }
75
76 func (s *runnerSuite) TestRunCallInstallDependenciesCommand(c *check.C) {
77- s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.fromBranch)
78+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.fromBranch)
79
80 installDepCmd := installDepCmd(s.path, s.goPath)
81 c.Assert(s.fakeUtil.ExecCalls[installDepCmd], check.Equals, 1,
82@@ -90,34 +91,46 @@
83 func (s *runnerSuite) TestRunReturnError(c *check.C) {
84 s.fakeUtil.FailExec = true
85
86- err := s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.fromBranch)
87+ err := s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.fromBranch)
88
89 c.Assert(err, check.NotNil, check.Commentf("Expected error not returned by Runner.RunTests"))
90 }
91
92 func (s *runnerSuite) TestRunCallRunTestsFromBranchCommand(c *check.C) {
93 fromBranch := true
94- s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, fromBranch)
95+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, fromBranch)
96
97- runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, fromBranch)
98+ runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, s.outputDir, fromBranch)
99 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
100 check.Commentf("The command %s was not called", runCmd))
101 }
102
103 func (s *runnerSuite) TestRunCallRunTestsWithArchCommand(c *check.C) {
104 arch := "testarch"
105- s.subject.RunTests(s.path, s.cmdTpl, s.ip, arch, s.fromBranch)
106-
107- runCmd := runCmd(s.path, s.cmdTpl, s.ip, arch, s.goPath, s.fromBranch)
108- c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
109- check.Commentf("The command %s was not called", runCmd))
110-}
111-
112-func runCmd(path, cmdTpl, ip, arch, goPath string, fromBranch bool) string {
113+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, arch, s.outputDir, s.fromBranch)
114+
115+ runCmd := runCmd(s.path, s.cmdTpl, s.ip, arch, s.goPath, s.outputDir, s.fromBranch)
116+ c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
117+ check.Commentf("The command %s was not called", runCmd))
118+}
119+
120+func (s *runnerSuite) TestRunCallRunTestsWithOutputDirCommand(c *check.C) {
121+ outputDir := "/tmp/test-output-dir"
122+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, outputDir, s.fromBranch)
123+
124+ runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, outputDir, s.fromBranch)
125+ c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
126+ check.Commentf("The command %s was not called", runCmd))
127+}
128+
129+func runCmd(path, cmdTpl, ip, arch, goPath, outputDir string, fromBranch bool) string {
130 var args []string
131 if arch != "" {
132 args = append(args, "-arch "+arch)
133 }
134+ if outputDir != "" {
135+ args = append(args, "-output-dir "+outputDir)
136+ }
137 if fromBranch {
138 args = append(args, "-snappy-from-branch")
139 }
140
141=== modified file 'snappy-tests-job/main.go'
142--- snappy-tests-job/main.go 2015-08-21 04:32:13 +0000
143+++ snappy-tests-job/main.go 2015-09-02 03:56:45 +0000
144@@ -46,7 +46,8 @@
145 "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.")
146 arch = flag.String("arch", "",
147 "Architecture of the test bed. Defaults to use the same architecture as the host.")
148- ip = flag.String("ip", "",
149+ outputDir = flag.String("output-dir", "", "Directory where test artifacts will be stored.")
150+ ip = flag.String("ip", "",
151 "IP of the testbed. If no IP is passed, a cloud instance will be started for the test.")
152 cloudProvider = flag.String("cloud", defaultCloudProvider,
153 "Cloud provider to use, defaults to "+defaultCloudProvider)
154@@ -99,7 +100,7 @@
155 }
156
157 testRunner := runner.NewBasicRunnerHandler(utilHandler)
158- if err := testRunner.RunTests(sourcePath, *commandTpl, ipString, *arch, *useSnappyFromBranch); err != nil {
159+ if err := testRunner.RunTests(sourcePath, *commandTpl, ipString, *arch, *outputDir, *useSnappyFromBranch); err != nil {
160 log.Panic("Error from test runner")
161 }
162 }

Subscribers

People subscribed via source and target branches

to all changes: