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
=== added directory '_integration-tests/helpers/build'
=== added file '_integration-tests/helpers/build/build.go'
--- _integration-tests/helpers/build/build.go 1970-01-01 00:00:00 +0000
+++ _integration-tests/helpers/build/build.go 2015-07-28 12:05:32 +0000
@@ -0,0 +1,76 @@
1// -*- Mode: Go; indent-tabs-mode: t -*-
2
3/*
4 * Copyright (C) 2015 Canonical Ltd
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20package build
21
22import (
23 "fmt"
24 "os"
25
26 "launchpad.net/snappy/_integration-tests/helpers/utils"
27)
28
29const (
30 // IntegrationTestName is the name of the test binary.
31 IntegrationTestName = "integration.test"
32 defaultGoArm = "7"
33 testsBinDir = "_integration-tests/bin/"
34)
35
36// Assets builds the snappy and integration tests binaries for the target
37// architecture.
38func Assets(useSnappyFromBranch bool, arch string) {
39 utils.PrepareTargetDir(testsBinDir)
40
41 if useSnappyFromBranch {
42 // FIXME We need to build an image that has the snappy from the branch
43 // installed. --elopio - 2015-06-25.
44 buildSnappyCLI(arch)
45 }
46 buildTests(arch)
47}
48
49func buildSnappyCLI(arch string) {
50 fmt.Println("Building snappy CLI...")
51 // On the root of the project we have a directory called snappy, so we
52 // output the binary for the tests in the tests directory.
53 goCall(arch, "build", "-o", testsBinDir+"snappy", "./cmd/snappy")
54}
55
56func buildTests(arch string) {
57 fmt.Println("Building tests...")
58
59 goCall(arch, "test", "-c", "./_integration-tests/tests")
60 // XXX Go test 1.3 does not have the output flag, so we move the
61 // binaries after they are generated.
62 os.Rename("tests.test", testsBinDir+IntegrationTestName)
63}
64
65func goCall(arch string, cmds ...string) {
66 if arch != "" {
67 defer os.Setenv("GOARCH", os.Getenv("GOARCH"))
68 os.Setenv("GOARCH", arch)
69 if arch == "arm" {
70 defer os.Setenv("GOARM", os.Getenv("GOARM"))
71 os.Setenv("GOARM", defaultGoArm)
72 }
73 }
74 goCmd := append([]string{"go"}, cmds...)
75 utils.ExecCommand(goCmd...)
76}
077
=== modified file '_integration-tests/main.go'
--- _integration-tests/main.go 2015-07-24 08:13:24 +0000
+++ _integration-tests/main.go 2015-07-28 12:05:32 +0000
@@ -28,21 +28,19 @@
28 "strconv"28 "strconv"
29 "text/template"29 "text/template"
3030
31 "launchpad.net/snappy/_integration-tests/helpers/build"
31 "launchpad.net/snappy/_integration-tests/helpers/config"32 "launchpad.net/snappy/_integration-tests/helpers/config"
32 "launchpad.net/snappy/_integration-tests/helpers/image"33 "launchpad.net/snappy/_integration-tests/helpers/image"
33 "launchpad.net/snappy/_integration-tests/helpers/utils"34 "launchpad.net/snappy/_integration-tests/helpers/utils"
34)35)
3536
36const (37const (
37 baseDir = "/tmp/snappy-test"38 baseDir = "/tmp/snappy-test"
38 testsBinDir = "_integration-tests/bin/"39 defaultRelease = "rolling"
39 defaultRelease = "rolling"40 defaultChannel = "edge"
40 defaultChannel = "edge"41 defaultSSHPort = 22
41 defaultSSHPort = 2242 dataOutputDir = "_integration-tests/data/output/"
42 defaultGoArm = "7"43 controlTpl = "_integration-tests/data/tpl/control"
43 dataOutputDir = "_integration-tests/data/output/"
44 controlTpl = "_integration-tests/data/tpl/control"
45 integrationTestName = "integration.test"
46)44)
4745
48var (46var (
@@ -51,17 +49,6 @@
51 controlFile = filepath.Join(dataOutputDir, "control")49 controlFile = filepath.Join(dataOutputDir, "control")
52)50)
5351
54func buildAssets(useSnappyFromBranch bool, arch string) {
55 utils.PrepareTargetDir(testsBinDir)
56
57 if useSnappyFromBranch {
58 // FIXME We need to build an image that has the snappy from the branch
59 // installed. --elopio - 2015-06-25.
60 buildSnappyCLI(arch)
61 }
62 buildTests(arch)
63}
64
65func setupAndRunLocalTests(rootPath, testFilter string, img image.Image) {52func setupAndRunLocalTests(rootPath, testFilter string, img image.Image) {
66 // Run the tests on the latest rolling edge image.53 // Run the tests on the latest rolling edge image.
67 if imageName, err := img.UdfCreate(); err == nil {54 if imageName, err := img.UdfCreate(); err == nil {
@@ -75,35 +62,6 @@
75 adtRun(rootPath, testFilter, remoteTestbedSSHOptions(testbedIP, testbedPort))62 adtRun(rootPath, testFilter, remoteTestbedSSHOptions(testbedIP, testbedPort))
76}63}
7764
78func buildSnappyCLI(arch string) {
79 fmt.Println("Building snappy CLI...")
80 // On the root of the project we have a directory called snappy, so we
81 // output the binary for the tests in the tests directory.
82 goCall(arch, "build", "-o", testsBinDir+"snappy", "./cmd/snappy")
83}
84
85func buildTests(arch string) {
86 fmt.Println("Building tests...")
87
88 goCall(arch, "test", "-c", "./_integration-tests/tests")
89 // XXX Go test 1.3 does not have the output flag, so we move the
90 // binaries after they are generated.
91 os.Rename("tests.test", testsBinDir+integrationTestName)
92}
93
94func goCall(arch string, cmds ...string) {
95 if arch != "" {
96 defer os.Setenv("GOARCH", os.Getenv("GOARCH"))
97 os.Setenv("GOARCH", arch)
98 if arch == "arm" {
99 defer os.Setenv("GOARM", os.Getenv("GOARM"))
100 os.Setenv("GOARM", defaultGoArm)
101 }
102 }
103 goCmd := append([]string{"go"}, cmds...)
104 utils.ExecCommand(goCmd...)
105}
106
107func adtRun(rootPath, testFilter string, testbedOptions []string) {65func adtRun(rootPath, testFilter string, testbedOptions []string) {
108 createControlFile(testFilter)66 createControlFile(testFilter)
10967
@@ -147,7 +105,7 @@
147 defer outputFile.Close()105 defer outputFile.Close()
148106
149 err = tpl.Execute(outputFile,107 err = tpl.Execute(outputFile,
150 controlData{Test: integrationTestName, Filter: testFilter})108 controlData{Test: build.IntegrationTestName, Filter: testFilter})
151 if err != nil {109 if err != nil {
152 log.Panicf("execution: %s", err)110 log.Panicf("execution: %s", err)
153 }111 }
@@ -201,7 +159,7 @@
201159
202 flag.Parse()160 flag.Parse()
203161
204 buildAssets(*useSnappyFromBranch, *arch)162 build.Assets(*useSnappyFromBranch, *arch)
205163
206 // TODO: generate the files out of the source tree. --elopio - 2015-07-15164 // TODO: generate the files out of the source tree. --elopio - 2015-07-15
207 utils.PrepareTargetDir(dataOutputDir)165 utils.PrepareTargetDir(dataOutputDir)

Subscribers

People subscribed via source and target branches