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
1=== added file '_integration-tests/data/snaps/basic-binaries/bin/fail'
2--- _integration-tests/data/snaps/basic-binaries/bin/fail 1970-01-01 00:00:00 +0000
3+++ _integration-tests/data/snaps/basic-binaries/bin/fail 2015-10-13 15:56:19 +0000
4@@ -0,0 +1,3 @@
5+#!/bin/sh
6+
7+exit 1
8
9=== added file '_integration-tests/data/snaps/basic-binaries/bin/success'
10--- _integration-tests/data/snaps/basic-binaries/bin/success 1970-01-01 00:00:00 +0000
11+++ _integration-tests/data/snaps/basic-binaries/bin/success 2015-10-13 15:56:19 +0000
12@@ -0,0 +1,3 @@
13+#!/bin/sh
14+
15+exit 0
16
17=== modified file '_integration-tests/data/snaps/basic-binaries/meta/package.yaml'
18--- _integration-tests/data/snaps/basic-binaries/meta/package.yaml 2015-10-09 07:42:40 +0000
19+++ _integration-tests/data/snaps/basic-binaries/meta/package.yaml 2015-10-13 15:56:19 +0000
20@@ -4,3 +4,5 @@
21 icon: meta/snappy64.png
22 binaries:
23 - name: bin/echo
24+ - name: bin/success
25+ - name: bin/fail
26
27=== modified file '_integration-tests/tests/activate_test.go'
28--- _integration-tests/tests/activate_test.go 2015-10-09 07:49:19 +0000
29+++ _integration-tests/tests/activate_test.go 2015-10-13 15:56:19 +0000
30@@ -27,10 +27,11 @@
31 "launchpad.net/snappy/_integration-tests/testutils/build"
32 "launchpad.net/snappy/_integration-tests/testutils/cli"
33 "launchpad.net/snappy/_integration-tests/testutils/common"
34+ "launchpad.net/snappy/_integration-tests/testutils/data"
35 )
36
37 const (
38- activateSnapName = "basic-binaries"
39+ activateSnapName = data.BasicBinariesSnapName
40 activateBinName = activateSnapName + ".echo"
41 activateEchoOutput = "From basic-binaries snap\n"
42 baseActivatePattern = "(?msU).*" + activateSnapName + `\s*.*\s*.*sideload`
43
44=== modified file '_integration-tests/tests/build_test.go'
45--- _integration-tests/tests/build_test.go 2015-09-28 10:35:06 +0000
46+++ _integration-tests/tests/build_test.go 2015-10-13 15:56:19 +0000
47@@ -26,6 +26,7 @@
48
49 "launchpad.net/snappy/_integration-tests/testutils/build"
50 "launchpad.net/snappy/_integration-tests/testutils/common"
51+ "launchpad.net/snappy/_integration-tests/testutils/data"
52
53 "gopkg.in/check.v1"
54 )
55@@ -38,37 +39,37 @@
56
57 func (s *buildSuite) TestBuildBasicSnapOnSnappy(c *check.C) {
58 // build basic snap and check output
59- snapPath, err := build.LocalSnap(c, build.BasicSnapName)
60+ snapPath, err := build.LocalSnap(c, data.BasicSnapName)
61 defer os.Remove(snapPath)
62 c.Assert(err, check.IsNil)
63
64 // install built snap and check output
65 installOutput := common.InstallSnap(c, snapPath)
66- defer common.RemoveSnap(c, build.BasicSnapName)
67+ defer common.RemoveSnap(c, data.BasicSnapName)
68 expected := "(?ms)" +
69 "Installing " + snapPath + "\n" +
70 ".*Signature check failed, but installing anyway as requested\n" +
71 "Name +Date +Version +Developer \n" +
72 ".*\n" +
73- build.BasicSnapName + " +.* +.* +sideload \n" +
74+ data.BasicSnapName + " +.* +.* +sideload \n" +
75 ".*\n"
76
77 c.Check(installOutput, check.Matches, expected)
78 }
79
80 func (s *buildSuite) TestBuildWrongYamlSnapOnSnappy(c *check.C) {
81- commonWrongTest(c, build.WrongYamlSnapName,
82+ commonWrongTest(c, data.WrongYamlSnapName,
83 "(?msi).*Can not parse.*yaml: line 2: mapping values are not allowed in this context.*")
84 }
85
86 func (s *buildSuite) TestBuildMissingReadmeSnapOnSnappy(c *check.C) {
87- commonWrongTest(c, build.MissingReadmeSnapName,
88+ commonWrongTest(c, data.MissingReadmeSnapName,
89 ".*readme.md: no such file or directory\n")
90 }
91
92 func commonWrongTest(c *check.C, testName, expected string) {
93 // build wrong snap and check error
94- cmd := exec.Command("snappy", "build", fmt.Sprintf("%s/%s", build.BaseSnapPath, testName))
95+ cmd := exec.Command("snappy", "build", fmt.Sprintf("%s/%s", data.BaseSnapPath, testName))
96 echoOutput, err := cmd.CombinedOutput()
97 c.Assert(err, check.NotNil, check.Commentf("%s should not be built", testName))
98
99
100=== modified file '_integration-tests/tests/examples_test.go'
101--- _integration-tests/tests/examples_test.go 2015-10-09 16:18:01 +0000
102+++ _integration-tests/tests/examples_test.go 2015-10-13 15:56:19 +0000
103@@ -29,6 +29,43 @@
104 "gopkg.in/check.v1"
105 )
106
107+var _ = check.Suite(&helloWorldExampleSuite{})
108+
109+type helloWorldExampleSuite struct {
110+ common.SnappySuite
111+}
112+
113+func (s *helloWorldExampleSuite) TestCallHelloWorldBinary(c *check.C) {
114+ common.InstallSnap(c, "hello-world")
115+ s.AddCleanup(func() {
116+ common.RemoveSnap(c, "hello-world")
117+ })
118+
119+ echoOutput := cli.ExecCommand(c, "hello-world.echo")
120+
121+ c.Assert(echoOutput, check.Equals, "Hello World!\n")
122+}
123+
124+func (s *helloWorldExampleSuite) TestCallHelloWorldEvilMustPrintPermissionDeniedError(c *check.C) {
125+ common.InstallSnap(c, "hello-world")
126+ s.AddCleanup(func() {
127+ common.RemoveSnap(c, "hello-world")
128+ })
129+
130+ echoOutput, err := cli.ExecCommandErr("hello-world.evil")
131+ c.Assert(err, check.NotNil, check.Commentf("hello-world.evil did not fail"))
132+
133+ expected := "" +
134+ "Hello Evil World!\n" +
135+ "This example demonstrates the app confinement\n" +
136+ "You should see a permission denied error next\n" +
137+ "/apps/hello-world.canonical/.*/bin/evil: \\d+: " +
138+ "/apps/hello-world.canonical/.*/bin/evil: " +
139+ "cannot create /var/tmp/myevil.txt: Permission denied\n"
140+
141+ c.Assert(string(echoOutput), check.Matches, expected)
142+}
143+
144 var _ = check.Suite(&webserverExampleSuite{})
145
146 type webserverExampleSuite struct {
147
148=== modified file '_integration-tests/tests/info_test.go'
149--- _integration-tests/tests/info_test.go 2015-10-08 06:40:06 +0000
150+++ _integration-tests/tests/info_test.go 2015-10-13 15:56:19 +0000
151@@ -26,6 +26,7 @@
152 "launchpad.net/snappy/_integration-tests/testutils/build"
153 "launchpad.net/snappy/_integration-tests/testutils/cli"
154 "launchpad.net/snappy/_integration-tests/testutils/common"
155+ "launchpad.net/snappy/_integration-tests/testutils/data"
156
157 "gopkg.in/check.v1"
158 )
159@@ -55,17 +56,17 @@
160 }
161
162 func (s *infoSuite) TestInfoMustPrintInstalledApps(c *check.C) {
163- snapPath, err := build.LocalSnap(c, build.BasicSnapName)
164+ snapPath, err := build.LocalSnap(c, data.BasicSnapName)
165 defer os.Remove(snapPath)
166 c.Assert(err, check.IsNil)
167 common.InstallSnap(c, snapPath)
168- defer common.RemoveSnap(c, build.BasicSnapName)
169+ defer common.RemoveSnap(c, data.BasicSnapName)
170
171 infoOutput := cli.ExecCommand(c, "snappy", "info")
172
173 expected := "(?ms)" +
174 ".*" +
175- "^apps: .*" + build.BasicSnapName + "\\.sideload.*\n"
176+ "^apps: .*" + data.BasicSnapName + "\\.sideload.*\n"
177 c.Assert(infoOutput, check.Matches, expected)
178 }
179
180
181=== modified file '_integration-tests/tests/installApp_test.go'
182--- _integration-tests/tests/installApp_test.go 2015-10-08 06:45:29 +0000
183+++ _integration-tests/tests/installApp_test.go 2015-10-13 15:56:19 +0000
184@@ -20,10 +20,13 @@
185 package tests
186
187 import (
188+ "os"
189 "os/exec"
190
191+ "launchpad.net/snappy/_integration-tests/testutils/build"
192 "launchpad.net/snappy/_integration-tests/testutils/cli"
193 "launchpad.net/snappy/_integration-tests/testutils/common"
194+ "launchpad.net/snappy/_integration-tests/testutils/data"
195
196 "gopkg.in/check.v1"
197 )
198@@ -50,36 +53,26 @@
199 c.Assert(installOutput, check.Matches, expected)
200 }
201
202-func (s *installAppSuite) TestCallBinaryFromInstalledSnap(c *check.C) {
203- common.InstallSnap(c, "hello-world")
204- s.AddCleanup(func() {
205- common.RemoveSnap(c, "hello-world")
206- })
207-
208- echoOutput := cli.ExecCommand(c, "hello-world.echo")
209-
210- c.Assert(echoOutput, check.Equals, "Hello World!\n")
211+func (s *installAppSuite) TestCallSuccessfulBinaryFromInstalledSnap(c *check.C) {
212+ snapPath, err := build.LocalSnap(c, data.BasicBinariesSnapName)
213+ defer os.Remove(snapPath)
214+ c.Assert(err, check.IsNil)
215+ common.InstallSnap(c, snapPath)
216+ defer common.RemoveSnap(c, data.BasicBinariesSnapName)
217+
218+ // Exec command does not fail.
219+ cli.ExecCommand(c, "basic-binaries.success")
220 }
221
222-func (s *installAppSuite) TestCallBinaryWithPermissionDeniedMustPrintError(c *check.C) {
223- common.InstallSnap(c, "hello-world")
224- s.AddCleanup(func() {
225- common.RemoveSnap(c, "hello-world")
226- })
227-
228- cmd := exec.Command("hello-world.evil")
229- echoOutput, err := cmd.CombinedOutput()
230- c.Assert(err, check.NotNil, check.Commentf("hello-world.evil did not fail"))
231-
232- expected := "" +
233- "Hello Evil World!\n" +
234- "This example demonstrates the app confinement\n" +
235- "You should see a permission denied error next\n" +
236- "/apps/hello-world.canonical/.*/bin/evil: \\d+: " +
237- "/apps/hello-world.canonical/.*/bin/evil: " +
238- "cannot create /var/tmp/myevil.txt: Permission denied\n"
239-
240- c.Assert(string(echoOutput), check.Matches, expected)
241+func (s *installAppSuite) TestCallFailBinaryFromInstalledSnap(c *check.C) {
242+ snapPath, err := build.LocalSnap(c, data.BasicBinariesSnapName)
243+ defer os.Remove(snapPath)
244+ c.Assert(err, check.IsNil)
245+ common.InstallSnap(c, snapPath)
246+ defer common.RemoveSnap(c, data.BasicBinariesSnapName)
247+
248+ _, err = cli.ExecCommandErr("basic-binaries.fail")
249+ c.Assert(err, check.NotNil, check.Commentf("The binary did not fail"))
250 }
251
252 func (s *installAppSuite) TestInstallUnexistingAppMustPrintError(c *check.C) {
253
254=== modified file '_integration-tests/tests/snapd_1_0_packages_test.go'
255--- _integration-tests/tests/snapd_1_0_packages_test.go 2015-10-08 08:55:17 +0000
256+++ _integration-tests/tests/snapd_1_0_packages_test.go 2015-10-13 15:56:19 +0000
257@@ -24,6 +24,7 @@
258
259 "launchpad.net/snappy/_integration-tests/testutils/build"
260 "launchpad.net/snappy/_integration-tests/testutils/common"
261+ "launchpad.net/snappy/_integration-tests/testutils/data"
262
263 "gopkg.in/check.v1"
264 )
265@@ -64,14 +65,14 @@
266 func (s *snapd10PackagesTestSuite) SetUpTest(c *check.C) {
267 s.snapdTestSuite.SetUpTest(c)
268 var err error
269- s.snapPath, err = build.LocalSnap(c, build.BasicSnapName)
270+ s.snapPath, err = build.LocalSnap(c, data.BasicSnapName)
271 c.Assert(err, check.IsNil)
272 }
273
274 func (s *snapd10PackagesTestSuite) TearDownTest(c *check.C) {
275 s.snapdTestSuite.TearDownTest(c)
276 os.Remove(s.snapPath)
277- common.RemoveSnap(c, build.BasicSnapName)
278+ common.RemoveSnap(c, data.BasicSnapName)
279 }
280
281 func (s *snapd10PackagesTestSuite) resource() string {
282@@ -92,7 +93,7 @@
283 payload: s.snapPath,
284 waitPattern: `(?U){.*,"status":"active".*"status":"OK","status_code":200,"type":"sync"}`,
285 waitFunction: func() (string, error) {
286- output, err := genericRequest(s.resource()+"/"+build.BasicSnapName+".sideload", "GET", nil)
287+ output, err := genericRequest(s.resource()+"/"+data.BasicSnapName+".sideload", "GET", nil)
288 return string(output), err
289 }}}
290 }
291
292=== modified file '_integration-tests/testutils/build/snap.go'
293--- _integration-tests/testutils/build/snap.go 2015-09-30 11:06:40 +0000
294+++ _integration-tests/testutils/build/snap.go 2015-10-13 15:56:19 +0000
295@@ -25,20 +25,10 @@
296
297 "gopkg.in/check.v1"
298 "launchpad.net/snappy/_integration-tests/testutils/cli"
299-)
300-
301-const (
302- // BaseSnapPath is the path for the snap sources used in testing
303- BaseSnapPath = "_integration-tests/data/snaps"
304- // BasicSnapName is the name of the basic snap
305- BasicSnapName = "basic"
306- // WrongYamlSnapName is the name of a snap with an invalid meta yaml
307- WrongYamlSnapName = "wrong-yaml"
308- // MissingReadmeSnapName is the name of a snap without readme
309- MissingReadmeSnapName = "missing-readme"
310-
311- snapFilenameSufix = "_1.0_all.snap"
312-)
313+ "launchpad.net/snappy/_integration-tests/testutils/data"
314+)
315+
316+const snapFilenameSufix = "_1.0_all.snap"
317
318 var (
319 // dependency aliasing
320@@ -67,5 +57,5 @@
321 }
322
323 func buildPath(snap string) string {
324- return filepath.Join(BaseSnapPath, snap)
325+ return filepath.Join(data.BaseSnapPath, snap)
326 }
327
328=== added directory '_integration-tests/testutils/data'
329=== added file '_integration-tests/testutils/data/data.go'
330--- _integration-tests/testutils/data/data.go 1970-01-01 00:00:00 +0000
331+++ _integration-tests/testutils/data/data.go 2015-10-13 15:56:19 +0000
332@@ -0,0 +1,33 @@
333+// -*- Mode: Go; indent-tabs-mode: t -*-
334+
335+/*
336+ * Copyright (C) 2015 Canonical Ltd
337+ *
338+ * This program is free software: you can redistribute it and/or modify
339+ * it under the terms of the GNU General Public License version 3 as
340+ * published by the Free Software Foundation.
341+ *
342+ * This program is distributed in the hope that it will be useful,
343+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
344+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
345+ * GNU General Public License for more details.
346+ *
347+ * You should have received a copy of the GNU General Public License
348+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
349+ *
350+ */
351+
352+package data
353+
354+const (
355+ // BaseSnapPath is the path for the snap sources used in testing
356+ BaseSnapPath = "_integration-tests/data/snaps"
357+ // BasicSnapName is the name of the basic snap
358+ BasicSnapName = "basic"
359+ // BasicBinariesSnapName is the name of the basic snap with binaries
360+ BasicBinariesSnapName = "basic-binaries"
361+ // WrongYamlSnapName is the name of a snap with an invalid meta yaml
362+ WrongYamlSnapName = "wrong-yaml"
363+ // MissingReadmeSnapName is the name of a snap without readme
364+ MissingReadmeSnapName = "missing-readme"
365+)

Subscribers

People subscribed via source and target branches