. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/pivotal-cf-experimental/garden/message_reader"
	protocol "github.com/pivotal-cf-experimental/garden/protocol"
)

var _ = Describe("Reading response messages over the wire", func() {
	Context("when a message of the expected type is received", func() {
		It("populates the response object and returns no error", func() {
			var echoResponse protocol.EchoResponse

			err := message_reader.ReadMessage(
				bufio.NewReader(protocol.Messages(&protocol.EchoRequest{
					Message: proto.String("some message"),
				})),
				&echoResponse,
			)

			Expect(err).ToNot(HaveOccurred())

			Expect(echoResponse.GetMessage()).To(Equal("some message"))
		})
	})

	Context("when the connection is broken", func() {
		It("returns an error", func() {
			var dummyResponse protocol.PingResponse

			payload := protocol.Messages(&protocol.PingRequest{})
예제 #2
0
			Eventually(ErrorDialing("unix", socketPath)).ShouldNot(HaveOccurred())

			serverConnection, err = net.Dial("unix", socketPath)
			Expect(err).ToNot(HaveOccurred())

			responses = bufio.NewReader(serverConnection)
		})

		writeMessages := func(message proto.Message) {
			num, err := protocol.Messages(message).WriteTo(serverConnection)
			Expect(err).ToNot(HaveOccurred())
			Expect(num).ToNot(Equal(0))
		}

		readResponse := func(response proto.Message) {
			err := message_reader.ReadMessage(responses, response)
			Expect(err).ToNot(HaveOccurred())
		}

		It("stops accepting new connections", func() {
			go wardenServer.Stop()
			Eventually(ErrorDialing("unix", socketPath)).Should(HaveOccurred())
		})

		It("stops handling requests on existing connections", func() {
			writeMessages(&protocol.PingRequest{})
			readResponse(&protocol.PingResponse{})

			go wardenServer.Stop()

			// server was already reading a request