Merge lp:~fgimenez/snappy-tests-job/test-build-tags into lp:snappy-tests-job

Proposed by Federico Gimenez
Status: Merged
Approved by: Federico Gimenez
Approved revision: 67
Merged at revision: 67
Proposed branch: lp:~fgimenez/snappy-tests-job/test-build-tags
Merge into: lp:snappy-tests-job
Diff against target: 203 lines (+40/-42)
3 files modified
runner/runner.go (+7/-4)
runner/runner_test.go (+31/-37)
snappy-tests-job/main.go (+2/-1)
To merge this branch: bzr merge lp:~fgimenez/snappy-tests-job/test-build-tags
Reviewer Review Type Date Requested Status
Leo Arias (community) Approve
Review via email: mp+278446@code.launchpad.net

Commit message

Added testBuildTags flag

Description of the change

Added testBuildTags flag

Also changed the test a bit, it had an exact copy of a production code function, those test passing weren't giving to much value.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

great change in the test, thanks :)
This needs to wait for the addition of the flag in the other project.

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

Thanks Leo! It can be landed now, the flag will be accessible and we can use it as needed

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-11-04 16:18:48 +0000
3+++ runner/runner.go 2015-11-24 12:29:14 +0000
4@@ -35,7 +35,7 @@
5
6 // Runner is the test runner type
7 type Runner interface {
8- RunTests(path, cmdTpl, ip, arch, outputDir string, fromBranch bool) error
9+ RunTests(path, cmdTpl, ip, arch, outputDir, testBuildTags 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, outputDir string, fromBranch bool) (err error) {
18+func (r *BasicRunnerHandler) RunTests(path, cmdTpl, ip, arch, outputDir, testBuildTags string, fromBranch bool) (err error) {
19 goPath := determineGoPath(path)
20
21 log.Print("*** Installing godeps ***")
22@@ -68,10 +68,10 @@
23 return
24 }
25
26- return r.runTests(path, goPath, cmdTpl, ip, arch, outputDir, fromBranch)
27+ return r.runTests(path, goPath, cmdTpl, ip, arch, outputDir, testBuildTags, fromBranch)
28 }
29
30-func (r *BasicRunnerHandler) runTests(path, goPath, cmdTpl, ip, arch, outputDir string, fromBranch bool) (err error) {
31+func (r *BasicRunnerHandler) runTests(path, goPath, cmdTpl, ip, arch, outputDir, testBuildTags string, fromBranch bool) (err error) {
32 var args []string
33 if arch != "" {
34 args = append(args, "-arch "+arch)
35@@ -82,6 +82,9 @@
36 if fromBranch {
37 args = append(args, "-snappy-from-branch")
38 }
39+ if testBuildTags != "" {
40+ args = append(args, "-test-build-tags "+testBuildTags)
41+ }
42
43 cmd := fmt.Sprintf(cmdTpl, ip, strings.Join(args, " "))
44
45
46=== modified file 'runner/runner_test.go'
47--- runner/runner_test.go 2015-09-02 03:49:52 +0000
48+++ runner/runner_test.go 2015-11-24 12:29:14 +0000
49@@ -25,7 +25,7 @@
50 "strings"
51 "testing"
52
53- check "gopkg.in/check.v1"
54+ "gopkg.in/check.v1"
55
56 "launchpad.net/snappy-tests-job/testhelpers"
57 "launchpad.net/snappy-tests-job/utils"
58@@ -34,15 +34,16 @@
59 var _ = check.Suite(&runnerSuite{})
60
61 type runnerSuite struct {
62- fakeUtil *testhelpers.FakeUtils
63- subject Runner
64- ip string
65- arch string
66- path string
67- goPath string
68- cmdTpl string
69- fromBranch bool
70- outputDir string
71+ fakeUtil *testhelpers.FakeUtils
72+ subject Runner
73+ ip string
74+ arch string
75+ path string
76+ goPath string
77+ cmdTpl string
78+ fromBranch bool
79+ outputDir string
80+ testBuildTags string
81 }
82
83 func Test(t *testing.T) { check.TestingT(t) }
84@@ -65,15 +66,16 @@
85 }
86
87 func (s *runnerSuite) TestRunCallRunTestsCommand(c *check.C) {
88- s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.fromBranch)
89+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.testBuildTags, s.fromBranch)
90
91- runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, s.outputDir, false)
92+ runCmd := "go run " + s.ip + " # executed in " + s.path + " with pipe and env GOPATH=" + s.goPath
93+ fmt.Println(runCmd)
94 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
95 check.Commentf("The command %s was not called", runCmd))
96 }
97
98 func (s *runnerSuite) TestRunCallInstallGodepsCommand(c *check.C) {
99- s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.fromBranch)
100+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.testBuildTags, s.fromBranch)
101
102 installGodepCmd := installGodepCmd(s.path, s.goPath)
103 c.Assert(s.fakeUtil.ExecCalls[installGodepCmd], check.Equals, 1,
104@@ -81,7 +83,7 @@
105 }
106
107 func (s *runnerSuite) TestRunCallInstallDependenciesCommand(c *check.C) {
108- s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.fromBranch)
109+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.testBuildTags, s.fromBranch)
110
111 installDepCmd := installDepCmd(s.path, s.goPath)
112 c.Assert(s.fakeUtil.ExecCalls[installDepCmd], check.Equals, 1,
113@@ -91,54 +93,46 @@
114 func (s *runnerSuite) TestRunReturnError(c *check.C) {
115 s.fakeUtil.FailExec = true
116
117- err := s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.fromBranch)
118+ err := s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.testBuildTags, s.fromBranch)
119
120 c.Assert(err, check.NotNil, check.Commentf("Expected error not returned by Runner.RunTests"))
121 }
122
123 func (s *runnerSuite) TestRunCallRunTestsFromBranchCommand(c *check.C) {
124 fromBranch := true
125- s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, fromBranch)
126-
127- runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, s.outputDir, fromBranch)
128+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, s.testBuildTags, fromBranch)
129+
130+ runCmd := "go run " + s.ip + " -snappy-from-branch # executed in " + s.path + " with pipe and env GOPATH=" + s.goPath
131+
132 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
133 check.Commentf("The command %s was not called", runCmd))
134 }
135
136 func (s *runnerSuite) TestRunCallRunTestsWithArchCommand(c *check.C) {
137 arch := "testarch"
138- s.subject.RunTests(s.path, s.cmdTpl, s.ip, arch, s.outputDir, s.fromBranch)
139+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, arch, s.outputDir, s.testBuildTags, s.fromBranch)
140
141- runCmd := runCmd(s.path, s.cmdTpl, s.ip, arch, s.goPath, s.outputDir, s.fromBranch)
142+ runCmd := "go run " + s.ip + " -arch " + arch + " # executed in " + s.path + " with pipe and env GOPATH=" + s.goPath
143 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
144 check.Commentf("The command %s was not called", runCmd))
145 }
146
147 func (s *runnerSuite) TestRunCallRunTestsWithOutputDirCommand(c *check.C) {
148 outputDir := "/tmp/test-output-dir"
149- s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, outputDir, s.fromBranch)
150+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, outputDir, s.testBuildTags, s.fromBranch)
151
152- runCmd := runCmd(s.path, s.cmdTpl, s.ip, s.arch, s.goPath, outputDir, s.fromBranch)
153+ runCmd := "go run " + s.ip + " -output-dir " + outputDir + " # executed in " + s.path + " with pipe and env GOPATH=" + s.goPath
154 c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
155 check.Commentf("The command %s was not called", runCmd))
156 }
157
158-func runCmd(path, cmdTpl, ip, arch, goPath, outputDir string, fromBranch bool) string {
159- var args []string
160- if arch != "" {
161- args = append(args, "-arch "+arch)
162- }
163- if outputDir != "" {
164- args = append(args, "-output-dir "+outputDir)
165- }
166- if fromBranch {
167- args = append(args, "-snappy-from-branch")
168- }
169+func (s *runnerSuite) TestRunCallRunTestsWithTestBuildTags(c *check.C) {
170+ testBuildTags := "mytestbuildtags"
171+ s.subject.RunTests(s.path, s.cmdTpl, s.ip, s.arch, s.outputDir, testBuildTags, s.fromBranch)
172
173- cmd := fmt.Sprintf(cmdTpl, ip, strings.Join(args, " "))
174- params := utils.NewExecCommandParams(path, strings.Fields(cmd), true)
175- params.AppendEnv(fmt.Sprintf("GOPATH=%s", goPath))
176- return params.String()
177+ runCmd := "go run " + s.ip + " -test-build-tags " + testBuildTags + " # executed in " + s.path + " with pipe and env GOPATH=" + s.goPath
178+ c.Assert(s.fakeUtil.ExecCalls[runCmd], check.Equals, 1,
179+ check.Commentf("The command %s was not called", runCmd))
180 }
181
182 func installGodepCmd(path, goPath string) string {
183
184=== modified file 'snappy-tests-job/main.go'
185--- snappy-tests-job/main.go 2015-11-05 09:39:17 +0000
186+++ snappy-tests-job/main.go 2015-11-24 12:29:14 +0000
187@@ -61,6 +61,7 @@
188 "Repository from which to get the source code, defaults to "+defaultRepo)
189 src = flag.String("src", defaultBranch,
190 "Branch from which to get the source code, defaults to "+defaultBranch)
191+ testBuildTags = flag.String("test-build-tags", "", "Build constraints to be be passed to the test build command")
192
193 commandTpl = flag.String("command", defaultCommandTpl,
194 "Command template, should include the testBed ip as %s, defaults to '"+defaultCommandTpl+"'")
195@@ -94,7 +95,7 @@
196 }
197
198 testRunner := runner.NewBasicRunnerHandler(utilHandler)
199- if err := testRunner.RunTests(sourcePath, *commandTpl, ipString, *arch, *outputDir, *useSnappyFromBranch); err != nil {
200+ if err := testRunner.RunTests(sourcePath, *commandTpl, ipString, *arch, *outputDir, *testBuildTags, *useSnappyFromBranch); err != nil {
201 log.Panic("Error from test runner")
202 }
203 }

Subscribers

People subscribed via source and target branches