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

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 754
Merged at revision: 756
Proposed branch: lp:~elopio/snappy/examples1
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~elopio/snappy/service_tests
Diff against target: 197 lines (+81/-52)
4 files modified
_integration-tests/tests/examples_test.go (+72/-0)
_integration-tests/tests/info_test.go (+9/-5)
_integration-tests/tests/installApp_test.go (+0/-31)
_integration-tests/tests/installFramework_test.go (+0/-16)
To merge this branch: bzr merge lp:~elopio/snappy/examples1
Reviewer Review Type Date Requested Status
Federico Gimenez (community) Approve
Review via email: mp+273787@code.launchpad.net

Commit message

Added a suite for testing the examples.

Description of the change

This branch is a request for comments. What I want to do is move as many tests that use examples to the examples_test.go. And use local snaps for the other tests. For example, in order to test that the info command works, we don't need to install anything from the store. This will better split the fast and slow tests, the errors due to the store or the examples will be in a single suite, and the data dir will contain just the things needed for most of the tests, no more and no less.

To post a comment you must log in.
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

On Thu, Oct 8, 2015 at 3:56 AM, Leo Arias <email address hidden> wrote:

> The proposal to merge lp:~elopio/snappy/examples1 into lp:snappy has been
> updated.
>
> Description changed to:
>
> This branch is a request for comments. What I want to do is move as many
> tests that use examples to the examples_test.go. And use local snaps for
> the other tests. For example, in order to test that the info command works,
> we don't need to install anything from the store. This will better split
> the fast and slow tests, the errors due to the store or the examples will
> be in a single suite, and the data dir will contain just the things needed
> for most of the tests, no more and no less.
>

The only gotcha is sideloading attributes, signed by store snaps are not
sideloaded ones while unsinged ones are.

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

We'll test things from the store too. First, as a side-effect of the examples suite, but we also need a store suite, to test things that are different when things come from the store.

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

LGTM, thanks :)

review: Approve
Revision history for this message
Snappy Tarmac (snappydevtarmac) wrote :

The attempt to merge lp:~elopio/snappy/examples1 into lp:snappy failed. Below is the output from the failed tests.

Checking docs
Checking formatting
Formatting wrong in following files
_integration-tests/tests/examples_test.go

Crushing failure and despair.

# we always run in a fresh dir in tarmac
export GOPATH=$(mktemp -d)
trap 'rm -rf "$GOPATH"' EXIT

# this is a hack, but not sure tarmac is golang friendly
mkdir -p $GOPATH/src/launchpad.net/snappy
cp -a . $GOPATH/src/launchpad.net/snappy/
cd $GOPATH/src/launchpad.net/snappy

sh -v ./run-checks
#!/bin/sh

set -eu

if which goctest >/dev/null; then
    goctest="goctest"
else
    goctest="go test"
fi

QUICK=""
if [ "${1:-}" = "--quick" ]; then
    QUICK=yes
fi

endmsg() {
    if [ $? -eq 0 ]; then
        p="success.txt"
        m="All good, what could possibly go wrong."
    else
        p="failure.txt"
        m="Crushing failure and despair."
    fi
    echo
    if [ -t 1 -a -z "$QUICK" ]; then
        cat "data/$p"
    else
        echo "$m"
    fi
}
trap endmsg EXIT

