Merge lp:~fgimenez/snappy/go-functional-tests into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Federico Gimenez
Status: Merged
Approved by: Leo Arias
Approved revision: 521
Merged at revision: 521
Proposed branch: lp:~fgimenez/snappy/go-functional-tests
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 412 lines (+217/-85)
10 files modified
_integration-tests/README (+7/-0)
_integration-tests/main.go (+113/-0)
_integration-tests/snappy-selftest (+7/-6)
_integration-tests/tests/10_test_info_has_stuff (+0/-1)
_integration-tests/tests/snappy_test.go (+83/-0)
debian/integration-tests/control (+6/-0)
integration-tests/run-in-image/debian/tests/control (+0/-2)
integration-tests/run-in-image/tests/04_test_install_hello (+0/-7)
integration-tests/selftest (+0/-68)
run-checks (+1/-1)
To merge this branch: bzr merge lp:~fgimenez/snappy/go-functional-tests
Reviewer Review Type Date Requested Status
Leo Arias (community) Approve
John Lenton (community) Approve
Michael Vogt Pending
Review via email: mp+261748@code.launchpad.net

Commit message

Wrapper for go-based dep8 tests and first functional test.

Description of the change

Wrapper for go-based dep8 tests and first functional test

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

@Sergio thanks a lot for your review!

Ok, now it doesn't check the install output, just the error. You mentioned checking an error output, how could this be done?

Now it's still checking the output from the binary, maybe this can be removed for the same reason, as we are checking for the error response here too?

Cheers!

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

> Ok, now it doesn't check the install output, just the error. You mentioned
> checking an error output, how could this be done?

I think what Sergio meant was that we should use a non-fatal assertion, so the tests continues even if the output of the install command is not what we expect. We can do this by just changing c.Assert by c.Check. I'll propose this in a new branch to be merged with yours.

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

After thinking it twice, instead of using a non-fatal assertion, I prefer to split the test in two. I'm testing the branch.

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

Leaving my approval here for the record. Somebody else should +1. Adding mvo as reviewer, because he did the original selftest. We also might need a +1 from an ubuntu core dev; luckily we have plenty on the team :)

review: Approve
Revision history for this message
John Lenton (chipaca) wrote :

several nits / stylistic questions. Only thing really needing fixing is the quoting of MYDIR.

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

@Chipaca thanks :) it should be fixed now, i've taken the opportunity to quote other occurrence of $MYDIR in the shell script.

Cheers!

Revision history for this message
John Lenton (chipaca) :
review: Approve
Revision history for this message
Leo Arias (elopio) wrote :

All good, what could possibly go wrong

:D

review: Approve
Revision history for this message
Snappy Tarmac (snappydevtarmac) wrote :
Download full text (5.5 KiB)

The attempt to merge lp:~fgimenez/snappy/go-functional-tests into lp:snappy failed. Below is the output from the failed tests.

Checking docs
Checking formatting
Installing godeps
Install golint
Obtaining dependencies
update code.google.com/p/go.crypto failed; trying to fetch newer version
update github.com/blakesmith/ar failed; trying to fetch newer version
code.google.com/p/go.crypto now at 69e2a90ed92d03812364aeb947b7068dc42e561e
update github.com/cheggaaa/pb failed; trying to fetch newer version
github.com/blakesmith/ar now at c9a977dd0cc1392b023382c7bfa5a22af8d3b730
update github.com/jessevdk/go-flags failed; trying to fetch newer version
github.com/cheggaaa/pb now at e8c7cc515bfde3e267957a3b110080ceed51354e
update github.com/mvo5/goconfigparser failed; trying to fetch newer version
github.com/jessevdk/go-flags now at 15347ef417a300349807983f15af9e65cd2e1b3a
update gopkg.in/check.v1 failed; trying to fetch newer version
github.com/mvo5/goconfigparser now at 26426272dda20cc76aa1fa44286dc743d2972fe8
update gopkg.in/yaml.v2 failed; trying to fetch newer version
gopkg.in/check.v1 now at 64131543e7896d5bcc6bd5a76287eb75ea96c673
gopkg.in/yaml.v2 now at 49c95bdc21843256fb6c4e0d370a05f24a0bf213
Building
Running tests from /home/tarmac/tmp/tmp.Jzd2H0EvYX/src/launchpad.net/snappy
=== RUN Test
OK: 16 passed
--- PASS: Test (0.39 seconds)
PASS
coverage: 74.3% of statements
ok launchpad.net/snappy/clickdeb 0.398s coverage: 74.3% of statements
=== RUN Test
OK: 6 passed
--- PASS: Test (0.01 seconds)
PASS
coverage: 12.9% of statements
ok launchpad.net/snappy/cmd/snappy 0.030s coverage: 12.9% of statements
=== RUN Test
OK: 24 passed
--- PASS: Test (0.10 seconds)
PASS
coverage: 100.0% of statements
ok launchpad.net/snappy/coreconfig 0.103s coverage: 100.0% of statements
=== RUN Test
OK: 50 passed
--- PASS: Test (0.49 seconds)
PASS
coverage: 80.9% of statements
ok launchpad.net/snappy/helpers 0.497s coverage: 80.9% of statements
=== RUN Test
OK: 6 passed
--- PASS: Test (0.00 seconds)
PASS
coverage: 93.5% of statements
ok launchpad.net/snappy/logger 0.005s coverage: 93.5% of statements
=== RUN Test
OK: 4 passed
--- PASS: Test (0.00 seconds)
PASS
coverage: 100.0% of statements
ok launchpad.net/snappy/oauth 0.005s coverage: 100.0% of statements
=== RUN Test
OK: 36 passed
--- PASS: Test (0.19 seconds)
PASS
coverage: 81.5% of statements
ok launchpad.net/snappy/partition 0.193s coverage: 81.5% of statements
=== RUN Test
OK: 3 passed
--- PASS: Test (0.00 seconds)
PASS
coverage: 100.0% of statements
ok launchpad.net/snappy/pkg 0.004s coverage: 100.0% of statements
=== RUN Test
OK: 12 passed
--- PASS: Test (0.11 seconds)
PASS
coverage: 94.3% of statements
ok launchpad.net/snappy/policy 0.110s coverage: 94.3% of statements
=== RUN Test
OK: 5 passed
--- PASS: Test (0.20 seconds)
PASS
coverage: 91.1% of statements
ok launchpad.net/snappy/priv 0.207s coverage: 91.1% of statements
=== RUN Test
OK: 4 passed
--- PASS: Test (0.00 seconds)
PASS
coverage: 50.0% of statements
ok launchpad.net/snappy/progress 0.017s coverage: 50.0% of statements
=== RUN Test
OK: 9 passed
--- PASS: Test (0.01 seconds)
PASS
coverage: 96.4% of statements
ok launchpad.net/sn...

