Merge lp:~elopio/snappy/go-tests into lp:~fgimenez/snappy/go-functional-tests

Proposed by Leo Arias
Status: Merged
Approved by: Federico Gimenez
Approved revision: 495
Merged at revision: 490
Proposed branch: lp:~elopio/snappy/go-tests
Merge into: lp:~fgimenez/snappy/go-functional-tests
Diff against target: 319 lines (+51/-39)
14 files modified
cmd/snappy/cmd_install.go (+2/-2)
debian/changelog (+8/-0)
debian/control (+6/-0)
debian/integration-tests/control (+5/-0)
debian/integration-tests/snappy_test.go (+1/-1)
debian/rules (+6/-0)
debian/tests/control (+0/-2)
debian/ubuntu-snappy-tests.install (+1/-0)
partition/bootloader_uboot_test.go (+2/-5)
policy/policy.go (+7/-7)
policy/policy_test.go (+7/-5)
run-functional-tests.py (+3/-15)
snappy/build.go (+1/-0)
snappy/snapp.go (+2/-2)
To merge this branch: bzr merge lp:~elopio/snappy/go-tests
Reviewer Review Type Date Requested Status
Federico Gimenez Approve
Review via email: mp+261903@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

@federico: if you merge yours with trunk you will see a nicer diff.
Here I'm playing with building the tests into a package, instead of compiling them as part of the script. It's a little ugly, it would be nice to get some comments from a go packager.

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

