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
=== modified file 'cmd/snappy/cmd_install.go'
--- cmd/snappy/cmd_install.go 2015-05-19 14:09:19 +0000
+++ cmd/snappy/cmd_install.go 2015-06-13 19:17:48 +0000
@@ -34,8 +34,8 @@
34 AllowUnauthenticated bool `long:"allow-unauthenticated" description:"Install snaps even if the signature can not be verified."`34 AllowUnauthenticated bool `long:"allow-unauthenticated" description:"Install snaps even if the signature can not be verified."`
35 DisableGC bool `long:"no-gc" description:"Do not clean up old versions of the package."`35 DisableGC bool `long:"no-gc" description:"Do not clean up old versions of the package."`
36 Positional struct {36 Positional struct {
37 PackageName string `positional-arg-name:"package name" description:"Set configuration for a specific installed package"`37 PackageName string `positional-arg-name:"package name" description:"The Package to install (name or path)"`
38 ConfigFile string `positional-arg-name:"config file" description:"The configuration for the given file"`38 ConfigFile string `positional-arg-name:"config file" description:"The configuration for the given install"`
39 } `positional-args:"yes"`39 } `positional-args:"yes"`
40}40}
4141
4242
=== modified file 'debian/changelog'
--- debian/changelog 2015-06-10 19:17:06 +0000
+++ debian/changelog 2015-06-13 19:17:48 +0000
@@ -1,3 +1,11 @@
1ubuntu-snappy (1.1.2-0ubuntu1) wily; urgency=medium
2
3 * New upstream release, including the following changes:
4 - Remove compatibility for click-bin-path in generated exec-wrappers
5 - Release the readme.md after parsing it
6
7 -- Ricardo Salveti de Araujo <ricardo.salveti@canonical.com> Thu, 11 Jun 2015 23:42:49 -0300
8
1ubuntu-snappy (1.1.1-0ubuntu1) wily; urgency=medium9ubuntu-snappy (1.1.1-0ubuntu1) wily; urgency=medium
210
3 * New upstream release, including the following changes:11 * New upstream release, including the following changes:
412
=== modified file 'debian/control'
--- debian/control 2015-06-02 20:46:07 +0000
+++ debian/control 2015-06-13 19:17:48 +0000
@@ -51,3 +51,9 @@
51Built-Using: ${misc:Built-Using}51Built-Using: ${misc:Built-Using}
52Description: Tool to interact with Ubuntu Core Snappy.52Description: Tool to interact with Ubuntu Core Snappy.
53 Manage an Ubuntu system with snappy.53 Manage an Ubuntu system with snappy.
54
55Package: ubuntu-snappy-tests
56Architecture: any
57Depends: ubuntu-snappy-cli (= ${binary:Version}),
58 ${misc:Depends}
59Description: snappy selftests
5460
=== added directory 'debian/integration-tests'
=== added file 'debian/integration-tests/control'
--- debian/integration-tests/control 1970-01-01 00:00:00 +0000
+++ debian/integration-tests/control 2015-06-13 19:17:48 +0000
@@ -0,0 +1,5 @@
1Test-Command: snappy.test
2Depends: ubuntu-snappy-tests
3
4#Test-Command: ./snappy-selftest --yes-really
5#Depends:
06
=== renamed file 'debian/tests/snappy_test.go' => 'debian/integration-tests/snappy_test.go'
--- debian/tests/snappy_test.go 2015-06-10 15:13:16 +0000
+++ debian/integration-tests/snappy_test.go 2015-06-13 19:17:48 +0000
@@ -4,7 +4,7 @@
4 "os/exec"4 "os/exec"
5 "testing"5 "testing"
66
7 . "launchpad.net/gocheck"7 . "gopkg.in/check.v1"
8)8)
99
10// Hook up gocheck into the "go test" runner10// Hook up gocheck into the "go test" runner
1111
=== modified file 'debian/rules'
--- debian/rules 2015-04-14 16:46:57 +0000
+++ debian/rules 2015-06-13 19:17:48 +0000
@@ -4,6 +4,7 @@
4#export DH_VERBOSE=14#export DH_VERBOSE=1
5export DH_OPTIONS5export DH_OPTIONS
6export DH_GOPKG := launchpad.net/snappy6export DH_GOPKG := launchpad.net/snappy
7DH_BUILDDIR = obj-$(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
78
8%:9%:
9 dh $@ --buildsystem=golang --with=golang --fail-missing --with systemd10 dh $@ --buildsystem=golang --with=golang --fail-missing --with systemd
@@ -50,6 +51,11 @@
50 -pubuntu-snappy \51 -pubuntu-snappy \
51 snappy-autopilot.service52 snappy-autopilot.service
5253
54override_dh_auto_build:
55 dh_auto_build
56 GOPATH=$$PWD/$(DH_BUILDDIR) go test -c debian/integration-tests/snappy_test.go
57 mv snappy.test $$PWD/$(DH_BUILDDIR)/bin
58
53override_dh_auto_install:59override_dh_auto_install:
54 dh_auto_install -O--buildsystem=golang60 dh_auto_install -O--buildsystem=golang
55 # Making the packages private61 # Making the packages private
5662
=== removed directory 'debian/tests'
=== removed file 'debian/tests/control'
--- debian/tests/control 2015-06-11 09:15:25 +0000
+++ debian/tests/control 1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
1Tests: tests.test
2Restrictions: allow-stderr
30
=== added file 'debian/ubuntu-snappy-tests.install'
--- debian/ubuntu-snappy-tests.install 1970-01-01 00:00:00 +0000
+++ debian/ubuntu-snappy-tests.install 2015-06-13 19:17:48 +0000
@@ -0,0 +1,1 @@
1/usr/bin/snappy.test
02
=== modified file 'partition/bootloader_uboot_test.go'
--- partition/bootloader_uboot_test.go 2015-06-09 17:43:20 +0000
+++ partition/bootloader_uboot_test.go 2015-06-13 19:17:48 +0000
@@ -204,7 +204,6 @@
204204
205 // mock the hardwareYaml and the cacheDir205 // mock the hardwareYaml and the cacheDir
206 p.hardwareSpecFile = makeHardwareYaml(c, "bootloader: grub")206 p.hardwareSpecFile = makeHardwareYaml(c, "bootloader: grub")
207 defaultCacheDir = c.MkDir()
208207
209 err = bootloader.HandleAssets()208 err = bootloader.HandleAssets()
210 c.Assert(err, NotNil)209 c.Assert(err, NotNil)
@@ -221,7 +220,6 @@
221bootloader: u-boot220bootloader: u-boot
222partition-layout: inplace221partition-layout: inplace
223`)222`)
224 defaultCacheDir = c.MkDir()
225223
226 err = bootloader.HandleAssets()224 err = bootloader.HandleAssets()
227 c.Assert(err, NotNil)225 c.Assert(err, NotNil)
@@ -229,12 +227,12 @@
229227
230func (s *PartitionTestSuite) TestHandleAssetsNoHardwareYaml(c *C) {228func (s *PartitionTestSuite) TestHandleAssetsNoHardwareYaml(c *C) {
231 s.makeFakeUbootEnv(c)229 s.makeFakeUbootEnv(c)
230 defaultCacheDir = c.MkDir()
231
232 p := New()232 p := New()
233 bootloader, err := bootloader(p)233 bootloader, err := bootloader(p)
234 c.Assert(err, IsNil)234 c.Assert(err, IsNil)
235235
236 defaultCacheDir = c.MkDir()
237
238 c.Assert(bootloader.HandleAssets(), IsNil)236 c.Assert(bootloader.HandleAssets(), IsNil)
239}237}
240238
@@ -247,7 +245,6 @@
247 p.hardwareSpecFile = makeHardwareYaml(c, `245 p.hardwareSpecFile = makeHardwareYaml(c, `
248bootloader u-boot246bootloader u-boot
249`)247`)
250 defaultCacheDir = c.MkDir()
251248
252 c.Assert(bootloader.HandleAssets(), NotNil)249 c.Assert(bootloader.HandleAssets(), NotNil)
253}250}
254251
=== modified file 'policy/policy.go'
--- policy/policy.go 2015-05-15 13:33:27 +0000
+++ policy/policy.go 2015-06-13 19:17:48 +0000
@@ -60,7 +60,7 @@
60// Directories are created as needed. Errors out with any of the things that60// Directories are created as needed. Errors out with any of the things that
61// could go wrong with this, including a file found by glob not being a61// could go wrong with this, including a file found by glob not being a
62// regular file.62// regular file.
63func iterOp(op policyOp, glob string, targetDir string, prefix string) (err error) {63func iterOp(op policyOp, glob, targetDir, prefix string) (err error) {
64 if err = os.MkdirAll(targetDir, 0755); err != nil {64 if err = os.MkdirAll(targetDir, 0755); err != nil {
65 return fmt.Errorf("unable to make %v directory: %v", targetDir, err)65 return fmt.Errorf("unable to make %v directory: %v", targetDir, err)
66 }66 }
@@ -104,11 +104,11 @@
104104
105// frameworkOp perform the given operation (either Install or Remove) on the105// frameworkOp perform the given operation (either Install or Remove) on the
106// given package that's installed in the given path.106// given package that's installed in the given path.
107func frameworkOp(op policyOp, pkgName string, instPath string) error {107func frameworkOp(op policyOp, pkgName, instPath, rootDir string) error {
108 pol := filepath.Join(instPath, "meta", "framework-policy")108 pol := filepath.Join(instPath, "meta", "framework-policy")
109 for _, i := range []string{"apparmor", "seccomp"} {109 for _, i := range []string{"apparmor", "seccomp"} {
110 for _, j := range []string{"policygroups", "templates"} {110 for _, j := range []string{"policygroups", "templates"} {
111 if err := iterOp(op, filepath.Join(pol, i, j, "*"), filepath.Join(SecBase, i, j), pkgName+"_"); err != nil {111 if err := iterOp(op, filepath.Join(pol, i, j, "*"), filepath.Join(rootDir, SecBase, i, j), pkgName+"_"); err != nil {
112 return err112 return err
113 }113 }
114 }114 }
@@ -119,14 +119,14 @@
119119
120// Install sets up the framework's policy from the given snap that's120// Install sets up the framework's policy from the given snap that's
121// installed in the given path.121// installed in the given path.
122func Install(pkgName string, instPath string) error {122func Install(pkgName, instPath, rootDir string) error {
123 return frameworkOp(install, pkgName, instPath)123 return frameworkOp(install, pkgName, instPath, rootDir)
124}124}
125125
126// Remove cleans up the framework's policy from the given snap that's126// Remove cleans up the framework's policy from the given snap that's
127// installed in the given path.127// installed in the given path.
128func Remove(pkgName string, instPath string) error {128func Remove(pkgName, instPath, rootDir string) error {
129 return frameworkOp(remove, pkgName, instPath)129 return frameworkOp(remove, pkgName, instPath, rootDir)
130}130}
131131
132func aaUp(old, new, dir, pfx string) map[string]bool {132func aaUp(old, new, dir, pfx string) map[string]bool {
133133
=== modified file 'policy/policy_test.go'
--- policy/policy_test.go 2015-06-02 20:53:10 +0000
+++ policy/policy_test.go 2015-06-13 19:17:48 +0000
@@ -26,8 +26,9 @@
26 "path/filepath"26 "path/filepath"
27 "testing"27 "testing"
2828
29 "sort"
30
29 . "gopkg.in/check.v1"31 . "gopkg.in/check.v1"
30 "sort"
31)32)
3233
33// Hook up check.v1 into the "go test" runner.34// Hook up check.v1 into the "go test" runner.
@@ -140,13 +141,14 @@
140}141}
141142
142func (s *policySuite) TestFrameworkRoundtrip(c *C) {143func (s *policySuite) TestFrameworkRoundtrip(c *C) {
144 rootDir := c.MkDir()
143 SecBase = s.dest145 SecBase = s.dest
144 c.Check(Install("foo", s.orig), IsNil)146 c.Check(Install("foo", s.orig, rootDir), IsNil)
145 // check the files were copied, with the packagename prepended properly147 // check the files were copied, with the packagename prepended properly
146 g, err := filepath.Glob(filepath.Join(SecBase, "*", "*", "foo_*"))148 g, err := filepath.Glob(filepath.Join(rootDir, SecBase, "*", "*", "foo_*"))
147 c.Check(err, IsNil)149 c.Check(err, IsNil)
148 c.Check(g, HasLen, 4*3)150 c.Check(g, HasLen, 4*3)
149 c.Check(Remove("foo", s.orig), IsNil)151 c.Check(Remove("foo", s.orig, rootDir), IsNil)
150 g, err = filepath.Glob(filepath.Join(SecBase, "*", "*", "*"))152 g, err = filepath.Glob(filepath.Join(SecBase, "*", "*", "*"))
151 c.Check(err, IsNil)153 c.Check(err, IsNil)
152 c.Check(g, HasLen, 0)154 c.Check(g, HasLen, 0)
@@ -155,7 +157,7 @@
155func (s *policySuite) TestFrameworkError(c *C) {157func (s *policySuite) TestFrameworkError(c *C) {
156 // check we get errors from the iterOp, is all158 // check we get errors from the iterOp, is all
157 SecBase = s.dest159 SecBase = s.dest
158 c.Check(frameworkOp(42, "foo", s.orig), ErrorMatches, ".*unknown operation.*")160 c.Check(frameworkOp(42, "foo", s.orig, ""), ErrorMatches, ".*unknown operation.*")
159}161}
160162
161func (s *policySuite) TestOpString(c *C) {163func (s *policySuite) TestOpString(c *C) {
162164
=== modified file 'run-functional-tests.py'
--- run-functional-tests.py 2015-06-12 08:02:18 +0000
+++ run-functional-tests.py 2015-06-13 19:17:48 +0000
@@ -45,7 +45,7 @@
45 print("Building debs...")45 print("Building debs...")
46 prepare_target_dir(DEBS_DIR)46 prepare_target_dir(DEBS_DIR)
47 return subprocess.check_output([47 return subprocess.check_output([
48 'bzr-buildpackage',48 'bzr', 'bd',
49 '--result-dir={}'.format(DEBS_DIR),49 '--result-dir={}'.format(DEBS_DIR),
50 HERE,50 HERE,
51 '--', '-uc', '-us',51 '--', '-uc', '-us',
@@ -65,7 +65,8 @@
65 "dpkg -i {debs_dir}/*deb".format(debs_dir=DEBS_TESTBED_PATH),65 "dpkg -i {debs_dir}/*deb".format(debs_dir=DEBS_TESTBED_PATH),
66 '--setup-commands',66 '--setup-commands',
67 'sync; sleep 2; mount -o remount,ro /',67 'sync; sleep 2; mount -o remount,ro /',
68 '--unbuilt-tree', HERE,68 '--override-control', 'debian/integration-tests/control',
69 '--built-tree', HERE,
69 '--output-dir', OUTPUT_DIR,70 '--output-dir', OUTPUT_DIR,
70 "--copy={orig_debs_dir}:{target_debs_dir}".format(71 "--copy={orig_debs_dir}:{target_debs_dir}".format(
71 orig_debs_dir=DEBS_DIR,72 orig_debs_dir=DEBS_DIR,
@@ -77,24 +78,11 @@
77 '--', '-i', IMAGE_TARGET,78 '--', '-i', IMAGE_TARGET,
78 ])79 ])
7980
80
81def compile_tests():
82 print("Compiling tests...")
83 return subprocess.check_output([
84 'go',
85 'test',
86 '-c',
87 '-o snappy'
88 ], cwd="{base}/debian/tests/".format(base=HERE))
89
90
91def main():81def main():
92 build_debs()82 build_debs()
9383
94 create_image()84 create_image()
9585
96 compile_tests()
97
98 adt_run()86 adt_run()
9987
100 return 088 return 0
10189
=== modified file 'snappy/build.go'
--- snappy/build.go 2015-06-03 12:06:17 +0000
+++ snappy/build.go 2015-06-13 19:17:48 +0000
@@ -101,6 +101,7 @@
101 if err != nil {101 if err != nil {
102 return "", "", err102 return "", "", err
103 }103 }
104 defer file.Close()
104105
105 scanner := bufio.NewScanner(file)106 scanner := bufio.NewScanner(file)
106 for scanner.Scan() {107 for scanner.Scan() {
107108
=== modified file 'snappy/snapp.go'
--- snappy/snapp.go 2015-06-09 19:11:54 +0000
+++ snappy/snapp.go 2015-06-13 19:17:48 +0000
@@ -939,7 +939,7 @@
939 }939 }
940940
941 if s.Type() == pkg.TypeFramework {941 if s.Type() == pkg.TypeFramework {
942 if err := policy.Install(s.Name(), s.basedir); err != nil {942 if err := policy.Install(s.Name(), s.basedir, globalRootDir); err != nil {
943 return err943 return err
944 }944 }
945 }945 }
@@ -1001,7 +1001,7 @@
1001 }1001 }
10021002
1003 if s.Type() == pkg.TypeFramework {1003 if s.Type() == pkg.TypeFramework {
1004 if err := policy.Remove(s.Name(), s.basedir); err != nil {1004 if err := policy.Remove(s.Name(), s.basedir, globalRootDir); err != nil {
1005 return err1005 return err
1006 }1006 }
1007 }1007 }

Subscribers

People subscribed via source and target branches

to all changes: