Skip to content

Commit

Permalink
Switch to testify & go modules (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromer authored Feb 16, 2021
1 parent 5fbaaf0 commit a20549f
Show file tree
Hide file tree
Showing 13 changed files with 1,568 additions and 1,050 deletions.
36 changes: 21 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
SUBPACKAGES=. rfc3164 rfc5424
help:
@echo "Available targets:"
@echo "- tests: run tests"
@echo "- installdependencies: installs dependencies declared in dependencies.txt"
@echo "- clean: cleans directory"
@echo "- benchmarks: run benchmarks"
GO ?= $(shell which go)

installdependencies:
@cat dependencies.txt | xargs go get
GO_PKGS ?= $(shell $(GO) list ./...)

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

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

benchmarks:
@for pkg in $(SUBPACKAGES); do cd $$pkg && go test -gocheck.b ; cd -;done
GO_BENCH=go test -bench=. -benchmem

all: test

test:
$(GO) test \
-race \
-timeout $(GO_TEST_TIMEOUT) \
$(GO_TEST_PKGS)

#XXX: ugly
benchmark:
$(GO_BENCH)
cd rfc3164 && $(GO_BENCH)
cd rfc5424 && $(GO_BENCH)
51 changes: 36 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ You should see
Detecting message format
------------------------

You can use the `WhichRFC()` function. Like this:
You can use the `DetectRFC()` function. Like this:

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

Run `make tests`
Run `make test`

Running benchmarks
------------------

Run `make benchmarks`

CommonTestSuite.BenchmarkParsePriority 20000000 85.9 ns/op
CommonTestSuite.BenchmarkParseVersion 500000000 4.59 ns/op
Rfc3164TestSuite.BenchmarkParseFull 10000000 187 ns/op
Rfc3164TestSuite.BenchmarkParseHeader 5000000 686 ns/op
Rfc3164TestSuite.BenchmarkParseHostname 50000000 43.4 ns/op
Rfc3164TestSuite.BenchmarkParseTag 50000000 63.5 ns/op
Rfc3164TestSuite.BenchmarkParseTimestamp 5000000 616 ns/op
Rfc3164TestSuite.BenchmarkParsemessage 10000000 187 ns/op
Rfc5424TestSuite.BenchmarkParseFull 1000000 1345 ns/op
Rfc5424TestSuite.BenchmarkParseHeader 1000000 1353 ns/op
Rfc5424TestSuite.BenchmarkParseTimestamp 1000000 2045 ns/op
Run `make benchmark`

go test -bench=. -benchmem
goos: linux
goarch: amd64
pkg: github.com/jeromer/syslogparser
BenchmarkParsePriority-8 41772079 31.2 ns/op 0 B/op 0 allocs/op
BenchmarkParseVersion-8 270007530 4.45 ns/op 0 B/op 0 allocs/op
BenchmarkDetectRFC-8 78742269 16.2 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/jeromer/syslogparser 5.257s

cd rfc3164 && go test -bench=. -benchmem
goos: linux
goarch: amd64
pkg: github.com/jeromer/syslogparser/rfc3164
BenchmarkParseTimestamp-8 2693362 467 ns/op 16 B/op 1 allocs/op
BenchmarkParseHostname-8 34919636 32.8 ns/op 16 B/op 1 allocs/op
BenchmarkParseTag-8 20970715 56.0 ns/op 8 B/op 1 allocs/op
BenchmarkParseHeader-8 2549106 478 ns/op 32 B/op 2 allocs/op
BenchmarkParsemessage-8 8280796 143 ns/op 72 B/op 3 allocs/op
BenchmarkParseFull-8 8070195 139 ns/op 120 B/op 3 allocs/op
PASS
ok github.com/jeromer/syslogparser/rfc3164 8.428s

cd rfc5424 && go test -bench=. -benchmem
goos: linux
goarch: amd64
pkg: github.com/jeromer/syslogparser/rfc5424
BenchmarkParseTimestamp-8 846019 1385 ns/op 352 B/op 18 allocs/op
BenchmarkParseHeader-8 1424103 840 ns/op 106 B/op 12 allocs/op
BenchmarkParseFull-8 1444834 825 ns/op 112 B/op 12 allocs/op
PASS
ok github.com/jeromer/syslogparser/rfc5424 6.195s

[RFC 5424]: https://tools.ietf.org/html/rfc5424
[RFC 3164]: https://tools.ietf.org/html/rfc3164
1 change: 0 additions & 1 deletion dependencies.txt

This file was deleted.

5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/jeromer/syslogparser

go 1.14

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

import (
"fmt"

"github.com/jeromer/syslogparser/rfc3164"
)

Expand Down
11 changes: 6 additions & 5 deletions rfc3164/rfc3164.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package rfc3164

import (
"bytes"
"github.com/jeromer/syslogparser"
"time"

"github.com/jeromer/syslogparser"
)

type Parser struct {
Expand Down Expand Up @@ -56,9 +57,9 @@ func (p *Parser) Parse() error {
p.priority = pri
} else {
p.priority = syslogparser.Priority{
0,
syslogparser.Facility{0},
syslogparser.Severity{0},
P: 0,
F: syslogparser.Facility{Value: 0},
S: syslogparser.Severity{Value: 0},
}
}

Expand Down Expand Up @@ -226,7 +227,7 @@ func (p *Parser) parseTag() (string, error) {
if endOfTag {
if !found {
tag = p.buff[from:p.cursor]
found = true
// found = true
}

p.cursor++
Expand Down
Loading

0 comments on commit a20549f

Please sign in to comment.