Skip to content

Commit

Permalink
chore: Add golangci-lint
Browse files Browse the repository at this point in the history
Closes: #24
Signed-off-by: Michael Gasch <[email protected]>
  • Loading branch information
Michael Gasch committed Jan 18, 2022
1 parent f688f35 commit 8558fed
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 28 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
40 changes: 20 additions & 20 deletions segment_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ 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")
})

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")
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down

0 comments on commit 8558fed

Please sign in to comment.