Beispiel #1
0
			It("returns tls", func() {
				Expect(client.Scheme()).To(Equal("udp"))
			})
		})

		Describe("Address", func() {
			It("returns the address", func() {
				Expect(client.Address()).To(Equal(udpListener.LocalAddr().String()))
			})
		})
	})

	It("sends log messages to loggregator", func() {
		expectedOutput := []byte("Important Testmessage")

		_, err := client.Write(expectedOutput)
		Expect(err).NotTo(HaveOccurred())

		buffer := make([]byte, 4096)
		readCount, _, err := udpListener.ReadFromUDP(buffer)
		Expect(err).NotTo(HaveOccurred())

		received := string(buffer[:readCount])
		Expect(received).To(Equal(string(expectedOutput)))
	})

	It("doesn't send empty data", func() {
		bufferSize := 4096
		firstMessage := []byte("")
		secondMessage := []byte("hi")
		Context("with an invalid address", func() {
			BeforeEach(func() {
				address = "I am definitely not an address"
			})

			It("returns an error and a nil client", func() {
				Expect(createErr).To(HaveOccurred())
				Expect(client).To(BeNil())
			})
		})

		Context("with a returned client", func() {
			var client clientpool.Client

			BeforeEach(func() {
				var err error
				client, err = udpClientCreator.CreateClient(address)
				Expect(err).ToNot(HaveOccurred())
			})

			It("can write", func() {
				message := []byte("foo")
				written, err := client.Write(message)
				Expect(err).ToNot(HaveOccurred())
				Expect(written).To(BeEquivalentTo(len(message)))
			})
		})
	})
})
Beispiel #3
0
	Describe("Address", func() {
		It("returns the address", func() {
			Expect(client.Address()).To(Equal(tlsListener.Addr().String()))
		})
	})

	Describe("Writing data", func() {
		var conn net.Conn

		JustBeforeEach(func() {
			Eventually(connChan).Should(Receive(&conn))
			Expect(conn).NotTo(BeNil())
		})

		It("sends data", func() {
			_, err := client.Write([]byte("abc"))
			Expect(err).NotTo(HaveOccurred())
			bytes := make([]byte, 10)
			n, err := conn.Read(bytes)
			Expect(err).NotTo(HaveOccurred())
			Expect(bytes[:n]).To(Equal([]byte("abc")))
		})

		Context("when there is no data", func() {
			It("does not send", func() {
				_, err := client.Write([]byte(""))
				Expect(err).NotTo(HaveOccurred())

				bytes := make([]byte, 10)
				conn.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
				_, err = conn.Read(bytes)