From 8558fed9ca5ca4040c34cbbab9ad68d252ffe941 Mon Sep 17 00:00:00 2001 From: Michael Gasch Date: Tue, 18 Jan 2022 13:40:51 +0100 Subject: [PATCH] chore: Add golangci-lint Closes: #24 Signed-off-by: Michael Gasch --- .github/workflows/lint.yaml | 43 +++++++++++++++++++++++++++++++++++++ options.go | 14 ++++++------ segment_internal_test.go | 40 +++++++++++++++++----------------- stream_test.go | 3 ++- 4 files changed, 72 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/lint.yaml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..36fa6fd --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,43 @@ +name: golangci-lint + +on: + push: + branches: ["main", "master"] + + pull_request: + branches: ["main", "master", "release-*"] + +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the action will use pre-installed Go. + # skip-go-installation: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true \ No newline at end of file diff --git a/options.go b/options.go index 02ca6f4..0c1c3c6 100644 --- a/options.go +++ b/options.go @@ -37,25 +37,25 @@ func WithClock(c clock.Clock) Option { } } -// WithMaxSegmentSize sets the maximum size, i.e. number of offsets, in a log -// segment. Must be greater than 0. -func WithMaxSegmentSize(size int) Option { +// WithMaxRecordDataSize sets the maximum record data (payload) size in bytes +func WithMaxRecordDataSize(size int) Option { return func(log *Log) error { if size <= 0 { return errors.New("size must be greater than 0") } - log.conf.segmentSize = size + log.conf.maxRecordSize = size return nil } } -// WithMaxRecordDataSize sets the maximum record data (payload) size in bytes -func WithMaxRecordDataSize(size int) Option { +// WithMaxSegmentSize sets the maximum size, i.e. number of offsets, in a log +// segment. Must be greater than 0. +func WithMaxSegmentSize(size int) Option { return func(log *Log) error { if size <= 0 { return errors.New("size must be greater than 0") } - log.conf.maxRecordSize = size + log.conf.segmentSize = size return nil } } diff --git a/segment_internal_test.go b/segment_internal_test.go index 17def29..1172656 100644 --- a/segment_internal_test.go +++ b/segment_internal_test.go @@ -13,8 +13,8 @@ import ( func Test_newSegment(t *testing.T) { t.Run("new fails with size 0", func(t *testing.T) { const ( - start Offset = 0 - size = 0 + start = Offset(0) + size = 0 ) _, err := newSegment(start, size) assert.ErrorContains(t, err, "size must be") @@ -22,8 +22,8 @@ func Test_newSegment(t *testing.T) { t.Run("new fails with negative size", func(t *testing.T) { const ( - start Offset = 0 - size = -10 + start = Offset(0) + size = -10 ) _, err := newSegment(start, size) assert.ErrorContains(t, err, "size must be") @@ -40,8 +40,8 @@ func Test_newSegment(t *testing.T) { t.Run("verify defaults on new segment", func(t *testing.T) { const ( - start Offset = 0 - size = 10 + start = Offset(0) + size = 10 ) s, err := newSegment(start, size) @@ -55,8 +55,8 @@ func Test_newSegment(t *testing.T) { func TestSegment_ReadWrite(t *testing.T) { t.Run("read fails on cancelled context", func(t *testing.T) { const ( - start Offset = 0 - size = 10 + start = Offset(0) + size = 10 ) s, err := newSegment(start, size) @@ -117,8 +117,8 @@ func TestSegment_ReadWrite(t *testing.T) { func TestSegment_Write(t *testing.T) { t.Run("write fails on cancelled context", func(t *testing.T) { const ( - start Offset = 0 - size = 10 + start = Offset(0) + size = 10 ) s, err := newSegment(start, size) @@ -134,8 +134,8 @@ func TestSegment_Write(t *testing.T) { t.Run("write fails on sealed segment", func(t *testing.T) { const ( - start Offset = 0 - size = 10 + start = Offset(0) + size = 10 ) ctx := context.Background() @@ -153,8 +153,8 @@ func TestSegment_Write(t *testing.T) { t.Run("write fails on full segment", func(t *testing.T) { const ( - start Offset = 0 - size = 5 + start = Offset(0) + size = 5 ) ctx := context.Background() @@ -175,8 +175,8 @@ func TestSegment_Write(t *testing.T) { t.Run("write and read one record, starts at virtual offset 0", func(t *testing.T) { const ( - start Offset = 0 - size = 10 + start = Offset(0) + size = 10 ) ctx := context.Background() @@ -205,10 +205,10 @@ func TestSegment_Write(t *testing.T) { t.Run("write and read five records, starts virtual offset 10", func(t *testing.T) { const ( - start Offset = 10 - size = 10 - eventIDRange = 10 - numRecords = 5 + start = Offset(10) + size = 10 + eventIDRange = 10 + numRecords = 5 ) var ( diff --git a/stream_test.go b/stream_test.go index 3cbdd39..c4fcc6b 100644 --- a/stream_test.go +++ b/stream_test.go @@ -144,8 +144,9 @@ func TestLog_Stream(t *testing.T) { for { if _, ok := stream.Next(); ok { t.Fatalf("should not receive from stream") + } else { + break } - break } assert.Assert(t, errors.Is(stream.Err(), ErrOutOfRange)) })