Merge lp:~elopio/snappy-tests-job/arch into lp:~fgimenez/snappy-tests-job/trunk

Proposed by Leo Arias
Status: Merged
Merged at revision: 58
Proposed branch: lp:~elopio/snappy-tests-job/arch
Merge into: lp:~fgimenez/snappy-tests-job/trunk
Diff against target: 160 lines (+42/-24)
3 files modified
runner/runner.go (+10/-7)
runner/runner_test.go (+29/-16)
snappy-tests-job/main.go (+3/-1)
To merge this branch: bzr merge lp:~elopio/snappy-tests-job/arch
Reviewer Review Type Date Requested Status
Federico Gimenez Approve
Review via email: mp+267969@code.launchpad.net

Commit message

Added the arch flag.

Description of the change

I don't link this runner test because we are basically writing the same command building method. I would prefer to just hardcode the expected cmd string in each test. But I'll leave that to the future :)

To post a comment you must log in.
Revision history for this message
Federico Gimenez (fgimenez) wrote :

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

Subscribers

People subscribed via source and target branches

to all changes: