Merge lp:~elopio/snappy/extract_integration_build into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 615
Merged at revision: 614
Proposed branch: lp:~elopio/snappy/extract_integration_build
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 186 lines (+85/-51)
2 files modified
_integration-tests/helpers/build/build.go (+76/-0)
_integration-tests/main.go (+9/-51)
To merge this branch: bzr merge lp:~elopio/snappy/extract_integration_build
Reviewer Review Type Date Requested Status
Federico Gimenez (community) Approve
Review via email: mp+266019@code.launchpad.net

Commit message

Moved the integration build helpers to a package.

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

I don't like the name "Assets", but I can't think of a better name. "Binaries" it's almost the same.
Maybe we can rename it to build.SnappyAndIntegraionTests. Or maybe we just split it and call it twice:

build.Snappy()
build.IntegrationTests()

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

I'm fine with Assets, mostly because of the common creation of the target directory, +1 for me.

As a nit maybe we could include the goCall method in the build package until it is used elsewhere.

Cheers!

review: Approve
614. By Leo Arias

Moved the goCall back to build.go.

615. By Leo Arias

Fixed goCall.

Revision history for this message
Leo Arias (elopio) wrote :

> As a nit maybe we could include the goCall method in the build package until
> it is used elsewhere.

Done!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory '_integration-tests/helpers/build'
2=== added file '_integration-tests/helpers/build/build.go'
3--- _integration-tests/helpers/build/build.go 1970-01-01 00:00:00 +0000
4+++ _integration-tests/helpers/build/build.go 2015-07-28 12:05:32 +0000
5@@ -0,0 +1,76 @@
6+// -*- Mode: Go; indent-tabs-mode: t -*-
7+
8+/*
9+ * Copyright (C) 2015 Canonical Ltd
10+ *
11+ * This program is free software: you can redistribute it and/or modify
12+ * it under the terms of the GNU General Public License version 3 as
13+ * published by the Free Software Foundation.
14+ *
15+ * This program is distributed in the hope that it will be useful,
16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+ * GNU General Public License for more details.
19+ *
20+ * You should have received a copy of the GNU General Public License
21+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
22+ *
23+ */
24+
25+package build
26+
27+import (
28+ "fmt"
29+ "os"
30+
31+ "launchpad.net/snappy/_integration-tests/helpers/utils"
32+)
33+
34+const (
35+ // IntegrationTestName is the name of the test binary.
36+ IntegrationTestName = "integration.test"
37+ defaultGoArm = "7"
38+ testsBinDir = "_integration-tests/bin/"
39+)
40+
41+// Assets builds the snappy and integration tests binaries for the target
42+// architecture.
43+func Assets(useSnappyFromBranch bool, arch string) {
44+ utils.PrepareTargetDir(testsBinDir)
45+
46+ if useSnappyFromBranch {
47+ // FIXME We need to build an image that has the snappy from the branch
48+ // installed. --elopio - 2015-06-25.
49+ buildSnappyCLI(arch)
50+ }
51+ buildTests(arch)
52+}
53+
54+func buildSnappyCLI(arch string) {
55+ fmt.Println("Building snappy CLI...")
56+ // On the root of the project we have a directory called snappy, so we
57+ // output the binary for the tests in the tests directory.
58+ goCall(arch, "build", "-o", testsBinDir+"snappy", "./cmd/snappy")
59+}
60+
61+func buildTests(arch string) {
62+ fmt.Println("Building tests...")
63+
64+ goCall(arch, "test", "-c", "./_integration-tests/tests")
65+ // XXX Go test 1.3 does not have the output flag, so we move the
66+ // binaries after they are generated.
67+ os.Rename("tests.test", testsBinDir+IntegrationTestName)
68+}
69+
70+func goCall(arch string, cmds ...string) {
71+ if arch != "" {
72+ defer os.Setenv("GOARCH", os.Getenv("GOARCH"))
73+ os.Setenv("GOARCH", arch)
74+ if arch == "arm" {
75+ defer os.Setenv("GOARM", os.Getenv("GOARM"))
76+ os.Setenv("GOARM", defaultGoArm)
77+ }
78+ }
79+ goCmd := append([]string{"go"}, cmds...)
80+ utils.ExecCommand(goCmd...)
81+}
82
83=== modified file '_integration-tests/main.go'
84--- _integration-tests/main.go 2015-07-24 08:13:24 +0000
85+++ _integration-tests/main.go 2015-07-28 12:05:32 +0000
86@@ -28,21 +28,19 @@
87 "strconv"
88 "text/template"
89
90+ "launchpad.net/snappy/_integration-tests/helpers/build"
91 "launchpad.net/snappy/_integration-tests/helpers/config"
92 "launchpad.net/snappy/_integration-tests/helpers/image"
93 "launchpad.net/snappy/_integration-tests/helpers/utils"
94 )
95
96 const (
97- baseDir = "/tmp/snappy-test"
98- testsBinDir = "_integration-tests/bin/"
99- defaultRelease = "rolling"
100- defaultChannel = "edge"
101- defaultSSHPort = 22
102- defaultGoArm = "7"
103- dataOutputDir = "_integration-tests/data/output/"
104- controlTpl = "_integration-tests/data/tpl/control"
105- integrationTestName = "integration.test"
106+ baseDir = "/tmp/snappy-test"
107+ defaultRelease = "rolling"
108+ defaultChannel = "edge"
109+ defaultSSHPort = 22
110+ dataOutputDir = "_integration-tests/data/output/"
111+ controlTpl = "_integration-tests/data/tpl/control"
112 )
113
114 var (
115@@ -51,17 +49,6 @@
116 controlFile = filepath.Join(dataOutputDir, "control")
117 )
118
119-func buildAssets(useSnappyFromBranch bool, arch string) {
120- utils.PrepareTargetDir(testsBinDir)
121-
122- if useSnappyFromBranch {
123- // FIXME We need to build an image that has the snappy from the branch
124- // installed. --elopio - 2015-06-25.
125- buildSnappyCLI(arch)
126- }
127- buildTests(arch)
128-}
129-
130 func setupAndRunLocalTests(rootPath, testFilter string, img image.Image) {
131 // Run the tests on the latest rolling edge image.
132 if imageName, err := img.UdfCreate(); err == nil {
133@@ -75,35 +62,6 @@
134 adtRun(rootPath, testFilter, remoteTestbedSSHOptions(testbedIP, testbedPort))
135 }
136
137-func buildSnappyCLI(arch string) {
138- fmt.Println("Building snappy CLI...")
139- // On the root of the project we have a directory called snappy, so we
140- // output the binary for the tests in the tests directory.
141- goCall(arch, "build", "-o", testsBinDir+"snappy", "./cmd/snappy")
142-}
143-
144-func buildTests(arch string) {
145- fmt.Println("Building tests...")
146-
147- goCall(arch, "test", "-c", "./_integration-tests/tests")
148- // XXX Go test 1.3 does not have the output flag, so we move the
149- // binaries after they are generated.
150- os.Rename("tests.test", testsBinDir+integrationTestName)
151-}
152-
153-func goCall(arch string, cmds ...string) {
154- if arch != "" {
155- defer os.Setenv("GOARCH", os.Getenv("GOARCH"))
156- os.Setenv("GOARCH", arch)
157- if arch == "arm" {
158- defer os.Setenv("GOARM", os.Getenv("GOARM"))
159- os.Setenv("GOARM", defaultGoArm)
160- }
161- }
162- goCmd := append([]string{"go"}, cmds...)
163- utils.ExecCommand(goCmd...)
164-}
165-
166 func adtRun(rootPath, testFilter string, testbedOptions []string) {
167 createControlFile(testFilter)
168
169@@ -147,7 +105,7 @@
170 defer outputFile.Close()
171
172 err = tpl.Execute(outputFile,
173- controlData{Test: integrationTestName, Filter: testFilter})
174+ controlData{Test: build.IntegrationTestName, Filter: testFilter})
175 if err != nil {
176 log.Panicf("execution: %s", err)
177 }
178@@ -201,7 +159,7 @@
179
180 flag.Parse()
181
182- buildAssets(*useSnappyFromBranch, *arch)
183+ build.Assets(*useSnappyFromBranch, *arch)
184
185 // TODO: generate the files out of the source tree. --elopio - 2015-07-15
186 utils.PrepareTargetDir(dataOutputDir)

Subscribers

People subscribed via source and target branches