Skip to content

Commit

Permalink
chore: update golangci-lint (argoproj#8988)
Browse files Browse the repository at this point in the history
* chore: update golangci-lint

Signed-off-by: Michael Crenshaw <[email protected]>
Signed-off-by: wojtekidd <[email protected]>
  • Loading branch information
crenshaw-dev authored and wojtekidd committed Apr 25, 2022
1 parent 14e869a commit 33ade1d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 29 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ jobs:
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.38.0
args: --timeout 10m --exclude SA5011
skip-go-installation: true # Because we need a specific version
version: v1.45.2
args: --timeout 10m --exclude SA5011 --verbose

test-go:
name: Run unit tests for Go packages
Expand Down
22 changes: 0 additions & 22 deletions .golangci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion hack/installers/install-lint-tools.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -eux -o pipefail

GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.38.0
GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
4 changes: 2 additions & 2 deletions util/io/bytereadseeker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type byteReadSeeker struct {
offset int64
}

func (f byteReadSeeker) Read(b []byte) (int, error) {
func (f *byteReadSeeker) Read(b []byte) (int, error) {
if f.offset >= int64(len(f.data)) {
return 0, io.EOF
}
Expand All @@ -23,7 +23,7 @@ func (f byteReadSeeker) Read(b []byte) (int, error) {
return n, nil
}

func (f byteReadSeeker) Seek(offset int64, whence int) (int64, error) {
func (f *byteReadSeeker) Seek(offset int64, whence int) (int64, error) {
switch whence {
case 1:
offset += f.offset
Expand Down
71 changes: 71 additions & 0 deletions util/io/bytereadseeker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package io

import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io"
"testing"
)

func TestByteReadSeeker_Read(t *testing.T) {
inString := "hello world"
reader := NewByteReadSeeker([]byte(inString))
var bytes = make([]byte, 11)
n, err := reader.Read(bytes)
require.NoError(t, err)
assert.Equal(t, len(inString), n)
assert.Equal(t, inString, string(bytes))
_, err = reader.Read(bytes)
assert.ErrorIs(t, err, io.EOF)
}

func TestByteReadSeeker_Seek_Start(t *testing.T) {
inString := "hello world"
reader := NewByteReadSeeker([]byte(inString))
offset, err := reader.Seek(6, io.SeekStart)
require.NoError(t, err)
assert.Equal(t, int64(6), offset)
var bytes = make([]byte, 5)
n, err := reader.Read(bytes)
require.NoError(t, err)
assert.Equal(t, 5, n)
assert.Equal(t, "world", string(bytes))
}

func TestByteReadSeeker_Seek_Current(t *testing.T) {
inString := "hello world"
reader := NewByteReadSeeker([]byte(inString))
offset, err := reader.Seek(3, io.SeekCurrent)
require.NoError(t, err)
assert.Equal(t, int64(3), offset)
offset, err = reader.Seek(3, io.SeekCurrent)
require.NoError(t, err)
assert.Equal(t, int64(6), offset)
var bytes = make([]byte, 5)
n, err := reader.Read(bytes)
require.NoError(t, err)
assert.Equal(t, 5, n)
assert.Equal(t, "world", string(bytes))
}

func TestByteReadSeeker_Seek_End(t *testing.T) {
inString := "hello world"
reader := NewByteReadSeeker([]byte(inString))
offset, err := reader.Seek(-5, io.SeekEnd)
require.NoError(t, err)
assert.Equal(t, int64(6), offset)
var bytes = make([]byte, 5)
n, err := reader.Read(bytes)
require.NoError(t, err)
assert.Equal(t, 5, n)
assert.Equal(t, "world", string(bytes))
}

func TestByteReadSeeker_Seek_OutOfBounds(t *testing.T) {
inString := "hello world"
reader := NewByteReadSeeker([]byte(inString))
_, err := reader.Seek(12, io.SeekStart)
assert.Error(t, err)
_, err = reader.Seek(-1, io.SeekStart)
assert.Error(t, err)
}

0 comments on commit 33ade1d

Please sign in to comment.