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

Proposed by Leo Arias on 2015-07-15
Status: Merged
Approved by: Leo Arias on 2015-07-16
Approved revision: 587
Merged at revision: 586
Proposed branch: lp:~elopio/snappy/test_go_info
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~elopio/snappy/test_go_xkcd
Diff against target: 184 lines (+113/-11)
4 files modified
_integration-tests/main.go (+27/-3)
_integration-tests/tests/01_test_info (+0/-4)
_integration-tests/tests/10_test_info_has_stuff (+0/-4)
_integration-tests/tests/latest/info_test.go (+86/-0)
To merge this branch: bzr merge lp:~elopio/snappy/test_go_info
Reviewer Review Type Date Requested Status
Federico Gimenez (community) 2015-07-15 Approve on 2015-07-15
Review via email: mp+264790@code.launchpad.net

Commit Message

Translated the info integration test to go.

To post a comment you must log in.
Federico Gimenez (fgimenez) wrote :

Looks very good, great idea checking the actual release and channel. I'm not sure I like the way that info is passed to the tests, do we have any alternative?

In any case, that file should be put under the _integration-tests/data/output directory IMO, and perhaps be cleaned up at the end of the execution (we should talk about reusing the AddCleanup in the files outside the tests too).

Otherwise +1

review: Needs Information
Leo Arias (elopio) wrote :

As an alternative, I thought about reading the info from channel.ini in the testbed; but then the test will be self-fulfilling because snappy reads from that file to print the info. And it would be duplicated, as we have unit tests that check the attributes of the release.

So, what I want is to make sure that we are running the tests in the image that we specified in the host. As how to pass that info from the host to the test bed, there are plenty of options. Different file formats, env vars, with the --setup-command... I just copied what we did on the sanity suite.

I'll change the file location.

Leo Arias (elopio) wrote :

Please give it another review. I'm not sure about removing the data files, as they can serve to debug an execution. And on prepare target we make sure that the dirs are wiped out before running a new test.

I think that the files will be collected as part of the artifacts, so maybe it's ok to remove them. But I don't know, lets talk about it and later we can make a branch that removes all the generated stuff.

Sergio Schvezov (sergiusens) wrote :

Just a small proposal for an alternate way to validate the output.

Federico Gimenez (fgimenez) wrote :

Great, we can take care of the generated files in [1]

Cheers!

[1] https://trello.com/c/1QOXRIqx/164-automation-remove-leftover-files

review: Approve
Sergio Schvezov (sergiusens) wrote :

A side effect of using a scanner is that you can c.Check every line for formatting (useful in snappy list where we have formatting guidelines)

Federico Gimenez (fgimenez) wrote :

@Sergio it looks very nice, thanks a lot :)

We could replace pattern matching with it in places where regex feels a little cumbersome, perhaps write a checker with this logic inside? (I feel very pro-custom-checkers today :D)

Leo Arias (elopio) wrote :

<elopio> sergiusens: I like your proposal for map + Scan, but for the format compliance tests.
<elopio> what we are doing in the integration tests is closer to pattern matching: a user will ignore big chunks of text and care only about some lines. I find regexp and .* to express that nicely.
<elopio> We have a card for the format tests, where we will want to check every single line. I'll copy your comment in there.
<elopio> what do you think?

Leo Arias (elopio) wrote :

Back to work in progress because this will now conflict with the branch that splits main.

Leo Arias (elopio) wrote :

<sergiusens> elopio: it's fine; scanning is also good to see how long a specific message takes to get on screen; but is leagues away

Federico Gimenez (fgimenez) wrote :

infoSuite is passing but I get this in one of the remaining shell tests:

****** Running ./_integration-tests/tests/08_test_versions_has_framework
Can not find 'docker[[:space:]]+[0-9]{4}-[0-9]{2}-[0-9]{2}[[:space:]]+[0-9]+\.[0-9]+' in 'Name Date Version Developer
ubuntu-core 2015-07-15 108 ubuntu
generic-amd64 2015-07-15 1.4 canonical '
ERROR
FAILED: ./_integration-tests/tests/08_test_versions_has_framework

AFAIU this will be removed in one of the branches, right?

Thanks,

Leo Arias (elopio) wrote :

Thanks for the review, and yes, removed in here:
https://code.launchpad.net/~elopio/snappy/test_go_list/+merge/264794

