예제 #1
0
var _ = Describe("TLSWriter", func() {
	var dialer *net.Dialer
	var ioTimeout time.Duration

	BeforeEach(func() {
		ioTimeout = 0
		dialer = &net.Dialer{
			Timeout: 500 * time.Millisecond,
		}
	})

	Describe("New", func() {
		It("returns an error for syslog scheme", func() {
			outputURL, _ := url.Parse("syslog://localhost")
			_, err := syslogwriter.NewTlsWriter(outputURL, "appId", false, dialer, ioTimeout)
			Expect(err).To(HaveOccurred())
		})

		It("returns an error for https scheme", func() {
			outputURL, _ := url.Parse("https://localhost")
			_, err := syslogwriter.NewTlsWriter(outputURL, "appId", false, dialer, ioTimeout)
			Expect(err).To(HaveOccurred())
		})

		It("returns an error if the provided dialer is nil", func() {
			outputURL, _ := url.Parse("syslog-tls://localhost")
			_, err := syslogwriter.NewTlsWriter(outputURL, "appId", false, nil, ioTimeout)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("cannot construct a writer with a nil dialer"))
		})
예제 #2
0
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
)

var _ = Describe("TLSWriter", func() {
	var syslogServerSession *gexec.Session
	var syslogWriter syslogwriter.Writer
	var standardOutPriority int = 14

	Context("writes and connects to syslog tls drains", func() {
		BeforeEach(func(done Done) {
			var err error
			syslogServerSession = startEncryptedTCPServer("127.0.0.1:9998")
			outputURL, _ := url.Parse("syslog-tls://127.0.0.1:9998")
			syslogWriter, err = syslogwriter.NewTlsWriter(outputURL, "appId", true)
			Expect(err).ToNot(HaveOccurred())
			close(done)
		}, 5)

		AfterEach(func() {
			syslogServerSession.Kill().Wait()
			syslogWriter.Close()
		})

		It("connects and writes", func(done Done) {
			ts := time.Now().UnixNano()
			Eventually(func() error {
				err := syslogWriter.Connect()
				return err
			}, 5, 1).ShouldNot(HaveOccurred())