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

Proposed by Leo Arias
Status: Merged
Approved by: Federico Gimenez
Approved revision: 761
Merged at revision: 769
Proposed branch: lp:~elopio/snappy/examples2
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~elopio/snappy/examples1
Diff against target: 365 lines (+121/-56)
11 files modified
_integration-tests/data/snaps/basic-binaries/bin/fail (+3/-0)
_integration-tests/data/snaps/basic-binaries/bin/success (+3/-0)
_integration-tests/data/snaps/basic-binaries/meta/package.yaml (+2/-0)
_integration-tests/tests/activate_test.go (+2/-1)
_integration-tests/tests/build_test.go (+7/-6)
_integration-tests/tests/examples_test.go (+37/-0)
_integration-tests/tests/info_test.go (+4/-3)
_integration-tests/tests/installApp_test.go (+21/-28)
_integration-tests/tests/snapd_1_0_packages_test.go (+4/-3)
_integration-tests/testutils/build/snap.go (+5/-15)
_integration-tests/testutils/data/data.go (+33/-0)
To merge this branch: bzr merge lp:~elopio/snappy/examples2
Reviewer Review Type Date Requested Status
Federico Gimenez (community) Approve
Review via email: mp+273852@code.launchpad.net

Commit message

Added a snap to test binaries.
Moved the hello-world tests to examples.

To post a comment you must log in.
lp:~elopio/snappy/examples2 updated
757. By Leo Arias

Moved the hello-world.evil test to examples. The hw-assign test already checks this.

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

Looks very good, I think that we should keep the TestCallBinaryWithPermissionDeniedMustPrintError test, in hwAssign we check hardware assignation (adding elements to a device cgroup) and this test checks app confinement (write permissions to a directory that can be granted through apparmor).

Thanks!

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

I merged with trunk.

@Federico, I moved the TestCallBinaryWithPermissionDeniedMustPrintError test to examples TestCallHelloWorldEvilMustPrintPermissionDeniedError

Can you please take a look again?

lp:~elopio/snappy/examples2 updated
758. By Leo Arias

Merged with trunk.

759. By Leo Arias

Fixed fmt.

760. By Leo Arias

Moved the binaries to the existing snap.

761. By Leo Arias

Updated the snap name.

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

