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

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 769
Merged at revision: 775
Proposed branch: lp:~elopio/snappy/examples6
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~elopio/snappy/examples5
Diff against target: 101 lines (+33/-9)
4 files modified
_integration-tests/tests/examples_test.go (+27/-4)
_integration-tests/tests/snapd_test.go (+1/-1)
_integration-tests/testutils/wait/wait.go (+3/-2)
_integration-tests/testutils/wait/wait_test.go (+2/-2)
To merge this branch: bzr merge lp:~elopio/snappy/examples6
Reviewer Review Type Date Requested Status
Federico Gimenez (community) Approve
Review via email: mp+274352@code.launchpad.net

Commit message

Added a test for go-webserver-example snap.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

@Federico, if you see this before I wake up, could you please ask why is the python server started with the tcp protol and the go server started with the tcp6 protocol?

lp:~elopio/snappy/examples6 updated
768. By Leo Arias

Added a space after the protocol in the regular expression.

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

Looks great, only one failing unit test [1], once it's fixed +1

Thanks!

[1] http://paste.ubuntu.com/12787160/

review: Needs Fixing
lp:~elopio/snappy/examples6 updated
769. By Leo Arias

Fixed the expected regexp.

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

Fixed, thanks for the review.

Revision history for this message
Federico Gimenez (fgimenez) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_integration-tests/tests/examples_test.go'
2--- _integration-tests/tests/examples_test.go 2015-10-14 05:18:25 +0000
3+++ _integration-tests/tests/examples_test.go 2015-10-15 15:06:21 +0000
4@@ -69,19 +69,19 @@
5 c.Assert(string(echoOutput), check.Matches, expected)
6 }
7
8-var _ = check.Suite(&webserverExampleSuite{})
9+var _ = check.Suite(&pythonWebserverExampleSuite{})
10
11-type webserverExampleSuite struct {
12+type pythonWebserverExampleSuite struct {
13 common.SnappySuite
14 }
15
16-func (s *webserverExampleSuite) TestNetworkingServiceMustBeStarted(c *check.C) {
17+func (s *pythonWebserverExampleSuite) TestNetworkingServiceMustBeStarted(c *check.C) {
18 baseAppName := "xkcd-webserver"
19 appName := baseAppName + ".canonical"
20 common.InstallSnap(c, appName)
21 defer common.RemoveSnap(c, appName)
22
23- err := wait.ForServerOnPort(c, 80)
24+ err := wait.ForServerOnPort(c, "tcp", 80)
25 c.Assert(err, check.IsNil)
26
27 resp, err := http.Get("http://localhost")
28@@ -90,6 +90,29 @@
29 c.Assert(resp.Proto, check.Equals, "HTTP/1.0")
30 }
31
32+var _ = check.Suite(&goWebserverExampleSuite{})
33+
34+type goWebserverExampleSuite struct {
35+ common.SnappySuite
36+}
37+
38+func (s *goWebserverExampleSuite) TestGetRootPathMustPrintMessage(c *check.C) {
39+ appName := "go-example-webserver"
40+ common.InstallSnap(c, appName)
41+ defer common.RemoveSnap(c, appName)
42+
43+ err := wait.ForServerOnPort(c, "tcp6", 8081)
44+ c.Assert(err, check.IsNil, check.Commentf("Error waiting for server: %s", err))
45+
46+ resp, err := http.Get("http://localhost:8081/")
47+ defer resp.Body.Close()
48+ c.Assert(err, check.IsNil, check.Commentf("Error getting the http resource: %s", err))
49+ c.Check(resp.Status, check.Equals, "200 OK", check.Commentf("Wrong reply status"))
50+ body, err := ioutil.ReadAll(resp.Body)
51+ c.Assert(err, check.IsNil, check.Commentf("Error reading the reply body: %s", err))
52+ c.Assert(string(body), check.Equals, "Hello World\n", check.Commentf("Wrong reply body"))
53+}
54+
55 var _ = check.Suite(&frameworkExampleSuite{})
56
57 type frameworkExampleSuite struct {
58
59=== modified file '_integration-tests/tests/snapd_test.go'
60--- _integration-tests/tests/snapd_test.go 2015-10-14 09:23:38 +0000
61+++ _integration-tests/tests/snapd_test.go 2015-10-15 15:06:21 +0000
62@@ -58,7 +58,7 @@
63 s.cmd.Start()
64
65 intPort, _ := strconv.Atoi(port)
66- err := wait.ForServerOnPort(c, intPort)
67+ err := wait.ForServerOnPort(c, "tcp", intPort)
68 c.Assert(err, check.IsNil)
69 }
70
71
72=== modified file '_integration-tests/testutils/wait/wait.go'
73--- _integration-tests/testutils/wait/wait.go 2015-09-30 11:06:40 +0000
74+++ _integration-tests/testutils/wait/wait.go 2015-10-15 15:06:21 +0000
75@@ -46,8 +46,9 @@
76 }
77
78 // ForServerOnPort uses ForCommand to check for process listening on the given port
79-func ForServerOnPort(c *check.C, port int) (err error) {
80- return ForCommand(c, fmt.Sprintf(`(?msU)^.*tcp.*0\.0\.0\.0:%d .*`, port), "netstat", "-tapn")
81+func ForServerOnPort(c *check.C, protocol string, port int) (err error) {
82+ return ForCommand(c, fmt.Sprintf(`(?msU)^.*%s .*:%d .* LISTEN.*`, protocol, port),
83+ "netstat", "-tapn")
84 }
85
86 // forCommand uses ForFunction to check for the execCommand output
87
88=== modified file '_integration-tests/testutils/wait/wait_test.go'
89--- _integration-tests/testutils/wait/wait_test.go 2015-09-28 10:54:40 +0000
90+++ _integration-tests/testutils/wait/wait_test.go 2015-10-15 15:06:21 +0000
91@@ -177,9 +177,9 @@
92 return
93 }
94
95- ForServerOnPort(c, 1234)
96+ ForServerOnPort(c, "tcp", 1234)
97
98- expectedCalled := `ForCommand called with pattern '(?msU)^.*tcp.*0\.0\.0\.0:1234 .*' and cmds 'netstat -tapn'`
99+ expectedCalled := `ForCommand called with pattern '(?msU)^.*tcp .*:1234 .* LISTEN.*' and cmds 'netstat -tapn'`
100 c.Assert(called, check.Equals, expectedCalled, check.Commentf("Expected call to ForCommand didn't happen"))
101 }
102

Subscribers

People subscribed via source and target branches