var syslogServerSession *gexec.Session BeforeEach(func() { dialer = &net.Dialer{ Timeout: 500 * time.Millisecond, } port := 9800 + config.GinkgoConfig.ParallelNode address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port)) outputURL := &url.URL{Scheme: "syslog", Host: address} syslogServerSession = startSyslogServer(address) sysLogWriter, _ = syslogwriter.NewSyslogWriter(outputURL, "appId", dialer, 0) Eventually(func() error { err := sysLogWriter.Connect() return err }, 5, 1).ShouldNot(HaveOccurred()) }, 10) AfterEach(func() { sysLogWriter.Close() syslogServerSession.Kill().Wait() }) Context("Message Format", func() { It("sends messages in the proper format", func() { sysLogWriter.Write(standardOutPriority, []byte("just a test"), "App", "2", time.Now().UnixNano()) Eventually(syslogServerSession, 5).Should(gbytes.Say(`\d <\d+>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,6}([-+]\d{2}:\d{2}) loggregator appId \[App/2\] - - just a test\n`)) }, 10)
address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port)) syslogServerSession = startEncryptedTCPServer(address) outputURL := &url.URL{Scheme: "syslog-tls", Host: address} syslogWriter, err = syslogwriter.NewTlsWriter(outputURL, "appId", skipCertVerify, dialer, ioTimeout) Expect(err).ToNot(HaveOccurred()) }, 5) AfterEach(func() { syslogServerSession.Terminate().Wait() syslogWriter.Close() }) It("connects and writes", func() { ts := time.Now().UnixNano() Eventually(func() error { err := syslogWriter.Connect() return err }, 5, 1).ShouldNot(HaveOccurred()) _, err := syslogWriter.Write(standardOutPriority, []byte("just a test"), "test", "", ts) Expect(err).ToNot(HaveOccurred()) Eventually(syslogServerSession, 3).Should(gbytes.Say("just a test")) }, 10) Context("when an i/o timeout is set", func() { BeforeEach(func() { // cause an immediate write timeout ioTimeout = -1 * time.Second })