Read more...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed directory 'integration-tests' => '_integration-tests'
2=== renamed file 'integration-tests/run-in-image/README' => '_integration-tests/README'
3--- integration-tests/run-in-image/README 2015-05-22 12:44:41 +0000
4+++ _integration-tests/README 2015-06-25 16:10:43 +0000
5@@ -14,3 +14,10 @@
6
7 $ adt-run $(pwd)/ --- ssh --reboot -l ubuntu -P ubuntu --reboot -H webdm.local
8
9+## Native Go tests
10+
11+Having golang installed, you can execute the full suite (including both go and
12+shell tests) with:
13+
14+$ go run _integration-test/main.go
15+
16
17=== added file '_integration-tests/main.go'
18--- _integration-tests/main.go 1970-01-01 00:00:00 +0000
19+++ _integration-tests/main.go 2015-06-25 16:10:43 +0000
20@@ -0,0 +1,113 @@
21+// -*- Mode: Go; indent-tabs-mode: t -*-
22+
23+/*
24+ * Copyright (C) 2015 Canonical Ltd
25+ *
26+ * This program is free software: you can redistribute it and/or modify
27+ * it under the terms of the GNU General Public License version 3 as
28+ * published by the Free Software Foundation.
29+ *
30+ * This program is distributed in the hope that it will be useful,
31+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
32+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33+ * GNU General Public License for more details.
34+ *
35+ * You should have received a copy of the GNU General Public License
36+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
37+ *
38+ */
39+
40+package main
41+
42+import (
43+ "fmt"
44+ "log"
45+ "os"
46+ "os/exec"
47+ "path/filepath"
48+)
49+
50+const (
51+ baseDir = "/tmp/snappy-test"
52+ debsTestBedPath = "/tmp/snappy-debs"
53+ defaultRelease = "rolling"
54+ defaultChannel = "edge"
55+)
56+
57+var (
58+ debsDir = filepath.Join(baseDir, "debs")
59+ testsDir = filepath.Join(baseDir, "tests")
60+ imageDir = filepath.Join(baseDir, "image")
61+ outputDir = filepath.Join(baseDir, "output")
62+ imageTarget = filepath.Join(imageDir, "snappy.img")
63+ testFile = filepath.Join(testsDir, "snappy.tests")
64+)
65+
66+func execCommand(cmds ...string) {
67+ cmd := exec.Command(cmds[0], cmds[1:]...)
68+ cmd.Stdout = os.Stdout
69+ cmd.Stderr = os.Stderr
70+ if err := cmd.Run(); err != nil {
71+ log.Fatalf("Error while running %s: %s\n", cmd.Args, err)
72+ }
73+}
74+
75+func buildTests() {
76+ fmt.Println("Building tests")
77+ prepareTargetDir(testsDir)
78+ execCommand("go", "test", "-c", "./_integration-tests/tests")
79+ execCommand("mv", "tests.test", testFile)
80+}
81+
82+func createImage(release, channel string) {
83+ fmt.Println("Creating image...")
84+ prepareTargetDir(imageDir)
85+ execCommand(
86+ "sudo", "ubuntu-device-flash", "--verbose",
87+ "core", release,
88+ "-o", imageTarget,
89+ "--channel", channel,
90+ "--developer-mode")
91+}
92+
93+func adtRun(rootPath string) {
94+ fmt.Println("Calling adt-run...")
95+ prepareTargetDir(outputDir)
96+ execCommand(
97+ "adt-run",
98+ "-B",
99+ "--setup-commands", "touch /run/autopkgtest_no_reboot.stamp",
100+ "--override-control", "debian/integration-tests/control",
101+ "--built-tree", rootPath,
102+ "--output-dir", outputDir,
103+ fmt.Sprintf("--copy=%s:%s", testsDir, testsDir),
104+ "---",
105+ "ssh", "-s", "/usr/share/autopkgtest/ssh-setup/snappy",
106+ "--", "-i", imageTarget)
107+}
108+
109+func prepareTargetDir(targetDir string) {
110+ if _, err := os.Stat(targetDir); err == nil {
111+ // dir exists, remove it
112+ os.RemoveAll(targetDir)
113+ }
114+ os.MkdirAll(targetDir, 0777)
115+}
116+
117+func getRootPath() string {
118+ dir, err := os.Getwd()
119+ if err != nil {
120+ log.Fatal(err)
121+ }
122+ return dir
123+}
124+
125+func main() {
126+ rootPath := getRootPath()
127+
128+ buildTests()
129+
130+ createImage(defaultRelease, defaultChannel)
131+
132+ adtRun(rootPath)
133+}
134
135=== renamed file 'integration-tests/run-in-image/snappy-selftest' => '_integration-tests/snappy-selftest'
136--- integration-tests/run-in-image/snappy-selftest 2015-05-22 12:44:41 +0000
137+++ _integration-tests/snappy-selftest 2015-06-25 16:10:43 +0000
138@@ -2,12 +2,12 @@
139
140 set -e
141
142-. tests/framework
143+MYDIR=$(dirname $0)
144+
145+. "$MYDIR"/tests/framework
146
147 SNAPPY=snappy
148
149-MYDIR=$(dirname $0)
150-
151 if [ "$1" != "--yes-really" ]; then
152 echo "The selftest may be destructive, please run with:"
153 echo " --yes-really"
154@@ -15,18 +15,19 @@
155 exit 1
156 fi
157
158-. tests/settings
159+. "$MYDIR"/tests/settings
160
161-. tests/common.sh
162+. "$MYDIR"/tests/common.sh
163
164 # prepare the environment
165 if [ -z "$ADT_REBOOT_MARK" ]; then
166+ sudo systemctl stop snappy-autopilot.timer
167 sudo snappy remove "$framework" 2>&1 || true
168 sudo snappy remove hello-world 2>&1 || true
169 sudo snappy remove xkcd-webserver 2>&1 || true
170 fi
171
172-for test in $MYDIR/tests/*_test_*[!~#]; do
173+for test in "$MYDIR"/tests/*_test_*[!~#]; do
174 CURRENT_TEST=$(basename $test)
175
176 # after a reboot, skip ahead to the test that triggered it
177
178=== added directory '_integration-tests/tests'
179=== renamed file 'integration-tests/run-in-image/tests/01_test_info' => '_integration-tests/tests/01_test_info'
180=== renamed file 'integration-tests/run-in-image/tests/02_test_versions' => '_integration-tests/tests/02_test_versions'
181=== renamed file 'integration-tests/run-in-image/tests/03_test_apt' => '_integration-tests/tests/03_test_apt'
182=== renamed file 'integration-tests/run-in-image/tests/05_test_install_nonexistant' => '_integration-tests/tests/05_test_install_nonexistant'
183=== renamed file 'integration-tests/run-in-image/tests/06_test_search_framework' => '_integration-tests/tests/06_test_search_framework'
184=== renamed file 'integration-tests/run-in-image/tests/07_test_install_framework' => '_integration-tests/tests/07_test_install_framework'
185=== renamed file 'integration-tests/run-in-image/tests/08_test_versions_has_framework' => '_integration-tests/tests/08_test_versions_has_framework'
186=== renamed file 'integration-tests/run-in-image/tests/10_test_info_has_stuff' => '_integration-tests/tests/10_test_info_has_stuff'
187--- integration-tests/run-in-image/tests/10_test_info_has_stuff 2015-05-20 10:23:39 +0000
188+++ _integration-tests/tests/10_test_info_has_stuff 2015-06-25 16:10:43 +0000
189@@ -1,5 +1,4 @@
190 test() {
191 test_regexp "^release: ubuntu-core/.*/(edge|stable)" $SNAPPY info
192 test_regexp "^frameworks: $framework" $SNAPPY info
193- test_regexp "^apps:.*\<hello-world\>" $SNAPPY info
194 }
195
196=== renamed file 'integration-tests/run-in-image/tests/11_test_xkcd_listens' => '_integration-tests/tests/11_test_xkcd_listens'
197=== renamed file 'integration-tests/run-in-image/tests/80_test_failover' => '_integration-tests/tests/80_test_failover'
198=== renamed file 'integration-tests/run-in-image/tests/90_test_upgrade' => '_integration-tests/tests/90_test_upgrade'
199=== renamed file 'integration-tests/run-in-image/tests/91_test_upgrade_from_stable_image' => '_integration-tests/tests/91_test_upgrade_from_stable_image'
200=== renamed file 'integration-tests/run-in-image/tests/common.sh' => '_integration-tests/tests/common.sh'
201=== renamed file 'integration-tests/run-in-image/tests/framework' => '_integration-tests/tests/framework'
202=== renamed file 'integration-tests/run-in-image/tests/settings' => '_integration-tests/tests/settings'
203=== added file '_integration-tests/tests/snappy_test.go'
204--- _integration-tests/tests/snappy_test.go 1970-01-01 00:00:00 +0000
205+++ _integration-tests/tests/snappy_test.go 2015-06-25 16:10:43 +0000
206@@ -0,0 +1,83 @@
207+// -*- Mode: Go; indent-tabs-mode: t -*-
208+
209+/*
210+ * Copyright (C) 2015 Canonical Ltd
211+ *
212+ * This program is free software: you can redistribute it and/or modify
213+ * it under the terms of the GNU General Public License version 3 as
214+ * published by the Free Software Foundation.
215+ *
216+ * This program is distributed in the hope that it will be useful,
217+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
218+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
219+ * GNU General Public License for more details.
220+ *
221+ * You should have received a copy of the GNU General Public License
222+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
223+ *
224+ */
225+
226+package tests
227+
228+import (
229+ "os/exec"
230+ "testing"
231+
232+ . "gopkg.in/check.v1"
233+)
234+
235+// Hook up gocheck into the "go test" runner
236+func Test(t *testing.T) { TestingT(t) }
237+
238+var _ = Suite(&InstallSuite{})
239+
240+type InstallSuite struct{}
241+
242+func (s *InstallSuite) installSnap(c *C, packageName string) string {
243+ return s.execCommand(c, "sudo", "snappy", "install", packageName)
244+}
245+
246+func (s *InstallSuite) execCommand(c *C, cmds ...string) string {
247+ cmd := exec.Command(cmds[0], cmds[1:]...)
248+ output, err := cmd.CombinedOutput()
249+ stringOutput := string(output)
250+ c.Assert(err, IsNil, Commentf("Error: %v", stringOutput))
251+ return stringOutput
252+}
253+
254+func (s *InstallSuite) SetUpSuite(c *C) {
255+ s.execCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer")
256+}
257+
258+func (s *InstallSuite) TearDownTest(c *C) {
259+ s.execCommand(c, "sudo", "snappy", "remove", "hello-world")
260+}
261+
262+func (s *InstallSuite) TestInstallSnapMustPrintPackageInformation(c *C) {
263+ installOutput := s.installSnap(c, "hello-world")
264+
265+ expected := "" +
266+ "Installing hello-world\n" +
267+ "Name Date Version Developer \n" +
268+ ".*\n" +
269+ "hello-world .* .* canonical \n" +
270+ ".*\n"
271+ c.Assert(installOutput, Matches, expected)
272+}
273+
274+func (s *InstallSuite) TestCallBinaryFromInstalledSnap(c *C) {
275+ s.installSnap(c, "hello-world")
276+
277+ echoOutput := s.execCommand(c, "hello-world.echo")
278+
279+ c.Assert(echoOutput, Equals, "Hello World!\n")
280+}
281+
282+func (s *InstallSuite) TestInfoMustPrintInstalledPackageInformation(c *C) {
283+ s.installSnap(c, "hello-world")
284+
285+ infoOutput := s.execCommand(c, "snappy", "info")
286+
287+ expected := "(?ms).*^apps: hello-world\n"
288+ c.Assert(infoOutput, Matches, expected)
289+}
290
291=== added directory 'debian/integration-tests'
292=== added file 'debian/integration-tests/control'
293--- debian/integration-tests/control 1970-01-01 00:00:00 +0000
294+++ debian/integration-tests/control 2015-06-25 16:10:43 +0000
295@@ -0,0 +1,6 @@
296+Test-Command: /tmp/snappy-test/tests/snappy.tests -gocheck.vv -test.outputdir=$ADT_ARTIFACTS
297+Restrictions: allow-stderr
298+Depends: ubuntu-snappy-tests
299+
300+Test-Command: ./_integration-tests/snappy-selftest --yes-really
301+Depends:
302
303=== removed directory 'integration-tests/debs'
304=== removed directory 'integration-tests/image'
305=== removed directory 'integration-tests/run-in-image'
306=== removed directory 'integration-tests/run-in-image/debian'
307=== removed directory 'integration-tests/run-in-image/debian/tests'
308=== removed file 'integration-tests/run-in-image/debian/tests/control'
309--- integration-tests/run-in-image/debian/tests/control 2015-05-20 10:23:39 +0000
310+++ integration-tests/run-in-image/debian/tests/control 1970-01-01 00:00:00 +0000
311@@ -1,2 +0,0 @@
312-Test-Command: ./snappy-selftest --yes-really
313-Depends:
314
315=== removed directory 'integration-tests/run-in-image/tests'
316=== removed file 'integration-tests/run-in-image/tests/04_test_install_hello'
317--- integration-tests/run-in-image/tests/04_test_install_hello 2015-05-20 10:23:39 +0000
318+++ integration-tests/run-in-image/tests/04_test_install_hello 1970-01-01 00:00:00 +0000
319@@ -1,7 +0,0 @@
320-test() {
321- T="hello-world[[:space:]]+[0-9]{4}-[0-9]{2}-[0-9]{2}[[:space:]]+[0-9]+(\.[0-9]+)+[[:space:]]+canonical"
322- test_regexp "$T" sudo $SNAPPY install hello-world
323-
324- T="Hello World!"
325- test_equal "$T" hello-world.echo
326-}
327
328=== removed file 'integration-tests/selftest'
329--- integration-tests/selftest 2015-06-09 15:41:02 +0000
330+++ integration-tests/selftest 1970-01-01 00:00:00 +0000
331@@ -1,68 +0,0 @@
332-#!/bin/sh
333-
334-set -ex
335-
336-HERE="$(dirname $0)"
337-
338-# build the updated deb packages for the image
339-rm -f "$HERE/debs/*"
340-# the "-us -uc " flags tell it not to sign it
341-bzr-buildpackage --result-dir="$HERE/debs" "$HERE/.." -- -us -uc
342-
343-# build a base image
344-IMAGE="$HERE/image/snappy.img"
345-rm -f "$IMAGE/*"
346-# FIXME: hrm, hrm, needs sudo to work on testbed
347-#
348-# FIXME2: use wget here instead and just get the latest image from
349-# cdimage
350-sudo ubuntu-device-flash core -o "$IMAGE" rolling --channel edge --enable-ssh --developer-mode
351-
352-# base cmd
353-QEMU_CMD="qemu-system-$(uname -m) -enable-kvm -m 768 -localtime -nographic -net user -net nic,model=virtio"
354-
355-# fire it up
356-port=11022
357-SERIAL=stdio
358-$QEMU_CMD -drive file="$IMAGE",if=virtio -redir tcp:$port::22 -monitor none -serial $SERIAL &
359-QEMU_PID=$!
360-trap "kill $QEMU_PID" INT QUIT
361-
362-# wait until the image is ready
363-SSH="ssh -oStrictHostKeyChecking=no -o UserKnownHostsFile=\"$HERE/image/known_hosts\" -p $port ubuntu@localhost"
364-SCP="scp -oStrictHostKeyChecking=no -o UserKnownHostsFile=\"$HERE/image/known_hosts\" -P $port"
365-for i in $(seq 100); do
366- if $SSH true; then
367- break
368- fi
369- sleep 1
370-done
371-if [ $i = 100 ]; then
372- echo "Failed to setup qemu"
373- exit 1
374-fi
375-
376-# install debs
377-$SSH rm -rf /tmp/debs
378-$SSH mkdir /tmp/debs
379-$SCP "$HERE"/debs/*.deb ubuntu@localhost:/tmp/debs
380-$SSH sudo mount -o remount,rw /
381-$SSH sudo dpkg -i /tmp/debs/*.deb
382-
383-# shut it down
384-$SSH sudo halt --poweroff || true
385-
386-# wait for qemu pid
387-for i in $(seq 100); do
388- if [ ! -e /proc/$QEMU_PID/exe ]; then
389- break
390- fi
391- i=$((i+1))
392- sleep 1
393-done
394-
395-# now run the tests against the image
396-(cd "$HERE";
397- adt-run run-in-image/ --- ssh -s snappy -- -i image/snappy.img;
398-)
399-
400
401=== modified file 'run-checks'
402--- run-checks 2015-06-09 15:35:35 +0000
403+++ run-checks 2015-06-25 16:10:43 +0000
404@@ -58,7 +58,7 @@
405 # integration tests
406 if which adt-run >/dev/null 2>&1; then
407 echo "Running integration tests"
408- ./integration-tests/selftest
409+ go run _integration-tests/main.go
410 fi
411
412 echo "All good, what could possibly go wrong"

Subscribers

People subscribed via source and target branches