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
=== modified file 'runner/runner.go'
--- runner/runner.go 2015-08-13 15:56:06 +0000
+++ runner/runner.go 2015-09-02 03:56:45 +0000
@@ -35,7 +35,7 @@
3535
36// Runner is the test runner type36// Runner is the test runner type
37type Runner interface {37type Runner interface {
38 RunTests(path, cmdTpl, ip, arch string, fromBranch bool) error38 RunTests(path, cmdTpl, ip, arch, outputDir string, fromBranch bool) error
39}39}
4040
41// BasicRunnerHandler is a basic type implementing Runner41// BasicRunnerHandler is a basic type implementing Runner
@@ -51,7 +51,7 @@
51// RunTests executes the given command in the given path. The command is formed51// RunTests executes the given command in the given path. The command is formed
52// by interpolating the ip in the cmdTpl; before it installs godeps and the52// by interpolating the ip in the cmdTpl; before it installs godeps and the
53// required dependencies53// required dependencies
54func (r *BasicRunnerHandler) RunTests(path, cmdTpl, ip, arch string, fromBranch bool) (err error) {54func (r *BasicRunnerHandler) RunTests(path, cmdTpl, ip, arch, outputDir string, fromBranch bool) (err error) {
55 goPath := determineGoPath(path)55 goPath := determineGoPath(path)
5656
57 log.Print("*** Installing godeps ***")57 log.Print("*** Installing godeps ***")
@@ -68,14 +68,17 @@
68 return68 return
69 }69 }
7070
71 return r.runTests(path, goPath, cmdTpl, ip, arch, fromBranch)71 return r.runTests(path, goPath, cmdTpl, ip, arch, outputDir, fromBranch)
72}72}
7373
74func (r *BasicRunnerHandler) runTests(path, goPath, cmdTpl, ip, arch string, fromBranch bool) (err error) {74func (r *BasicRunnerHandler) runTests(path, goPath, cmdTpl, ip, arch, outputDir string, fromBranch bool) (err error) {
75 var args []string75 var args []string
76 if arch != "" {76 if arch != "" {
77 args = append(args, "-arch "+arch)77 args = append(args, "-arch "+arch)
78 }78 }
79 if outputDir != "" {
80 args = append(args, "-output-dir "+outputDir)
81 }
79 if fromBranch {82 if fromBranch {
80 args = append(args, "-snappy-from-branch")83 args = append(args, "-snappy-from-branch")
81 }84 }
8285
=== modified file 'runner/runner_test.go'
--- runner/runner_test.go 2015-08-13 15:56:06 +0000
+++ runner/runner_test.go 2015-09-02 03:56:45 +0000
@@ -42,6 +42,7 @@
42 goPath string42 goPath string
43 cmdTpl string43 cmdTpl string
44 fromBranch bool44 fromBranch bool
45 outputDir string
45}46}
4647
47func Test(t *testing.T) { check.TestingT(t) }48func Test(t *testing.T) { check.TestingT(t) }
@@ -64,15 +65,15 @@
64}65}
6566
66func (s *runnerSuite) TestRunCallRunTestsCommand(c *check.C) {67func (s *runnerSuite) TestRunCallRunTestsCommand(c *check.C) {
67 s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.fromBranch)68 s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.fromBranch)
6869
69 runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, false)70 runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, s.outputDir, false)
70 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,71 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
71 check.Commentf("The command %s was not called", runCmd))72 check.Commentf("The command %s was not called", runCmd))
72}73}
7374
74func (s *runnerSuite) TestRunCallInstallGodepsCommand(c *check.C) {75func (s *runnerSuite) TestRunCallInstallGodepsCommand(c *check.C) {
75 s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.fromBranch)76 s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.fromBranch)
7677
77 installGodepCmd := installGodepCmd(s.path, s.goPath)78 installGodepCmd := installGodepCmd(s.path, s.goPath)
78 c.Assert(s.fakeUtil.ExecCalls[installGodepCmd], check.Equals, 1,79 c.Assert(s.fakeUtil.ExecCalls[installGodepCmd], check.Equals, 1,
@@ -80,7 +81,7 @@
80}81}
8182
82func (s *runnerSuite) TestRunCallInstallDependenciesCommand(c *check.C) {83func (s *runnerSuite) TestRunCallInstallDependenciesCommand(c *check.C) {
83 s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.fromBranch)84 s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.fromBranch)
8485
85 installDepCmd := installDepCmd(s.path, s.goPath)86 installDepCmd := installDepCmd(s.path, s.goPath)
86 c.Assert(s.fakeUtil.ExecCalls[installDepCmd], check.Equals, 1,87 c.Assert(s.fakeUtil.ExecCalls[installDepCmd], check.Equals, 1,
@@ -90,34 +91,46 @@
90func (s *runnerSuite) TestRunReturnError(c *check.C) {91func (s *runnerSuite) TestRunReturnError(c *check.C) {
91 s.fakeUtil.FailExec = true92 s.fakeUtil.FailExec = true
9293
93 err := s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.fromBranch)94 err := s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.fromBranch)
9495
95 c.Assert(err, check.NotNil, check.Commentf("Expected error not returned by Runner.RunTests"))96 c.Assert(err, check.NotNil, check.Commentf("Expected error not returned by Runner.RunTests"))
96}97}
9798
98func (s *runnerSuite) TestRunCallRunTestsFromBranchCommand(c *check.C) {99func (s *runnerSuite) TestRunCallRunTestsFromBranchCommand(c *check.C) {
99 fromBranch := true100 fromBranch := true
100 s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, fromBranch)101 s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, fromBranch)
101102
102 runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, fromBranch)103 runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, s.outputDir, fromBranch)
103 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,104 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
104 check.Commentf("The command %s was not called", runCmd))105 check.Commentf("The command %s was not called", runCmd))
105}106}
106107
107func (s *runnerSuite) TestRunCallRunTestsWithArchCommand(c *check.C) {108func (s *runnerSuite) TestRunCallRunTestsWithArchCommand(c *check.C) {
108 arch := "testarch"109 arch := "testarch"
109 s.subject.RunTests(s.path, s.cmdTpl, s.ip, arch, s.fromBranch)110 s.subject.RunTests(s.path, s.cmdTpl, s.ip, arch, s.outputDir, s.fromBranch)
110111
111 runCmd := runCmd(s.path, s.cmdTpl, s.ip, arch, s.goPath, s.fromBranch)112 runCmd := runCmd(s.path, s.cmdTpl, s.ip, arch, s.goPath, s.outputDir, s.fromBranch)
112 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,113 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
113 check.Commentf("The command %s was not called", runCmd))114 check.Commentf("The command %s was not called", runCmd))
114}115}
115116
116func runCmd(path, cmdTpl, ip, arch, goPath string, fromBranch bool) string {117func (s *runnerSuite) TestRunCallRunTestsWithOutputDirCommand(c *check.C) {
118 outputDir := "/tmp/test-output-dir"
119 s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, outputDir, s.fromBranch)
120
121 runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, outputDir, s.fromBranch)
122 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
123 check.Commentf("The command %s was not called", runCmd))
124}
125
126func runCmd(path, cmdTpl, ip, arch, goPath, outputDir string, fromBranch bool) string {
117 var args []string127 var args []string
118 if arch != "" {128 if arch != "" {
119 args = append(args, "-arch "+arch)129 args = append(args, "-arch "+arch)
120 }130 }
131 if outputDir != "" {
132 args = append(args, "-output-dir "+outputDir)
133 }
121 if fromBranch {134 if fromBranch {
122 args = append(args, "-snappy-from-branch")135 args = append(args, "-snappy-from-branch")
123 }136 }
124137
=== modified file 'snappy-tests-job/main.go'
--- snappy-tests-job/main.go 2015-08-21 04:32:13 +0000
+++ snappy-tests-job/main.go 2015-09-02 03:56:45 +0000
@@ -46,7 +46,8 @@
46 "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.")46 "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.")
47 arch = flag.String("arch", "",47 arch = flag.String("arch", "",
48 "Architecture of the test bed. Defaults to use the same architecture as the host.")48 "Architecture of the test bed. Defaults to use the same architecture as the host.")
49 ip = flag.String("ip", "",49 outputDir = flag.String("output-dir", "", "Directory where test artifacts will be stored.")
50 ip = flag.String("ip", "",
50 "IP of the testbed. If no IP is passed, a cloud instance will be started for the test.")51 "IP of the testbed. If no IP is passed, a cloud instance will be started for the test.")
51 cloudProvider = flag.String("cloud", defaultCloudProvider,52 cloudProvider = flag.String("cloud", defaultCloudProvider,
52 "Cloud provider to use, defaults to "+defaultCloudProvider)53 "Cloud provider to use, defaults to "+defaultCloudProvider)
@@ -99,7 +100,7 @@
99 }100 }
100101
101 testRunner := runner.NewBasicRunnerHandler(utilHandler)102 testRunner := runner.NewBasicRunnerHandler(utilHandler)
102 if err := testRunner.RunTests(sourcePath, *commandTpl, ipString, *arch, *useSnappyFromBranch); err != nil {103 if err := testRunner.RunTests(sourcePath, *commandTpl, ipString, *arch, *outputDir, *useSnappyFromBranch); err != nil {
103 log.Panic("Error from test runner")104 log.Panic("Error from test runner")
104 }105 }
105}106}

Subscribers

People subscribed via source and target branches

to all changes: