@@ -13,14 +13,12 @@ var _ = Suite(&Rfc3164TestSuite{})
13
13
14
14
func (s * Rfc3164TestSuite ) TestRfc3164Parser_Valid (c * C ) {
15
15
buff := []byte ("<34>Oct 11 22:14:15 mymachine su: 'su root' failed for lonvick on /dev/pts/8" )
16
- start := 0
17
- l := len (buff )
18
16
19
- p := NewRfc3164Parser (buff , start , l )
17
+ p := NewRfc3164Parser (buff )
20
18
expectedP := & rfc3164Parser {
21
19
buff : buff ,
22
- cursor : start ,
23
- l : l ,
20
+ cursor : 0 ,
21
+ l : len ( buff ) ,
24
22
}
25
23
26
24
c .Assert (p , DeepEquals , expectedP )
@@ -46,75 +44,68 @@ func (s *Rfc3164TestSuite) TestRfc3164Parser_Valid(c *C) {
46
44
47
45
func (s * Rfc3164TestSuite ) TestParseHeader_Valid (c * C ) {
48
46
buff := []byte ("Oct 11 22:14:15 mymachine " )
49
- start := 0
50
47
now := time .Now ()
51
48
hdr := rfc3164Header {
52
49
timestamp : time .Date (now .Year (), time .October , 11 , 22 , 14 , 15 , 0 , time .UTC ),
53
50
hostname : "mymachine" ,
54
51
}
55
52
56
- s .assertRfc3164Header (c , hdr , buff , start , 25 , nil )
53
+ s .assertRfc3164Header (c , hdr , buff , 25 , nil )
57
54
}
58
55
59
56
func (s * Rfc3164TestSuite ) TestParseHeader_InvalidTimestamp (c * C ) {
60
57
buff := []byte ("Oct 34 32:72:82 mymachine " )
61
- start := 0
62
58
hdr := rfc3164Header {}
63
59
64
- s .assertRfc3164Header (c , hdr , buff , start , 16 , ErrTimestampUnknownFormat )
60
+ s .assertRfc3164Header (c , hdr , buff , 16 , ErrTimestampUnknownFormat )
65
61
}
66
62
67
63
func (s * Rfc3164TestSuite ) TestParseMessage_Valid (c * C ) {
68
64
content := "foo bar baz blah quux"
69
65
buff := []byte ("sometag[123]: " + content )
70
- start := 0
71
66
hdr := rfc3164Message {
72
67
tag : "sometag" ,
73
68
content : content ,
74
69
}
75
70
76
- s .assertRfc3164Message (c , hdr , buff , start , len (buff ), ErrEOL )
71
+ s .assertRfc3164Message (c , hdr , buff , len (buff ), ErrEOL )
77
72
}
78
73
79
74
func (s * Rfc3164TestSuite ) TestParseTimestamp_TooLong (c * C ) {
80
75
// XXX : <15 chars
81
76
buff := []byte ("aaa" )
82
- start := 0
83
77
ts := new (time.Time )
84
78
85
- s .assertTimestamp (c , * ts , buff , start , len (buff ), ErrEOL )
79
+ s .assertTimestamp (c , * ts , buff , len (buff ), ErrEOL )
86
80
}
87
81
88
82
func (s * Rfc3164TestSuite ) TestParseTimestamp_Invalid (c * C ) {
89
83
buff := []byte ("Oct 34 32:72:82" )
90
- start := 0
91
84
ts := new (time.Time )
92
85
93
- s .assertTimestamp (c , * ts , buff , start , len (buff ), ErrTimestampUnknownFormat )
86
+ s .assertTimestamp (c , * ts , buff , len (buff ), ErrTimestampUnknownFormat )
94
87
}
95
88
96
89
func (s * Rfc3164TestSuite ) TestParseTimestamp_TrailingSpace (c * C ) {
97
90
// XXX : no year specified. Assumed current year
98
91
// XXX : no timezone specified. Assume UTC
99
92
buff := []byte ("Oct 11 22:14:15 " )
100
- start := 0
101
93
102
94
now := time .Now ()
103
95
ts := time .Date (now .Year (), time .October , 11 , 22 , 14 , 15 , 0 , time .UTC )
104
96
105
- s .assertTimestamp (c , ts , buff , start , len (buff ), nil )
97
+ s .assertTimestamp (c , ts , buff , len (buff ), nil )
106
98
}
107
99
108
100
func (s * Rfc3164TestSuite ) TestParseTimestamp_Valid (c * C ) {
109
101
// XXX : no year specified. Assumed current year
110
102
// XXX : no timezone specified. Assume UTC
111
103
buff := []byte ("Oct 11 22:14:15" )
112
- start := 0
113
104
114
105
now := time .Now ()
115
106
ts := time .Date (now .Year (), time .October , 11 , 22 , 14 , 15 , 0 , time .UTC )
116
107
117
- s .assertTimestamp (c , ts , buff , start , len (buff ), nil )
108
+ s .assertTimestamp (c , ts , buff , len (buff ), nil )
118
109
}
119
110
120
111
func (s * Rfc3164TestSuite ) TestParseTag_TooLong (c * C ) {
@@ -123,42 +114,37 @@ func (s *Rfc3164TestSuite) TestParseTag_TooLong(c *C) {
123
114
124
115
aaa := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
125
116
buff := []byte (aaa + "[10]:" )
126
- start := 0
127
117
tag := ""
128
118
129
- s .assertTag (c , tag , buff , start , len (aaa )+ 1 , ErrTagTooLong )
119
+ s .assertTag (c , tag , buff , len (aaa )+ 1 , ErrTagTooLong )
130
120
}
131
121
132
122
func (s * Rfc3164TestSuite ) TestParseTag_Pid (c * C ) {
133
123
buff := []byte ("apache2[10]:" )
134
- start := 0
135
124
tag := "apache2"
136
125
137
- s .assertTag (c , tag , buff , start , len (buff ), nil )
126
+ s .assertTag (c , tag , buff , len (buff ), nil )
138
127
}
139
128
140
129
func (s * Rfc3164TestSuite ) TestParseTag_NoPid (c * C ) {
141
130
buff := []byte ("apache2:" )
142
- start := 0
143
131
tag := "apache2"
144
132
145
- s .assertTag (c , tag , buff , start , len (buff ), nil )
133
+ s .assertTag (c , tag , buff , len (buff ), nil )
146
134
}
147
135
148
136
func (s * Rfc3164TestSuite ) TestParseTag_TrailingSpace (c * C ) {
149
137
buff := []byte ("apache2: " )
150
- start := 0
151
138
tag := "apache2"
152
139
153
- s .assertTag (c , tag , buff , start , len (buff ), nil )
140
+ s .assertTag (c , tag , buff , len (buff ), nil )
154
141
}
155
142
156
143
func (s * Rfc3164TestSuite ) TestParseContent_Valid (c * C ) {
157
144
buff := []byte (" foo bar baz quux " )
158
- start := 0
159
145
content := string (bytes .Trim (buff , " " ))
160
146
161
- p := NewRfc3164Parser (buff , start , len ( buff ) )
147
+ p := NewRfc3164Parser (buff )
162
148
obtained , err := p .parseContent ()
163
149
c .Assert (err , Equals , ErrEOL )
164
150
c .Assert (obtained , Equals , content )
@@ -167,9 +153,8 @@ func (s *Rfc3164TestSuite) TestParseContent_Valid(c *C) {
167
153
168
154
func (s * Rfc3164TestSuite ) BenchmarkParseTimestamp (c * C ) {
169
155
buff := []byte ("Oct 11 22:14:15" )
170
- l := len (buff )
171
156
172
- p := NewRfc3164Parser (buff , 0 , l )
157
+ p := NewRfc3164Parser (buff )
173
158
174
159
for i := 0 ; i < c .N ; i ++ {
175
160
_ , err := p .parseTimestamp ()
@@ -183,10 +168,8 @@ func (s *Rfc3164TestSuite) BenchmarkParseTimestamp(c *C) {
183
168
184
169
func (s * Rfc3164TestSuite ) BenchmarkParseHostname (c * C ) {
185
170
buff := []byte ("gimli.local" )
186
- var start int
187
- l := len (buff )
188
171
189
- p := NewRfc3164Parser (buff , start , l )
172
+ p := NewRfc3164Parser (buff )
190
173
191
174
for i := 0 ; i < c .N ; i ++ {
192
175
_ , err := p .parseHostname ()
@@ -200,9 +183,8 @@ func (s *Rfc3164TestSuite) BenchmarkParseHostname(c *C) {
200
183
201
184
func (s * Rfc3164TestSuite ) BenchmarkParseTag (c * C ) {
202
185
buff := []byte ("apache2[10]:" )
203
- l := len (buff )
204
186
205
- p := NewRfc3164Parser (buff , 0 , l )
187
+ p := NewRfc3164Parser (buff )
206
188
207
189
for i := 0 ; i < c .N ; i ++ {
208
190
_ , err := p .parseTag ()
@@ -216,9 +198,8 @@ func (s *Rfc3164TestSuite) BenchmarkParseTag(c *C) {
216
198
217
199
func (s * Rfc3164TestSuite ) BenchmarkParseHeader (c * C ) {
218
200
buff := []byte ("Oct 11 22:14:15 mymachine " )
219
- l := len (buff )
220
201
221
- p := NewRfc3164Parser (buff , 0 , l )
202
+ p := NewRfc3164Parser (buff )
222
203
223
204
for i := 0 ; i < c .N ; i ++ {
224
205
_ , err := p .parseHeader ()
@@ -232,10 +213,8 @@ func (s *Rfc3164TestSuite) BenchmarkParseHeader(c *C) {
232
213
233
214
func (s * Rfc3164TestSuite ) BenchmarkParseMessage (c * C ) {
234
215
buff := []byte ("sometag[123]: foo bar baz blah quux" )
235
- var start int
236
- l := len (buff )
237
216
238
- p := NewRfc3164Parser (buff , start , l )
217
+ p := NewRfc3164Parser (buff )
239
218
240
219
for i := 0 ; i < c .N ; i ++ {
241
220
_ , err := p .parseMessage ()
@@ -247,32 +226,32 @@ func (s *Rfc3164TestSuite) BenchmarkParseMessage(c *C) {
247
226
}
248
227
}
249
228
250
- func (s * Rfc3164TestSuite ) assertTimestamp (c * C , ts time.Time , b []byte , cursor int , expC int , e error ) {
251
- p := NewRfc3164Parser (b , cursor , len ( b ) )
229
+ func (s * Rfc3164TestSuite ) assertTimestamp (c * C , ts time.Time , b []byte , expC int , e error ) {
230
+ p := NewRfc3164Parser (b )
252
231
obtained , err := p .parseTimestamp ()
253
232
c .Assert (obtained , Equals , ts )
254
233
c .Assert (p .cursor , Equals , expC )
255
234
c .Assert (err , Equals , e )
256
235
}
257
236
258
- func (s * Rfc3164TestSuite ) assertTag (c * C , t string , b []byte , cursor int , expC int , e error ) {
259
- p := NewRfc3164Parser (b , cursor , len ( b ) )
237
+ func (s * Rfc3164TestSuite ) assertTag (c * C , t string , b []byte , expC int , e error ) {
238
+ p := NewRfc3164Parser (b )
260
239
obtained , err := p .parseTag ()
261
240
c .Assert (obtained , Equals , t )
262
241
c .Assert (p .cursor , Equals , expC )
263
242
c .Assert (err , Equals , e )
264
243
}
265
244
266
- func (s * Rfc3164TestSuite ) assertRfc3164Header (c * C , hdr rfc3164Header , b []byte , cursor int , expC int , e error ) {
267
- p := NewRfc3164Parser (b , cursor , len ( b ) )
245
+ func (s * Rfc3164TestSuite ) assertRfc3164Header (c * C , hdr rfc3164Header , b []byte , expC int , e error ) {
246
+ p := NewRfc3164Parser (b )
268
247
obtained , err := p .parseHeader ()
269
248
c .Assert (err , Equals , e )
270
249
c .Assert (obtained , Equals , hdr )
271
250
c .Assert (p .cursor , Equals , expC )
272
251
}
273
252
274
- func (s * Rfc3164TestSuite ) assertRfc3164Message (c * C , msg rfc3164Message , b []byte , cursor int , expC int , e error ) {
275
- p := NewRfc3164Parser (b , cursor , len ( b ) )
253
+ func (s * Rfc3164TestSuite ) assertRfc3164Message (c * C , msg rfc3164Message , b []byte , expC int , e error ) {
254
+ p := NewRfc3164Parser (b )
276
255
obtained , err := p .parseMessage ()
277
256
c .Assert (err , Equals , e )
278
257
c .Assert (obtained , Equals , msg )
0 commit comments