예제 #1
0
				_, err := clientpool.NewUDPClient(gosteno.NewLogger("TestLogger"), "127.0.0.1:abc", 0)
				Expect(err).To(HaveOccurred())
			})
		})
	})

	Describe("udpClient", func() {
		Describe("Scheme", func() {
			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])
		address = "127.0.0.1:1234"
		udpClientCreator = clientpool.NewUDPClientCreator(logger)
	})

	Describe("CreateClient", func() {
		var (
			client    clientpool.Client
			createErr error
		)

		JustBeforeEach(func() {
			client, createErr = udpClientCreator.CreateClient(address)
		})
		It("makes clients", func() {
			Expect(createErr).ToNot(HaveOccurred())
			Expect(client.Address()).To(Equal(address))
			Expect(client.Scheme()).To(Equal("udp"))
		})

		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() {
예제 #3
0
			It("returns a client", func() {
				Expect(client).NotTo(BeNil())
				Consistently(connChan).ShouldNot(Receive())
			})
		})
	})

	Describe("Scheme", func() {
		It("returns tls", func() {
			Expect(client.Scheme()).To(Equal("tls"))
		})
	})

	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)