Should land anytime now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_integration-tests/main.go'
2--- _integration-tests/main.go 2015-07-15 14:22:11 +0000
3+++ _integration-tests/main.go 2015-07-15 15:54:02 +0000
4@@ -20,8 +20,10 @@
5 package main
6
7 import (
8+ "encoding/json"
9 "flag"
10 "fmt"
11+ "io/ioutil"
12 "log"
13 "os"
14 "path/filepath"
15@@ -40,13 +42,14 @@
16 defaultChannel = "edge"
17 defaultSSHPort = 22
18 defaultGoArm = "7"
19- tplOutputDir = "_integration-tests/data/output/"
20+ dataOutputDir = "_integration-tests/data/output/"
21 controlTpl = "_integration-tests/data/tpl/control"
22 )
23
24 var (
25 commonSSHOptions = []string{"---", "ssh"}
26- controlFile = filepath.Join(tplOutputDir, "control")
27+ configFileName = filepath.Join(dataOutputDir, "testconfig.json")
28+ controlFile = filepath.Join(dataOutputDir, "control")
29 testPackagesLatest = []string{"latest", "failover"}
30 testPackageUpdate = []string{"update"}
31 testPackages = append(testPackagesLatest, testPackageUpdate...)
32@@ -63,6 +66,20 @@
33 buildTests(arch)
34 }
35
36+func writeTestConfig(release, channel string) {
37+ fmt.Println("Writing test config...")
38+ testConfig := map[string]string{
39+ "release": release,
40+ "channel": channel,
41+ }
42+ fmt.Println(testConfig)
43+ encoded, err := json.Marshal(testConfig)
44+ if err != nil {
45+ log.Fatalf("Error encoding the test config: %v", testConfig)
46+ }
47+ ioutil.WriteFile(configFileName, encoded, 0644)
48+}
49+
50 func setupAndRunLocalTests(rootPath, testFilter string, img image.Image) {
51 var includeShell bool
52 if testFilter == "" {
53@@ -161,7 +178,6 @@
54 log.Fatalf("Error reading adt-run control template %s", controlTpl)
55 }
56
57- utils.PrepareTargetDir(tplOutputDir)
58 outputFile, err := os.Create(controlFile)
59 if err != nil {
60 log.Fatalf("Error creating control file %s", controlFile)
61@@ -224,6 +240,14 @@
62
63 buildAssets(*useSnappyFromBranch, *arch)
64
65+ // TODO: generate the files out of the source tree. --elopio - 2015-07-15
66+ utils.PrepareTargetDir(dataOutputDir)
67+ defer os.RemoveAll(dataOutputDir)
68+
69+ // TODO: pass the config as arguments to the test binaries.
70+ // --elopio - 2015-07-15
71+ writeTestConfig(*imgRelease, *imgChannel)
72+
73 rootPath := getRootPath()
74
75 if *testbedIP == "" {
76
77=== removed file '_integration-tests/tests/01_test_info'
78--- _integration-tests/tests/01_test_info 2015-06-15 15:36:29 +0000
79+++ _integration-tests/tests/01_test_info 1970-01-01 00:00:00 +0000
80@@ -1,4 +0,0 @@
81-test() {
82- test_regexp "^release: ubuntu-core/.*/(edge|stable)" $SNAPPY info
83- test_regexp "^frameworks: ($framework|)*$" $SNAPPY info
84-}
85
86=== removed file '_integration-tests/tests/10_test_info_has_stuff'
87--- _integration-tests/tests/10_test_info_has_stuff 2015-06-16 06:05:14 +0000
88+++ _integration-tests/tests/10_test_info_has_stuff 1970-01-01 00:00:00 +0000
89@@ -1,4 +0,0 @@
90-test() {
91- test_regexp "^release: ubuntu-core/.*/(edge|stable)" $SNAPPY info
92- test_regexp "^frameworks: $framework" $SNAPPY info
93-}
94
95=== added file '_integration-tests/tests/latest/info_test.go'
96--- _integration-tests/tests/latest/info_test.go 1970-01-01 00:00:00 +0000
97+++ _integration-tests/tests/latest/info_test.go 2015-07-15 15:54:02 +0000
98@@ -0,0 +1,86 @@
99+// -*- Mode: Go; indent-tabs-mode: t -*-
100+
101+/*
102+ * Copyright (C) 2015 Canonical Ltd
103+ *
104+ * This program is free software: you can redistribute it and/or modify
105+ * it under the terms of the GNU General Public License version 3 as
106+ * published by the Free Software Foundation.
107+ *
108+ * This program is distributed in the hope that it will be useful,
109+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
110+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
111+ * GNU General Public License for more details.
112+ *
113+ * You should have received a copy of the GNU General Public License
114+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
115+ *
116+ */
117+
118+package latest
119+
120+import (
121+ "encoding/json"
122+ "fmt"
123+ "io/ioutil"
124+
125+ . "../common"
126+
127+ check "gopkg.in/check.v1"
128+)
129+
130+var _ = check.Suite(&infoSuite{})
131+
132+type infoSuite struct {
133+ SnappySuite
134+}
135+
136+func readConfig(c *check.C) map[string]string {
137+ b, err := ioutil.ReadFile("_integration-tests/data/output/testconfig.json")
138+ c.Assert(
139+ err, check.IsNil, check.Commentf("Failed to read test config: %v", err))
140+
141+ var decoded map[string]string
142+ err = json.Unmarshal(b, &decoded)
143+ c.Assert(
144+ err, check.IsNil, check.Commentf("Failed to decode test config: %v", err))
145+ return decoded
146+}
147+
148+func (s *infoSuite) TestInfoMustPrintReleaseAndChannel(c *check.C) {
149+ infoOutput := ExecCommand(c, "snappy", "info")
150+
151+ config := readConfig(c)
152+ expected := "(?ms)" +
153+ fmt.Sprintf("^release: ubuntu-core/%s/%s\n", config["release"], config["channel"]) +
154+ ".*"
155+
156+ c.Assert(infoOutput, check.Matches, expected)
157+}
158+
159+func (s *infoSuite) TestInfoMustPrintInstalledApps(c *check.C) {
160+ InstallSnap(c, "hello-world")
161+ s.AddCleanup(func() {
162+ RemoveSnap(c, "hello-world")
163+ })
164+ infoOutput := ExecCommand(c, "snappy", "info")
165+
166+ expected := "(?ms)" +
167+ ".*" +
168+ "^apps: .*hello-world.*\n"
169+ c.Assert(infoOutput, check.Matches, expected)
170+}
171+
172+func (s *infoSuite) TestInfoMustPrintInstalledFrameworks(c *check.C) {
173+ InstallSnap(c, "hello-dbus-fwk.canonical")
174+ s.AddCleanup(func() {
175+ RemoveSnap(c, "hello-dbus-fwk.canonical")
176+ })
177+ infoOutput := ExecCommand(c, "snappy", "info")
178+
179+ expected := "(?ms)" +
180+ ".*" +
181+ "^frameworks: .*hello-dbus-fwk.*\n" +
182+ ".*"
183+ c.Assert(infoOutput, check.Matches, expected)
184+}

Subscribers

People subscribed via source and target branches