func TestUnixSocketCommunications(t *testing.T) { Convey("Given a server listening on a UNIX socket", t, func() { testServer, err := local.NewServer("/tmp/hologram.test.sock", testHandler) So(err, ShouldBeNil) Reset(func() { testServer.Close() }) Convey("When a client connects and pings", func() { testPingClient, err := local.NewClient("/tmp/hologram.test.sock") So(err, ShouldBeNil) pingReq := protocol.Ping_REQUEST pingMsg := &protocol.Message{ Ping: &protocol.Ping{ Type: &pingReq, }, } err = testPingClient.Write(pingMsg) So(err, ShouldBeNil) Convey("Then it should get a pong response", func() { resp, err := testPingClient.Read() So(err, ShouldBeNil) So(resp.GetPing(), ShouldNotBeNil) }) }) }) }
func (h *cliHandler) Start() error { _, err := local.NewServer(h.address, h.HandleConnection) if err != nil { return err } // we run as root, so let others connect to the socket os.Chmod(h.address, 0777) return nil }