Thanks Leo, sorry I didn't realize at first that the test was moved, not deleted.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file '_integration-tests/data/snaps/basic-binaries/bin/fail'
--- _integration-tests/data/snaps/basic-binaries/bin/fail 1970-01-01 00:00:00 +0000
+++ _integration-tests/data/snaps/basic-binaries/bin/fail 2015-10-13 15:56:19 +0000
@@ -0,0 +1,3 @@
1#!/bin/sh
2
3exit 1
04
=== added file '_integration-tests/data/snaps/basic-binaries/bin/success'
--- _integration-tests/data/snaps/basic-binaries/bin/success 1970-01-01 00:00:00 +0000
+++ _integration-tests/data/snaps/basic-binaries/bin/success 2015-10-13 15:56:19 +0000
@@ -0,0 +1,3 @@
1#!/bin/sh
2
3exit 0
04
=== modified file '_integration-tests/data/snaps/basic-binaries/meta/package.yaml'
--- _integration-tests/data/snaps/basic-binaries/meta/package.yaml 2015-10-09 07:42:40 +0000
+++ _integration-tests/data/snaps/basic-binaries/meta/package.yaml 2015-10-13 15:56:19 +0000
@@ -4,3 +4,5 @@
4icon: meta/snappy64.png4icon: meta/snappy64.png
5binaries:5binaries:
6 - name: bin/echo6 - name: bin/echo
7 - name: bin/success
8 - name: bin/fail
79
=== modified file '_integration-tests/tests/activate_test.go'
--- _integration-tests/tests/activate_test.go 2015-10-09 07:49:19 +0000
+++ _integration-tests/tests/activate_test.go 2015-10-13 15:56:19 +0000
@@ -27,10 +27,11 @@
27 "launchpad.net/snappy/_integration-tests/testutils/build"27 "launchpad.net/snappy/_integration-tests/testutils/build"
28 "launchpad.net/snappy/_integration-tests/testutils/cli"28 "launchpad.net/snappy/_integration-tests/testutils/cli"
29 "launchpad.net/snappy/_integration-tests/testutils/common"29 "launchpad.net/snappy/_integration-tests/testutils/common"
30 "launchpad.net/snappy/_integration-tests/testutils/data"
30)31)
3132
32const (33const (
33 activateSnapName = "basic-binaries"34 activateSnapName = data.BasicBinariesSnapName
34 activateBinName = activateSnapName + ".echo"35 activateBinName = activateSnapName + ".echo"
35 activateEchoOutput = "From basic-binaries snap\n"36 activateEchoOutput = "From basic-binaries snap\n"
36 baseActivatePattern = "(?msU).*" + activateSnapName + `\s*.*\s*.*sideload`37 baseActivatePattern = "(?msU).*" + activateSnapName + `\s*.*\s*.*sideload`
3738
=== modified file '_integration-tests/tests/build_test.go'
--- _integration-tests/tests/build_test.go 2015-09-28 10:35:06 +0000
+++ _integration-tests/tests/build_test.go 2015-10-13 15:56:19 +0000
@@ -26,6 +26,7 @@
2626
27 "launchpad.net/snappy/_integration-tests/testutils/build"27 "launchpad.net/snappy/_integration-tests/testutils/build"
28 "launchpad.net/snappy/_integration-tests/testutils/common"28 "launchpad.net/snappy/_integration-tests/testutils/common"
29 "launchpad.net/snappy/_integration-tests/testutils/data"
2930
30 "gopkg.in/check.v1"31 "gopkg.in/check.v1"
31)32)
@@ -38,37 +39,37 @@
3839
39func (s *buildSuite) TestBuildBasicSnapOnSnappy(c *check.C) {40func (s *buildSuite) TestBuildBasicSnapOnSnappy(c *check.C) {
40 // build basic snap and check output41 // build basic snap and check output
41 snapPath, err := build.LocalSnap(c, build.BasicSnapName)42 snapPath, err := build.LocalSnap(c, data.BasicSnapName)
42 defer os.Remove(snapPath)43 defer os.Remove(snapPath)
43 c.Assert(err, check.IsNil)44 c.Assert(err, check.IsNil)
4445
45 // install built snap and check output46 // install built snap and check output
46 installOutput := common.InstallSnap(c, snapPath)47 installOutput := common.InstallSnap(c, snapPath)
47 defer common.RemoveSnap(c, build.BasicSnapName)48 defer common.RemoveSnap(c, data.BasicSnapName)
48 expected := "(?ms)" +49 expected := "(?ms)" +
49 "Installing " + snapPath + "\n" +50 "Installing " + snapPath + "\n" +
50 ".*Signature check failed, but installing anyway as requested\n" +51 ".*Signature check failed, but installing anyway as requested\n" +
51 "Name +Date +Version +Developer \n" +52 "Name +Date +Version +Developer \n" +
52 ".*\n" +53 ".*\n" +
53 build.BasicSnapName + " +.* +.* +sideload \n" +54 data.BasicSnapName + " +.* +.* +sideload \n" +
54 ".*\n"55 ".*\n"
5556
56 c.Check(installOutput, check.Matches, expected)57 c.Check(installOutput, check.Matches, expected)
57}58}
5859
59func (s *buildSuite) TestBuildWrongYamlSnapOnSnappy(c *check.C) {60func (s *buildSuite) TestBuildWrongYamlSnapOnSnappy(c *check.C) {
60 commonWrongTest(c, build.WrongYamlSnapName,61 commonWrongTest(c, data.WrongYamlSnapName,
61 "(?msi).*Can not parse.*yaml: line 2: mapping values are not allowed in this context.*")62 "(?msi).*Can not parse.*yaml: line 2: mapping values are not allowed in this context.*")
62}63}
6364
64func (s *buildSuite) TestBuildMissingReadmeSnapOnSnappy(c *check.C) {65func (s *buildSuite) TestBuildMissingReadmeSnapOnSnappy(c *check.C) {
65 commonWrongTest(c, build.MissingReadmeSnapName,66 commonWrongTest(c, data.MissingReadmeSnapName,
66 ".*readme.md: no such file or directory\n")67 ".*readme.md: no such file or directory\n")
67}68}
6869
69func commonWrongTest(c *check.C, testName, expected string) {70func commonWrongTest(c *check.C, testName, expected string) {
70 // build wrong snap and check error71 // build wrong snap and check error
71 cmd := exec.Command("snappy", "build", fmt.Sprintf("%s/%s", build.BaseSnapPath, testName))72 cmd := exec.Command("snappy", "build", fmt.Sprintf("%s/%s", data.BaseSnapPath, testName))
72 echoOutput, err := cmd.CombinedOutput()73 echoOutput, err := cmd.CombinedOutput()
73 c.Assert(err, check.NotNil, check.Commentf("%s should not be built", testName))74 c.Assert(err, check.NotNil, check.Commentf("%s should not be built", testName))
7475
7576
=== modified file '_integration-tests/tests/examples_test.go'
--- _integration-tests/tests/examples_test.go 2015-10-09 16:18:01 +0000
+++ _integration-tests/tests/examples_test.go 2015-10-13 15:56:19 +0000
@@ -29,6 +29,43 @@
29 "gopkg.in/check.v1"29 "gopkg.in/check.v1"
30)30)
3131
32var _ = check.Suite(&helloWorldExampleSuite{})
33
34type helloWorldExampleSuite struct {
35 common.SnappySuite
36}
37
38func (s *helloWorldExampleSuite) TestCallHelloWorldBinary(c *check.C) {
39 common.InstallSnap(c, "hello-world")
40 s.AddCleanup(func() {
41 common.RemoveSnap(c, "hello-world")
42 })
43
44 echoOutput := cli.ExecCommand(c, "hello-world.echo")
45
46 c.Assert(echoOutput, check.Equals, "Hello World!\n")
47}
48
49func (s *helloWorldExampleSuite) TestCallHelloWorldEvilMustPrintPermissionDeniedError(c *check.C) {
50 common.InstallSnap(c, "hello-world")
51 s.AddCleanup(func() {
52 common.RemoveSnap(c, "hello-world")
53 })
54
55 echoOutput, err := cli.ExecCommandErr("hello-world.evil")
56 c.Assert(err, check.NotNil, check.Commentf("hello-world.evil did not fail"))
57
58 expected := "" +
59 "Hello Evil World!\n" +
60 "This example demonstrates the app confinement\n" +
61 "You should see a permission denied error next\n" +
62 "/apps/hello-world.canonical/.*/bin/evil: \\d+: " +
63 "/apps/hello-world.canonical/.*/bin/evil: " +
64 "cannot create /var/tmp/myevil.txt: Permission denied\n"
65
66 c.Assert(string(echoOutput), check.Matches, expected)
67}
68
32var _ = check.Suite(&webserverExampleSuite{})69var _ = check.Suite(&webserverExampleSuite{})
3370
34type webserverExampleSuite struct {71type webserverExampleSuite struct {
3572
=== modified file '_integration-tests/tests/info_test.go'
--- _integration-tests/tests/info_test.go 2015-10-08 06:40:06 +0000
+++ _integration-tests/tests/info_test.go 2015-10-13 15:56:19 +0000
@@ -26,6 +26,7 @@
26 "launchpad.net/snappy/_integration-tests/testutils/build"26 "launchpad.net/snappy/_integration-tests/testutils/build"
27 "launchpad.net/snappy/_integration-tests/testutils/cli"27 "launchpad.net/snappy/_integration-tests/testutils/cli"
28 "launchpad.net/snappy/_integration-tests/testutils/common"28 "launchpad.net/snappy/_integration-tests/testutils/common"
29 "launchpad.net/snappy/_integration-tests/testutils/data"
2930
30 "gopkg.in/check.v1"31 "gopkg.in/check.v1"
31)32)
@@ -55,17 +56,17 @@
55}56}
5657
57func (s *infoSuite) TestInfoMustPrintInstalledApps(c *check.C) {58func (s *infoSuite) TestInfoMustPrintInstalledApps(c *check.C) {
58 snapPath, err := build.LocalSnap(c, build.BasicSnapName)59 snapPath, err := build.LocalSnap(c, data.BasicSnapName)
59 defer os.Remove(snapPath)60 defer os.Remove(snapPath)
60 c.Assert(err, check.IsNil)61 c.Assert(err, check.IsNil)
61 common.InstallSnap(c, snapPath)62 common.InstallSnap(c, snapPath)
62 defer common.RemoveSnap(c, build.BasicSnapName)63 defer common.RemoveSnap(c, data.BasicSnapName)
6364
64 infoOutput := cli.ExecCommand(c, "snappy", "info")65 infoOutput := cli.ExecCommand(c, "snappy", "info")
6566
66 expected := "(?ms)" +67 expected := "(?ms)" +
67 ".*" +68 ".*" +
68 "^apps: .*" + build.BasicSnapName + "\\.sideload.*\n"69 "^apps: .*" + data.BasicSnapName + "\\.sideload.*\n"
69 c.Assert(infoOutput, check.Matches, expected)70 c.Assert(infoOutput, check.Matches, expected)
70}71}
7172
7273
=== modified file '_integration-tests/tests/installApp_test.go'
--- _integration-tests/tests/installApp_test.go 2015-10-08 06:45:29 +0000
+++ _integration-tests/tests/installApp_test.go 2015-10-13 15:56:19 +0000
@@ -20,10 +20,13 @@
20package tests20package tests
2121
22import (22import (
23 "os"
23 "os/exec"24 "os/exec"
2425
26 "launchpad.net/snappy/_integration-tests/testutils/build"
25 "launchpad.net/snappy/_integration-tests/testutils/cli"27 "launchpad.net/snappy/_integration-tests/testutils/cli"
26 "launchpad.net/snappy/_integration-tests/testutils/common"28 "launchpad.net/snappy/_integration-tests/testutils/common"
29 "launchpad.net/snappy/_integration-tests/testutils/data"
2730
28 "gopkg.in/check.v1"31 "gopkg.in/check.v1"
29)32)
@@ -50,36 +53,26 @@
50 c.Assert(installOutput, check.Matches, expected)53 c.Assert(installOutput, check.Matches, expected)
51}54}
5255
53func (s *installAppSuite) TestCallBinaryFromInstalledSnap(c *check.C) {56func (s *installAppSuite) TestCallSuccessfulBinaryFromInstalledSnap(c *check.C) {
54 common.InstallSnap(c, "hello-world")57 snapPath, err := build.LocalSnap(c, data.BasicBinariesSnapName)
55 s.AddCleanup(func() {58 defer os.Remove(snapPath)
56 common.RemoveSnap(c, "hello-world")59 c.Assert(err, check.IsNil)
57 })60 common.InstallSnap(c, snapPath)
5861 defer common.RemoveSnap(c, data.BasicBinariesSnapName)
59 echoOutput := cli.ExecCommand(c, "hello-world.echo")62
6063 // Exec command does not fail.
61 c.Assert(echoOutput, check.Equals, "Hello World!\n")64 cli.ExecCommand(c, "basic-binaries.success")
62}65}
6366
64func (s *installAppSuite) TestCallBinaryWithPermissionDeniedMustPrintError(c *check.C) {67func (s *installAppSuite) TestCallFailBinaryFromInstalledSnap(c *check.C) {
65 common.InstallSnap(c, "hello-world")68 snapPath, err := build.LocalSnap(c, data.BasicBinariesSnapName)
66 s.AddCleanup(func() {69 defer os.Remove(snapPath)
67 common.RemoveSnap(c, "hello-world")70 c.Assert(err, check.IsNil)
68 })71 common.InstallSnap(c, snapPath)
6972 defer common.RemoveSnap(c, data.BasicBinariesSnapName)
70 cmd := exec.Command("hello-world.evil")73
71 echoOutput, err := cmd.CombinedOutput()74 _, err = cli.ExecCommandErr("basic-binaries.fail")
72 c.Assert(err, check.NotNil, check.Commentf("hello-world.evil did not fail"))75 c.Assert(err, check.NotNil, check.Commentf("The binary did not fail"))
73
74 expected := "" +
75 "Hello Evil World!\n" +
76 "This example demonstrates the app confinement\n" +
77 "You should see a permission denied error next\n" +
78 "/apps/hello-world.canonical/.*/bin/evil: \\d+: " +
79 "/apps/hello-world.canonical/.*/bin/evil: " +
80 "cannot create /var/tmp/myevil.txt: Permission denied\n"
81
82 c.Assert(string(echoOutput), check.Matches, expected)
83}76}
8477
85func (s *installAppSuite) TestInstallUnexistingAppMustPrintError(c *check.C) {78func (s *installAppSuite) TestInstallUnexistingAppMustPrintError(c *check.C) {
8679
=== modified file '_integration-tests/tests/snapd_1_0_packages_test.go'
--- _integration-tests/tests/snapd_1_0_packages_test.go 2015-10-08 08:55:17 +0000
+++ _integration-tests/tests/snapd_1_0_packages_test.go 2015-10-13 15:56:19 +0000
@@ -24,6 +24,7 @@
2424
25 "launchpad.net/snappy/_integration-tests/testutils/build"25 "launchpad.net/snappy/_integration-tests/testutils/build"
26 "launchpad.net/snappy/_integration-tests/testutils/common"26 "launchpad.net/snappy/_integration-tests/testutils/common"
27 "launchpad.net/snappy/_integration-tests/testutils/data"
2728
28 "gopkg.in/check.v1"29 "gopkg.in/check.v1"
29)30)
@@ -64,14 +65,14 @@
64func (s *snapd10PackagesTestSuite) SetUpTest(c *check.C) {65func (s *snapd10PackagesTestSuite) SetUpTest(c *check.C) {
65 s.snapdTestSuite.SetUpTest(c)66 s.snapdTestSuite.SetUpTest(c)
66 var err error67 var err error
67 s.snapPath, err = build.LocalSnap(c, build.BasicSnapName)68 s.snapPath, err = build.LocalSnap(c, data.BasicSnapName)
68 c.Assert(err, check.IsNil)69 c.Assert(err, check.IsNil)
69}70}
7071
71func (s *snapd10PackagesTestSuite) TearDownTest(c *check.C) {72func (s *snapd10PackagesTestSuite) TearDownTest(c *check.C) {
72 s.snapdTestSuite.TearDownTest(c)73 s.snapdTestSuite.TearDownTest(c)
73 os.Remove(s.snapPath)74 os.Remove(s.snapPath)
74 common.RemoveSnap(c, build.BasicSnapName)75 common.RemoveSnap(c, data.BasicSnapName)
75}76}
7677
77func (s *snapd10PackagesTestSuite) resource() string {78func (s *snapd10PackagesTestSuite) resource() string {
@@ -92,7 +93,7 @@
92 payload: s.snapPath,93 payload: s.snapPath,
93 waitPattern: `(?U){.*,"status":"active".*"status":"OK","status_code":200,"type":"sync"}`,94 waitPattern: `(?U){.*,"status":"active".*"status":"OK","status_code":200,"type":"sync"}`,
94 waitFunction: func() (string, error) {95 waitFunction: func() (string, error) {
95 output, err := genericRequest(s.resource()+"/"+build.BasicSnapName+".sideload", "GET", nil)96 output, err := genericRequest(s.resource()+"/"+data.BasicSnapName+".sideload", "GET", nil)
96 return string(output), err97 return string(output), err
97 }}}98 }}}
98}99}
99100
=== modified file '_integration-tests/testutils/build/snap.go'
--- _integration-tests/testutils/build/snap.go 2015-09-30 11:06:40 +0000
+++ _integration-tests/testutils/build/snap.go 2015-10-13 15:56:19 +0000
@@ -25,20 +25,10 @@
2525
26 "gopkg.in/check.v1"26 "gopkg.in/check.v1"
27 "launchpad.net/snappy/_integration-tests/testutils/cli"27 "launchpad.net/snappy/_integration-tests/testutils/cli"
28)28 "launchpad.net/snappy/_integration-tests/testutils/data"
2929)
30const (30
31 // BaseSnapPath is the path for the snap sources used in testing31const snapFilenameSufix = "_1.0_all.snap"
32 BaseSnapPath = "_integration-tests/data/snaps"
33 // BasicSnapName is the name of the basic snap
34 BasicSnapName = "basic"
35 // WrongYamlSnapName is the name of a snap with an invalid meta yaml
36 WrongYamlSnapName = "wrong-yaml"
37 // MissingReadmeSnapName is the name of a snap without readme
38 MissingReadmeSnapName = "missing-readme"
39
40 snapFilenameSufix = "_1.0_all.snap"
41)
4232
43var (33var (
44 // dependency aliasing34 // dependency aliasing
@@ -67,5 +57,5 @@
67}57}
6858
69func buildPath(snap string) string {59func buildPath(snap string) string {
70 return filepath.Join(BaseSnapPath, snap)60 return filepath.Join(data.BaseSnapPath, snap)
71}61}
7262
=== added directory '_integration-tests/testutils/data'
=== added file '_integration-tests/testutils/data/data.go'
--- _integration-tests/testutils/data/data.go 1970-01-01 00:00:00 +0000
+++ _integration-tests/testutils/data/data.go 2015-10-13 15:56:19 +0000
@@ -0,0 +1,33 @@
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 data
21
22const (
23 // BaseSnapPath is the path for the snap sources used in testing
24 BaseSnapPath = "_integration-tests/data/snaps"
25 // BasicSnapName is the name of the basic snap
26 BasicSnapName = "basic"
27 // BasicBinariesSnapName is the name of the basic snap with binaries
28 BasicBinariesSnapName = "basic-binaries"
29 // WrongYamlSnapName is the name of a snap with an invalid meta yaml
30 WrongYamlSnapName = "wrong-yaml"
31 // MissingReadmeSnapName is the name of a snap without readme
32 MissingReadmeSnapName = "missing-readme"
33)

Subscribers

People subscribed via source and target branches