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

Proposed by Leo Arias
Status: Rejected
Rejected by: Leo Arias
Proposed branch: lp:~elopio/snappy/serve_daemon_test
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~chipaca/snappy/serve
Diff against target: 77 lines (+61/-0)
2 files modified
cmd/snapd/main.go (+11/-0)
cmd/snapd/main_test.go (+50/-0)
To merge this branch: bzr merge lp:~elopio/snappy/serve_daemon_test
Reviewer Review Type Date Requested Status
Leo Arias (community) Disapprove
Review via email: mp+270484@code.launchpad.net

This proposal supersedes a proposal from 2015-09-09.

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

Seems not worth it. It's easier to test the daemon on the snappy system:
https://code.launchpad.net/~fgimenez/snappy/snapd_integration_test/+merge/270515

review: Disapprove

Unmerged revisions

651. By Leo Arias

Playing with the daemon.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'cmd/snapd/main.go'
--- cmd/snapd/main.go 2015-09-09 06:34:47 +0000
+++ cmd/snapd/main.go 2015-09-09 06:34:47 +0000
@@ -36,7 +36,18 @@
36 }36 }
37}37}
3838
39// XXX what are the alternatives here? use real systemd to run the binary? --elopio- 2015-09-09
40func fixListenPid() {
41 if os.Getenv("FIX_LISTEN_PID") != "" {
42 // HACK: real systemd would set LISTEN_PID before exec'ing but
43 // this is too difficult in golang for the purpose of a test.
44 // Do not do this in real code.
45 os.Setenv("LISTEN_PID", fmt.Sprintf("%d", os.Getpid()))
46 }
47}
48
39func main() {49func main() {
50 fixListenPid()
40 if err := run(); err != nil {51 if err := run(); err != nil {
41 fmt.Fprintf(os.Stderr, "error: %v\n", err)52 fmt.Fprintf(os.Stderr, "error: %v\n", err)
42 os.Exit(1)53 os.Exit(1)
4354
=== added file 'cmd/snapd/main_test.go'
--- cmd/snapd/main_test.go 1970-01-01 00:00:00 +0000
+++ cmd/snapd/main_test.go 2015-09-09 06:34:47 +0000
@@ -0,0 +1,50 @@
1package main
2
3import (
4 "io/ioutil"
5 "net"
6 "net/http"
7 "os"
8 "os/exec"
9 "syscall"
10 "testing"
11
12 "gopkg.in/check.v1"
13)
14
15// Hook up check.v1 into the "go test" runner
16func Test(t *testing.T) { check.TestingT(t) }
17
18type snapdSuite struct{}
19
20var _ = check.Suite(&snapdSuite{})
21
22func (s *snapdSuite) Test(c *check.C) {
23 cmd := exec.Command("go", "run", "main.go")
24
25 // TODO get a random port. Not yet because this is useful to know if the server is being killed.
26 // --elopio - 2015-09-09
27 listener, err := net.Listen("tcp", ":9999")
28 c.Assert(err, check.IsNil)
29
30 tcpListener := listener.(*net.TCPListener)
31 f, err := tcpListener.File()
32 c.Assert(err, check.IsNil)
33 cmd.ExtraFiles = []*os.File{f}
34
35 cmd.Env = os.Environ()
36 cmd.Env = append(cmd.Env, "LISTEN_FDS=1", "FIX_LISTEN_PID=1")
37
38 cmd.Start()
39 // FIXME this is not killing the server. How do we get the pid? Close the listener? Close the file?
40 // --elopio - 2015-09-09
41 defer cmd.Process.Signal(syscall.SIGTERM)
42
43 resp, err := http.Get("http://127.0.0.1:9999")
44 defer resp.Body.Close()
45 c.Assert(err, check.IsNil)
46 body, err := ioutil.ReadAll(resp.Body)
47 c.Assert(err, check.IsNil)
48 expected := `{"metadata":["/1.0"],"status":"OK","status_code":200,"type":"sync"}`
49 c.Assert(string(body), check.Equals, expected)
50}

Subscribers

People subscribed via source and target branches