Skip to content

Commit a20549f

Browse files
authored
Switch to testify & go modules (#21)
1 parent 5fbaaf0 commit a20549f

13 files changed

+1568
-1050
lines changed

Makefile

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
SUBPACKAGES=. rfc3164 rfc5424
2-
help:
3-
@echo "Available targets:"
4-
@echo "- tests: run tests"
5-
@echo "- installdependencies: installs dependencies declared in dependencies.txt"
6-
@echo "- clean: cleans directory"
7-
@echo "- benchmarks: run benchmarks"
1+
GO ?= $(shell which go)
82

9-
installdependencies:
10-
@cat dependencies.txt | xargs go get
3+
GO_PKGS ?= $(shell $(GO) list ./...)
114

12-
tests: installdependencies
13-
@for pkg in $(SUBPACKAGES); do cd $$pkg && go test -i && go test ; cd -;done
5+
GO_TEST_PKGS ?= $(shell test -f go.mod && $(GO) list -f \
6+
'{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' \
7+
$(GO_PKGS))
148

15-
clean:
16-
find . -type 'f' -name '*.test' -print | xargs rm -f
9+
GO_TEST_TIMEOUT ?= 15s
1710

18-
benchmarks:
19-
@for pkg in $(SUBPACKAGES); do cd $$pkg && go test -gocheck.b ; cd -;done
11+
GO_BENCH=go test -bench=. -benchmem
12+
13+
all: test
14+
15+
test:
16+
$(GO) test \
17+
-race \
18+
-timeout $(GO_TEST_TIMEOUT) \
19+
$(GO_TEST_PKGS)
20+
21+
#XXX: ugly
22+
benchmark:
23+
$(GO_BENCH)
24+
cd rfc3164 && $(GO_BENCH)
25+
cd rfc5424 && $(GO_BENCH)

README.md

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ You should see
8181
Detecting message format
8282
------------------------
8383

84-
You can use the `WhichRFC()` function. Like this:
84+
You can use the `DetectRFC()` function. Like this:
8585

8686
b := []byte(`<165>1 2003-10-11T22:14:15.003Z ...`)
8787
rfc, err := syslogparser.DetectRFC(b)
@@ -101,24 +101,45 @@ You can use the `WhichRFC()` function. Like this:
101101
Running tests
102102
-------------
103103

104-
Run `make tests`
104+
Run `make test`
105105

106106
Running benchmarks
107107
------------------
108108

109-
Run `make benchmarks`
110-
111-
CommonTestSuite.BenchmarkParsePriority 20000000 85.9 ns/op
112-
CommonTestSuite.BenchmarkParseVersion 500000000 4.59 ns/op
113-
Rfc3164TestSuite.BenchmarkParseFull 10000000 187 ns/op
114-
Rfc3164TestSuite.BenchmarkParseHeader 5000000 686 ns/op
115-
Rfc3164TestSuite.BenchmarkParseHostname 50000000 43.4 ns/op
116-
Rfc3164TestSuite.BenchmarkParseTag 50000000 63.5 ns/op
117-
Rfc3164TestSuite.BenchmarkParseTimestamp 5000000 616 ns/op
118-
Rfc3164TestSuite.BenchmarkParsemessage 10000000 187 ns/op
119-
Rfc5424TestSuite.BenchmarkParseFull 1000000 1345 ns/op
120-
Rfc5424TestSuite.BenchmarkParseHeader 1000000 1353 ns/op
121-
Rfc5424TestSuite.BenchmarkParseTimestamp 1000000 2045 ns/op
109+
Run `make benchmark`
110+
111+
go test -bench=. -benchmem
112+
goos: linux
113+
goarch: amd64
114+
pkg: github.com/jeromer/syslogparser
115+
BenchmarkParsePriority-8 41772079 31.2 ns/op 0 B/op 0 allocs/op
116+
BenchmarkParseVersion-8 270007530 4.45 ns/op 0 B/op 0 allocs/op
117+
BenchmarkDetectRFC-8 78742269 16.2 ns/op 0 B/op 0 allocs/op
118+
PASS
119+
ok github.com/jeromer/syslogparser 5.257s
120+
121+
cd rfc3164 && go test -bench=. -benchmem
122+
goos: linux
123+
goarch: amd64
124+
pkg: github.com/jeromer/syslogparser/rfc3164
125+
BenchmarkParseTimestamp-8 2693362 467 ns/op 16 B/op 1 allocs/op
126+
BenchmarkParseHostname-8 34919636 32.8 ns/op 16 B/op 1 allocs/op
127+
BenchmarkParseTag-8 20970715 56.0 ns/op 8 B/op 1 allocs/op
128+
BenchmarkParseHeader-8 2549106 478 ns/op 32 B/op 2 allocs/op
129+
BenchmarkParsemessage-8 8280796 143 ns/op 72 B/op 3 allocs/op
130+
BenchmarkParseFull-8 8070195 139 ns/op 120 B/op 3 allocs/op
131+
PASS
132+
ok github.com/jeromer/syslogparser/rfc3164 8.428s
133+
134+
cd rfc5424 && go test -bench=. -benchmem
135+
goos: linux
136+
goarch: amd64
137+
pkg: github.com/jeromer/syslogparser/rfc5424
138+
BenchmarkParseTimestamp-8 846019 1385 ns/op 352 B/op 18 allocs/op
139+
BenchmarkParseHeader-8 1424103 840 ns/op 106 B/op 12 allocs/op
140+
BenchmarkParseFull-8 1444834 825 ns/op 112 B/op 12 allocs/op
141+
PASS
142+
ok github.com/jeromer/syslogparser/rfc5424 6.195s
122143

123144
[RFC 5424]: https://tools.ietf.org/html/rfc5424
124145
[RFC 3164]: https://tools.ietf.org/html/rfc3164

dependencies.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/jeromer/syslogparser
2+
3+
go 1.14
4+
5+
require github.com/stretchr/testify v1.7.0

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
7+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
10+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

rfc3164/example_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package rfc3164_test
22

33
import (
44
"fmt"
5+
56
"github.com/jeromer/syslogparser/rfc3164"
67
)
78

rfc3164/rfc3164.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package rfc3164
22

33
import (
44
"bytes"
5-
"github.com/jeromer/syslogparser"
65
"time"
6+
7+
"github.com/jeromer/syslogparser"
78
)
89

910
type Parser struct {
@@ -56,9 +57,9 @@ func (p *Parser) Parse() error {
5657
p.priority = pri
5758
} else {
5859
p.priority = syslogparser.Priority{
59-
0,
60-
syslogparser.Facility{0},
61-
syslogparser.Severity{0},
60+
P: 0,
61+
F: syslogparser.Facility{Value: 0},
62+
S: syslogparser.Severity{Value: 0},
6263
}
6364
}
6465

@@ -226,7 +227,7 @@ func (p *Parser) parseTag() (string, error) {
226227
if endOfTag {
227228
if !found {
228229
tag = p.buff[from:p.cursor]
229-
found = true
230+
// found = true
230231
}
231232

232233
p.cursor++

0 commit comments

Comments
 (0)