/
syslog_raw_test.go
112 lines (99 loc) · 2.71 KB
/
syslog_raw_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package syslog_test
import (
"bytes"
"compress/gzip"
"github.com/ArthurHlt/go-syslog-client"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"io"
)
var _ = Describe("SyslogRaw", func() {
Context("TCP/UDP server", func() {
var server *Server
var syslogClient io.WriteCloser
BeforeEach(func() {
var err error
server = NewServer("tcp")
syslogClient, err = syslog.NewWriter(server.URL)
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
syslogClient.Close()
server.Close()
})
It("should pass to server the content", func() {
syslogClient.Write([]byte("my content"))
Eventually(server.BufferResp.String).Should(Equal("my content"))
})
})
Context("TCP with pool size", func() {
var server *Server
var syslogClient io.WriteCloser
BeforeEach(func() {
var err error
server = NewServer("tcp")
syslogClient, err = syslog.NewWriter(server.URL + "?pool_size=2")
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
syslogClient.Close()
server.Close()
})
It("should pass to server the content", func() {
Expect(syslogClient).To(BeAssignableToTypeOf(&syslog.WriterPool{}))
syslogClient.Write([]byte("my content"))
Eventually(server.BufferResp.String).Should(Equal("my content"))
})
})
Context("HTTP server", func() {
var server *Server
var syslogClient io.WriteCloser
BeforeEach(func() {
var err error
server = NewServer("http")
syslogClient, err = syslog.HttpDial(server.URL)
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
syslogClient.Close()
server.Close()
})
It("should pass to server the content", func() {
syslogClient.Write([]byte("my content"))
Eventually(server.BufferResp.String).Should(Equal("my content"))
})
When("set in gzip", func() {
It("should pass to server the content in gzip format", func() {
var err error
syslogClient, err = syslog.HttpDial(server.URL + "?in_gzip=true")
Expect(err).ToNot(HaveOccurred())
content := []byte("my content")
syslogClient.Write(content)
buf := &bytes.Buffer{}
gw := gzip.NewWriter(buf)
gw.Write(content)
gw.Flush()
gw.Close()
Eventually(server.BufferResp.Bytes).Should(Equal(buf.Bytes()))
})
})
})
Context("TCP Tls server", func() {
var server *Server
var syslogClient io.WriteCloser
BeforeEach(func() {
var err error
server = NewServer("tcp+tls")
syslogClient, err = syslog.NewWriter(server.URL + "?verify=false")
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
syslogClient.Close()
server.Close()
})
It("should pass to server the content", func() {
syslogClient.Write([]byte("my content"))
Eventually(server.BufferResp.String).Should(Equal("my content"))
})
})
})