echo Checking docs
./mdlint.py docs/*.md

echo Checking formatting
fmt=$(gofmt -l .)

if [ -n "$fmt" ]; then
    echo "Formatting wrong in following files"
    echo "$fmt"
    exit 1
fi

lp:~elopio/snappy/examples1 updated
754. By Leo Arias

Fixed fmt.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '_integration-tests/tests/examples_test.go'
2--- _integration-tests/tests/examples_test.go 1970-01-01 00:00:00 +0000
3+++ _integration-tests/tests/examples_test.go 2015-10-09 16:18:31 +0000
4@@ -0,0 +1,72 @@
5+// -*- Mode: Go; indent-tabs-mode: t -*-
6+
7+/*
8+ * Copyright (C) 2015 Canonical Ltd
9+ *
10+ * This program is free software: you can redistribute it and/or modify
11+ * it under the terms of the GNU General Public License version 3 as
12+ * published by the Free Software Foundation.
13+ *
14+ * This program is distributed in the hope that it will be useful,
15+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+ * GNU General Public License for more details.
18+ *
19+ * You should have received a copy of the GNU General Public License
20+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21+ *
22+ */
23+
24+package tests
25+
26+import (
27+ "net/http"
28+
29+ "launchpad.net/snappy/_integration-tests/testutils/cli"
30+ "launchpad.net/snappy/_integration-tests/testutils/common"
31+ "launchpad.net/snappy/_integration-tests/testutils/wait"
32+
33+ "gopkg.in/check.v1"
34+)
35+
36+var _ = check.Suite(&webserverExampleSuite{})
37+
38+type webserverExampleSuite struct {
39+ common.SnappySuite
40+}
41+
42+func (s *webserverExampleSuite) TestNetworkingServiceMustBeStarted(c *check.C) {
43+ baseAppName := "xkcd-webserver"
44+ appName := baseAppName + ".canonical"
45+ common.InstallSnap(c, appName)
46+ defer common.RemoveSnap(c, appName)
47+
48+ err := wait.ForServerOnPort(c, 80)
49+ c.Assert(err, check.IsNil)
50+
51+ resp, err := http.Get("http://localhost")
52+ c.Assert(err, check.IsNil)
53+ c.Check(resp.Status, check.Equals, "200 OK")
54+ c.Assert(resp.Proto, check.Equals, "HTTP/1.0")
55+}
56+
57+var _ = check.Suite(&frameworkExampleSuite{})
58+
59+type frameworkExampleSuite struct {
60+ common.SnappySuite
61+}
62+
63+func (s *frameworkExampleSuite) TestFrameworkClient(c *check.C) {
64+ common.InstallSnap(c, "hello-dbus-fwk.canonical")
65+ defer common.RemoveSnap(c, "hello-dbus-fwk.canonical")
66+
67+ common.InstallSnap(c, "hello-dbus-app.canonical")
68+ defer common.RemoveSnap(c, "hello-dbus-app.canonical")
69+
70+ output := cli.ExecCommand(c, "hello-dbus-app.client")
71+
72+ expected := "PASS\n"
73+
74+ c.Assert(output, check.Equals, expected,
75+ check.Commentf("Expected output %s not found, %s", expected, output))
76+}
77
78=== modified file '_integration-tests/tests/info_test.go'
79--- _integration-tests/tests/info_test.go 2015-09-30 11:27:49 +0000
80+++ _integration-tests/tests/info_test.go 2015-10-09 16:18:31 +0000
81@@ -21,7 +21,9 @@
82
83 import (
84 "fmt"
85+ "os"
86
87+ "launchpad.net/snappy/_integration-tests/testutils/build"
88 "launchpad.net/snappy/_integration-tests/testutils/cli"
89 "launchpad.net/snappy/_integration-tests/testutils/common"
90
91@@ -53,15 +55,17 @@
92 }
93
94 func (s *infoSuite) TestInfoMustPrintInstalledApps(c *check.C) {
95- common.InstallSnap(c, "hello-world")
96- s.AddCleanup(func() {
97- common.RemoveSnap(c, "hello-world")
98- })
99+ snapPath, err := build.LocalSnap(c, build.BasicSnapName)
100+ defer os.Remove(snapPath)
101+ c.Assert(err, check.IsNil)
102+ common.InstallSnap(c, snapPath)
103+ defer common.RemoveSnap(c, build.BasicSnapName)
104+
105 infoOutput := cli.ExecCommand(c, "snappy", "info")
106
107 expected := "(?ms)" +
108 ".*" +
109- "^apps: .*hello-world.*\n"
110+ "^apps: .*" + build.BasicSnapName + "\\.sideload.*\n"
111 c.Assert(infoOutput, check.Matches, expected)
112 }
113
114
115=== modified file '_integration-tests/tests/installApp_test.go'
116--- _integration-tests/tests/installApp_test.go 2015-09-30 11:27:49 +0000
117+++ _integration-tests/tests/installApp_test.go 2015-10-09 16:18:31 +0000
118@@ -20,12 +20,10 @@
119 package tests
120
121 import (
122- "net/http"
123 "os/exec"
124
125 "launchpad.net/snappy/_integration-tests/testutils/cli"
126 "launchpad.net/snappy/_integration-tests/testutils/common"
127- "launchpad.net/snappy/_integration-tests/testutils/wait"
128
129 "gopkg.in/check.v1"
130 )
131@@ -84,35 +82,6 @@
132 c.Assert(string(echoOutput), check.Matches, expected)
133 }
134
135-func (s *installAppSuite) TestInfoMustPrintInstalledPackageInformation(c *check.C) {
136- common.InstallSnap(c, "hello-world")
137- s.AddCleanup(func() {
138- common.RemoveSnap(c, "hello-world")
139- })
140-
141- infoOutput := cli.ExecCommand(c, "snappy", "info")
142-
143- expected := "(?ms).*^apps: hello-world.canonical\n"
144- c.Assert(infoOutput, check.Matches, expected)
145-}
146-
147-func (s *installAppSuite) TestAppNetworkingServiceMustBeStarted(c *check.C) {
148- baseAppName := "xkcd-webserver"
149- appName := baseAppName + ".canonical"
150- common.InstallSnap(c, appName)
151- s.AddCleanup(func() {
152- common.RemoveSnap(c, appName)
153- })
154-
155- err := wait.ForServerOnPort(c, 80)
156- c.Assert(err, check.IsNil)
157-
158- resp, err := http.Get("http://localhost")
159- c.Assert(err, check.IsNil)
160- c.Check(resp.Status, check.Equals, "200 OK")
161- c.Assert(resp.Proto, check.Equals, "HTTP/1.0")
162-}
163-
164 func (s *installAppSuite) TestInstallUnexistingAppMustPrintError(c *check.C) {
165 cmd := exec.Command("sudo", "snappy", "install", "unexisting.canonical")
166 output, err := cmd.CombinedOutput()
167
168=== modified file '_integration-tests/tests/installFramework_test.go'
169--- _integration-tests/tests/installFramework_test.go 2015-10-08 05:47:08 +0000
170+++ _integration-tests/tests/installFramework_test.go 2015-10-09 16:18:31 +0000
171@@ -20,7 +20,6 @@
172 package tests
173
174 import (
175- "launchpad.net/snappy/_integration-tests/testutils/cli"
176 "launchpad.net/snappy/_integration-tests/testutils/common"
177
178 "gopkg.in/check.v1"
179@@ -45,18 +44,3 @@
180
181 c.Assert(installOutput, check.Matches, expected)
182 }
183-
184-func (s *installFrameworkSuite) TestFrameworkClient(c *check.C) {
185- common.InstallSnap(c, "hello-dbus-fwk.canonical")
186- defer common.RemoveSnap(c, "hello-dbus-fwk.canonical")
187-
188- common.InstallSnap(c, "hello-dbus-app.canonical")
189- defer common.RemoveSnap(c, "hello-dbus-app.canonical")
190-
191- output := cli.ExecCommand(c, "hello-dbus-app.client")
192-
193- expected := "PASS\n"
194-
195- c.Assert(output, check.Equals, expected,
196- check.Commentf("Expected output %s not found, %s", expected, output))
197-}

Subscribers

People subscribed via source and target branches