Awesome Leo, this is getting into shape :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/snappy/cmd_install.go'
2--- cmd/snappy/cmd_install.go 2015-05-19 14:09:19 +0000
3+++ cmd/snappy/cmd_install.go 2015-06-13 19:17:48 +0000
4@@ -34,8 +34,8 @@
5 AllowUnauthenticated bool `long:"allow-unauthenticated" description:"Install snaps even if the signature can not be verified."`
6 DisableGC bool `long:"no-gc" description:"Do not clean up old versions of the package."`
7 Positional struct {
8- PackageName string `positional-arg-name:"package name" description:"Set configuration for a specific installed package"`
9- ConfigFile string `positional-arg-name:"config file" description:"The configuration for the given file"`
10+ PackageName string `positional-arg-name:"package name" description:"The Package to install (name or path)"`
11+ ConfigFile string `positional-arg-name:"config file" description:"The configuration for the given install"`
12 } `positional-args:"yes"`
13 }
14
15
16=== modified file 'debian/changelog'
17--- debian/changelog 2015-06-10 19:17:06 +0000
18+++ debian/changelog 2015-06-13 19:17:48 +0000
19@@ -1,3 +1,11 @@
20+ubuntu-snappy (1.1.2-0ubuntu1) wily; urgency=medium
21+
22+ * New upstream release, including the following changes:
23+ - Remove compatibility for click-bin-path in generated exec-wrappers
24+ - Release the readme.md after parsing it
25+
26+ -- Ricardo Salveti de Araujo <ricardo.salveti@canonical.com> Thu, 11 Jun 2015 23:42:49 -0300
27+
28 ubuntu-snappy (1.1.1-0ubuntu1) wily; urgency=medium
29
30 * New upstream release, including the following changes:
31
32=== modified file 'debian/control'
33--- debian/control 2015-06-02 20:46:07 +0000
34+++ debian/control 2015-06-13 19:17:48 +0000
35@@ -51,3 +51,9 @@
36 Built-Using: ${misc:Built-Using}
37 Description: Tool to interact with Ubuntu Core Snappy.
38 Manage an Ubuntu system with snappy.
39+
40+Package: ubuntu-snappy-tests
41+Architecture: any
42+Depends: ubuntu-snappy-cli (= ${binary:Version}),
43+ ${misc:Depends}
44+Description: snappy selftests
45
46=== added directory 'debian/integration-tests'
47=== added file 'debian/integration-tests/control'
48--- debian/integration-tests/control 1970-01-01 00:00:00 +0000
49+++ debian/integration-tests/control 2015-06-13 19:17:48 +0000
50@@ -0,0 +1,5 @@
51+Test-Command: snappy.test
52+Depends: ubuntu-snappy-tests
53+
54+#Test-Command: ./snappy-selftest --yes-really
55+#Depends:
56
57=== renamed file 'debian/tests/snappy_test.go' => 'debian/integration-tests/snappy_test.go'
58--- debian/tests/snappy_test.go 2015-06-10 15:13:16 +0000
59+++ debian/integration-tests/snappy_test.go 2015-06-13 19:17:48 +0000
60@@ -4,7 +4,7 @@
61 "os/exec"
62 "testing"
63
64- . "launchpad.net/gocheck"
65+ . "gopkg.in/check.v1"
66 )
67
68 // Hook up gocheck into the "go test" runner
69
70=== modified file 'debian/rules'
71--- debian/rules 2015-04-14 16:46:57 +0000
72+++ debian/rules 2015-06-13 19:17:48 +0000
73@@ -4,6 +4,7 @@
74 #export DH_VERBOSE=1
75 export DH_OPTIONS
76 export DH_GOPKG := launchpad.net/snappy
77+DH_BUILDDIR = obj-$(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
78
79 %:
80 dh $@ --buildsystem=golang --with=golang --fail-missing --with systemd
81@@ -50,6 +51,11 @@
82 -pubuntu-snappy \
83 snappy-autopilot.service
84
85+override_dh_auto_build:
86+ dh_auto_build
87+ GOPATH=$$PWD/$(DH_BUILDDIR) go test -c debian/integration-tests/snappy_test.go
88+ mv snappy.test $$PWD/$(DH_BUILDDIR)/bin
89+
90 override_dh_auto_install:
91 dh_auto_install -O--buildsystem=golang
92 # Making the packages private
93
94=== removed directory 'debian/tests'
95=== removed file 'debian/tests/control'
96--- debian/tests/control 2015-06-11 09:15:25 +0000
97+++ debian/tests/control 1970-01-01 00:00:00 +0000
98@@ -1,2 +0,0 @@
99-Tests: tests.test
100-Restrictions: allow-stderr
101
102=== added file 'debian/ubuntu-snappy-tests.install'
103--- debian/ubuntu-snappy-tests.install 1970-01-01 00:00:00 +0000
104+++ debian/ubuntu-snappy-tests.install 2015-06-13 19:17:48 +0000
105@@ -0,0 +1,1 @@
106+/usr/bin/snappy.test
107
108=== modified file 'partition/bootloader_uboot_test.go'
109--- partition/bootloader_uboot_test.go 2015-06-09 17:43:20 +0000
110+++ partition/bootloader_uboot_test.go 2015-06-13 19:17:48 +0000
111@@ -204,7 +204,6 @@
112
113 // mock the hardwareYaml and the cacheDir
114 p.hardwareSpecFile = makeHardwareYaml(c, "bootloader: grub")
115- defaultCacheDir = c.MkDir()
116
117 err = bootloader.HandleAssets()
118 c.Assert(err, NotNil)
119@@ -221,7 +220,6 @@
120 bootloader: u-boot
121 partition-layout: inplace
122 `)
123- defaultCacheDir = c.MkDir()
124
125 err = bootloader.HandleAssets()
126 c.Assert(err, NotNil)
127@@ -229,12 +227,12 @@
128
129 func (s *PartitionTestSuite) TestHandleAssetsNoHardwareYaml(c *C) {
130 s.makeFakeUbootEnv(c)
131+ defaultCacheDir = c.MkDir()
132+
133 p := New()
134 bootloader, err := bootloader(p)
135 c.Assert(err, IsNil)
136
137- defaultCacheDir = c.MkDir()
138-
139 c.Assert(bootloader.HandleAssets(), IsNil)
140 }
141
142@@ -247,7 +245,6 @@
143 p.hardwareSpecFile = makeHardwareYaml(c, `
144 bootloader u-boot
145 `)
146- defaultCacheDir = c.MkDir()
147
148 c.Assert(bootloader.HandleAssets(), NotNil)
149 }
150
151=== modified file 'policy/policy.go'
152--- policy/policy.go 2015-05-15 13:33:27 +0000
153+++ policy/policy.go 2015-06-13 19:17:48 +0000
154@@ -60,7 +60,7 @@
155 // Directories are created as needed. Errors out with any of the things that
156 // could go wrong with this, including a file found by glob not being a
157 // regular file.
158-func iterOp(op policyOp, glob string, targetDir string, prefix string) (err error) {
159+func iterOp(op policyOp, glob, targetDir, prefix string) (err error) {
160 if err = os.MkdirAll(targetDir, 0755); err != nil {
161 return fmt.Errorf("unable to make %v directory: %v", targetDir, err)
162 }
163@@ -104,11 +104,11 @@
164
165 // frameworkOp perform the given operation (either Install or Remove) on the
166 // given package that's installed in the given path.
167-func frameworkOp(op policyOp, pkgName string, instPath string) error {
168+func frameworkOp(op policyOp, pkgName, instPath, rootDir string) error {
169 pol := filepath.Join(instPath, "meta", "framework-policy")
170 for _, i := range []string{"apparmor", "seccomp"} {
171 for _, j := range []string{"policygroups", "templates"} {
172- if err := iterOp(op, filepath.Join(pol, i, j, "*"), filepath.Join(SecBase, i, j), pkgName+"_"); err != nil {
173+ if err := iterOp(op, filepath.Join(pol, i, j, "*"), filepath.Join(rootDir, SecBase, i, j), pkgName+"_"); err != nil {
174 return err
175 }
176 }
177@@ -119,14 +119,14 @@
178
179 // Install sets up the framework's policy from the given snap that's
180 // installed in the given path.
181-func Install(pkgName string, instPath string) error {
182- return frameworkOp(install, pkgName, instPath)
183+func Install(pkgName, instPath, rootDir string) error {
184+ return frameworkOp(install, pkgName, instPath, rootDir)
185 }
186
187 // Remove cleans up the framework's policy from the given snap that's
188 // installed in the given path.
189-func Remove(pkgName string, instPath string) error {
190- return frameworkOp(remove, pkgName, instPath)
191+func Remove(pkgName, instPath, rootDir string) error {
192+ return frameworkOp(remove, pkgName, instPath, rootDir)
193 }
194
195 func aaUp(old, new, dir, pfx string) map[string]bool {
196
197=== modified file 'policy/policy_test.go'
198--- policy/policy_test.go 2015-06-02 20:53:10 +0000
199+++ policy/policy_test.go 2015-06-13 19:17:48 +0000
200@@ -26,8 +26,9 @@
201 "path/filepath"
202 "testing"
203
204+ "sort"
205+
206 . "gopkg.in/check.v1"
207- "sort"
208 )
209
210 // Hook up check.v1 into the "go test" runner.
211@@ -140,13 +141,14 @@
212 }
213
214 func (s *policySuite) TestFrameworkRoundtrip(c *C) {
215+ rootDir := c.MkDir()
216 SecBase = s.dest
217- c.Check(Install("foo", s.orig), IsNil)
218+ c.Check(Install("foo", s.orig, rootDir), IsNil)
219 // check the files were copied, with the packagename prepended properly
220- g, err := filepath.Glob(filepath.Join(SecBase, "*", "*", "foo_*"))
221+ g, err := filepath.Glob(filepath.Join(rootDir, SecBase, "*", "*", "foo_*"))
222 c.Check(err, IsNil)
223 c.Check(g, HasLen, 4*3)
224- c.Check(Remove("foo", s.orig), IsNil)
225+ c.Check(Remove("foo", s.orig, rootDir), IsNil)
226 g, err = filepath.Glob(filepath.Join(SecBase, "*", "*", "*"))
227 c.Check(err, IsNil)
228 c.Check(g, HasLen, 0)
229@@ -155,7 +157,7 @@
230 func (s *policySuite) TestFrameworkError(c *C) {
231 // check we get errors from the iterOp, is all
232 SecBase = s.dest
233- c.Check(frameworkOp(42, "foo", s.orig), ErrorMatches, ".*unknown operation.*")
234+ c.Check(frameworkOp(42, "foo", s.orig, ""), ErrorMatches, ".*unknown operation.*")
235 }
236
237 func (s *policySuite) TestOpString(c *C) {
238
239=== modified file 'run-functional-tests.py'
240--- run-functional-tests.py 2015-06-12 08:02:18 +0000
241+++ run-functional-tests.py 2015-06-13 19:17:48 +0000
242@@ -45,7 +45,7 @@
243 print("Building debs...")
244 prepare_target_dir(DEBS_DIR)
245 return subprocess.check_output([
246- 'bzr-buildpackage',
247+ 'bzr', 'bd',
248 '--result-dir={}'.format(DEBS_DIR),
249 HERE,
250 '--', '-uc', '-us',
251@@ -65,7 +65,8 @@
252 "dpkg -i {debs_dir}/*deb".format(debs_dir=DEBS_TESTBED_PATH),
253 '--setup-commands',
254 'sync; sleep 2; mount -o remount,ro /',
255- '--unbuilt-tree', HERE,
256+ '--override-control', 'debian/integration-tests/control',
257+ '--built-tree', HERE,
258 '--output-dir', OUTPUT_DIR,
259 "--copy={orig_debs_dir}:{target_debs_dir}".format(
260 orig_debs_dir=DEBS_DIR,
261@@ -77,24 +78,11 @@
262 '--', '-i', IMAGE_TARGET,
263 ])
264
265-
266-def compile_tests():
267- print("Compiling tests...")
268- return subprocess.check_output([
269- 'go',
270- 'test',
271- '-c',
272- '-o snappy'
273- ], cwd="{base}/debian/tests/".format(base=HERE))
274-
275-
276 def main():
277 build_debs()
278
279 create_image()
280
281- compile_tests()
282-
283 adt_run()
284
285 return 0
286
287=== modified file 'snappy/build.go'
288--- snappy/build.go 2015-06-03 12:06:17 +0000
289+++ snappy/build.go 2015-06-13 19:17:48 +0000
290@@ -101,6 +101,7 @@
291 if err != nil {
292 return "", "", err
293 }
294+ defer file.Close()
295
296 scanner := bufio.NewScanner(file)
297 for scanner.Scan() {
298
299=== modified file 'snappy/snapp.go'
300--- snappy/snapp.go 2015-06-09 19:11:54 +0000
301+++ snappy/snapp.go 2015-06-13 19:17:48 +0000
302@@ -939,7 +939,7 @@
303 }
304
305 if s.Type() == pkg.TypeFramework {
306- if err := policy.Install(s.Name(), s.basedir); err != nil {
307+ if err := policy.Install(s.Name(), s.basedir, globalRootDir); err != nil {
308 return err
309 }
310 }
311@@ -1001,7 +1001,7 @@
312 }
313
314 if s.Type() == pkg.TypeFramework {
315- if err := policy.Remove(s.Name(), s.basedir); err != nil {
316+ if err := policy.Remove(s.Name(), s.basedir, globalRootDir); err != nil {
317 return err
318 }
319 }

Subscribers

People subscribed via source and target branches

to all changes: