Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make golangci-lint happy #2

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/stdin-parser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package main
import (
"bufio"
"fmt"
"github.com/wneessen/go-parsesyslog"
"github.com/wneessen/go-parsesyslog/rfc5424"
"os"
"time"

"github.com/wneessen/go-parsesyslog"
"github.com/wneessen/go-parsesyslog/rfc5424"
)

func main() {
Expand Down
6 changes: 4 additions & 2 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ func Test_readBytesUntilSpaceOrNilValue(t *testing.T) {
wantErr bool
}{
{"test1", `123-test - blubb`, []byte("123-test"), 9, false},
{"timestamp", `2016-02-28T09:57:10.804642398-05:00 - - `,
[]byte("2016-02-28T09:57:10.804642398-05:00"), 36, false},
{
"timestamp", `2016-02-28T09:57:10.804642398-05:00 - - `,
[]byte("2016-02-28T09:57:10.804642398-05:00"), 36, false,
},
{"NILVAL", ` - foo bar`, []byte{}, 1, false},
{"empty", ``, []byte{}, 0, true},
}
Expand Down
2 changes: 1 addition & 1 deletion logmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type LogMsg struct {
Facility Facility
HasBOM bool
Hostname string
//Message []byte
// Message []byte
Message bytes.Buffer
MsgLength int
MsgID string
Expand Down
8 changes: 3 additions & 5 deletions parsesyslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ var (
lock sync.RWMutex

// types is a map of installed message parser types, supplying a function that
//creates a new instance of that Parser.
// creates a new instance of that Parser.
types = map[ParserType]func() (Parser, error){}
)

var (
// ErrUnknownParserType is returned if a Parser is requested via New() which is not registered
ErrUnknownParserType = errors.New("unknown parser type")
)
// ErrUnknownParserType is returned if a Parser is requested via New() which is not registered
var ErrUnknownParserType = errors.New("unknown parser type")

// Parser defines the interface for parsing different types of Syslog messages
type Parser interface {
Expand Down
2 changes: 2 additions & 0 deletions priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestFacilityFromPrio(t *testing.T) {
}

// TestSeverityFromPrio tests the SeverityFromPrio method
//
//nolint:staticcheck
func TestSeverityFromPrio(t *testing.T) {
tests := []struct {
Expand Down Expand Up @@ -111,6 +112,7 @@ func TestFacilityStringFromPrio(t *testing.T) {
}

// TestSeverityStringFromPrio tests the SeverityStringFromPrio method
//
//nolint:staticcheck
func TestSeverityStringFromPrio(t *testing.T) {
tests := []struct {
Expand Down
3 changes: 2 additions & 1 deletion rfc3164/rfc3164.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bufio"
"bytes"
"errors"
"github.com/wneessen/go-parsesyslog"
"io"
"strings"
"time"

"github.com/wneessen/go-parsesyslog"
)

// msg represents a log message in that matches RFC3164
Expand Down
9 changes: 6 additions & 3 deletions rfc3164/rfc3164_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package rfc3164
import (
"bufio"
"errors"
"github.com/wneessen/go-parsesyslog"
"io"
"strings"
"testing"

"github.com/wneessen/go-parsesyslog"
)

// TestParseStringRFC3164 tests the NewRFC3164Parser method together with the ParseString
Expand Down Expand Up @@ -59,8 +60,10 @@ func TestRFC3164Msg_parseTag(t *testing.T) {
wantErr bool
wantText string
}{
{"valid tag with pid", `syslog-ng[1122680]: Test123`, `syslog-ng`, `1122680`,
false, `Test123`},
{
"valid tag with pid", `syslog-ng[1122680]: Test123`, `syslog-ng`, `1122680`,
false, `Test123`,
},
{"valid tag no pid", `su: Test123`, `su`, ``, false, `Test123`},
{"no tag", `This is a test `, ``, ``, false, `This is a test `},
{"mark", "-- MARK --\n", ``, ``, false, "-- MARK --\n"},
Expand Down
5 changes: 3 additions & 2 deletions rfc5424/rfc5424.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bufio"
"bytes"
"errors"
"github.com/wneessen/go-parsesyslog"
"io"
"strings"
"time"

"github.com/wneessen/go-parsesyslog"
)

// msg represents a log message in that matches RFC5424
Expand Down Expand Up @@ -72,7 +73,7 @@ func (m *msg) ParseReader(r io.Reader) (parsesyslog.LogMsg, error) {
return l, nil
}

//rb := make([]byte, ml - l.Message.Len())
// rb := make([]byte, ml - l.Message.Len())
md, err := io.ReadAll(br)
if err != nil {
return l, err
Expand Down
73 changes: 50 additions & 23 deletions rfc5424/rfc5424_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package rfc5424

import (
"bufio"
"github.com/wneessen/go-parsesyslog"
"io"
"strings"
"testing"

"github.com/wneessen/go-parsesyslog"
)

// TestParseStringRFC5424 tests the NewRFC5424Parser method together with the ParseString
Expand Down Expand Up @@ -106,14 +107,22 @@ func TestRFC5424Msg_parseTimestamp(t *testing.T) {
want string
wantErr bool
}{
{`1985-04-12T23:20:50.52Z`, `1985-04-12T23:20:50.52Z `,
`1985-04-12 23:20:50.520 +00`, false},
{`1985-04-12T19:20:50.52-04:00`, `1985-04-12T23:20:50.52Z `,
`1985-04-12 23:20:50.520 +00`, false},
{`2003-10-11T22:14:15.003Z`, `2003-10-11T22:14:15.003Z `,
`2003-10-11 22:14:15.003 +00`, false},
{`2003-08-24T05:14:15.000003-07:00`, `2003-08-24T05:14:15.000003-07:00 `,
`2003-08-24 12:14:15.000 +00`, false},
{
`1985-04-12T23:20:50.52Z`, `1985-04-12T23:20:50.52Z `,
`1985-04-12 23:20:50.520 +00`, false,
},
{
`1985-04-12T19:20:50.52-04:00`, `1985-04-12T23:20:50.52Z `,
`1985-04-12 23:20:50.520 +00`, false,
},
{
`2003-10-11T22:14:15.003Z`, `2003-10-11T22:14:15.003Z `,
`2003-10-11 22:14:15.003 +00`, false,
},
{
`2003-08-24T05:14:15.000003-07:00`, `2003-08-24T05:14:15.000003-07:00 `,
`2003-08-24 12:14:15.000 +00`, false,
},
{`NILVALUE`, `- `, `0001-01-01 00:00:00.000 +00`, false},
{`Invalid TS`, `20211112345 `, `0001-01-01 00:00:00.000 +00`, true},
}
Expand Down Expand Up @@ -144,8 +153,10 @@ func TestRFC5424Msg_parseHostname(t *testing.T) {
}{
{`FQDN`, `host.domain.tld `, `host.domain.tld`, false},
{`IPv4`, `10.0.1.2 `, `10.0.1.2`, false},
{`IPv6`, `2345:0425:2CA1:0000:0000:0567:5673:23b5 `, `2345:0425:2CA1:0000:0000:0567:5673:23b5`,
false},
{
`IPv6`, `2345:0425:2CA1:0000:0000:0567:5673:23b5 `, `2345:0425:2CA1:0000:0000:0567:5673:23b5`,
false,
},
{`Host`, `test-machine `, `test-machine`, false},
{`NILVALUE`, `- `, ``, false},
}
Expand Down Expand Up @@ -260,17 +271,34 @@ func TestRFC5424Msg_parseStructuredData(t *testing.T) {
wantElemID []string
wantErr bool
}{
{`foo@1234 with 1 element`, `[foo@1234 Revision="1.2.3.4"] `,
[]string{`foo@1234`}, 1, 1, []string{"Revision"},
false},
{`foo@1234 with 3 elements`, `[foo@1234 Revision="1.2 3.4" intu="4" foo="bar"] `,
[]string{`foo@1234`}, 1, 3, []string{"Revision", "intu", "foo"},
false},
{`foo@1234 and bar@1234`, `[foo@1234 Revision="1.2.3.4"][bar@1234 Revision="1.2.3.4"] `,
[]string{`foo@1234`, `bar@1234`}, 2, 1, []string{"Revision"},
false},
{`NILVALUE`, `- `, []string{``}, 0, 0, []string{},
false},
{
`foo@1234 with 1 element`, `[foo@1234 Revision="1.2.3.4"] `,
[]string{`foo@1234`},
1, 1,
[]string{"Revision"},
false,
},
{
`foo@1234 with 3 elements`, `[foo@1234 Revision="1.2 3.4" intu="4" foo="bar"] `,
[]string{`foo@1234`},
1, 3,
[]string{"Revision", "intu", "foo"},
false,
},
{
`foo@1234 and bar@1234`, `[foo@1234 Revision="1.2.3.4"][bar@1234 Revision="1.2.3.4"] `,
[]string{`foo@1234`, `bar@1234`},
2, 1,
[]string{"Revision"},
false,
},
{
`NILVALUE`, `- `,
[]string{``},
0, 0,
[]string{},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -317,7 +345,6 @@ func TestRFC5424Msg_parseStructuredData(t *testing.T) {
t.Error("parseStructuredData() param names = not all parameters found")
}
}

})
}
}
Expand Down