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

chore: Always use newest golangci lint, fix linting issues #90

Merged
merged 1 commit into from
Aug 1, 2024
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
2 changes: 0 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ jobs:
fetch-depth: '0'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.55
18 changes: 3 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,11 @@ run:
concurrency: 4
timeout: 5m
tests: true
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
modules-download-mode: readonly
allow-parallel-runners: false
go: '1.19'

# output configuration options
output:
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
#
# Multiple can be specified by separating them by comma, output can be provided
# for each of them by separating format name and path by colon symbol.
# Output path can be either `stdout`, `stderr` or path to the file to write to.
# Example: "checkstyle:report.json,colored-line-number"
#
# Default: colored-line-number
format: colored-line-number
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
Expand All @@ -44,9 +32,9 @@ linters:
- gocognit
- goconst
- gocritic
- goerr113
- err113
- gofmt
- gomnd
- mnd
- gomoddirectives
- gosec
- gosimple
Expand Down Expand Up @@ -94,7 +82,7 @@ issues:
- wrapcheck

linters-settings:
gomnd:
mnd:
ignored-functions:
- context.WithTimeout
nolintlint:
Expand Down
6 changes: 6 additions & 0 deletions factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,31 @@ func TestHTTPFrontendFactory_BuildBackend(t *testing.T) {

t.Run("memory", func(t *testing.T) {
t.Parallel()

testConfig := httpcache.BackendConfig{
BackendType: "memory",
Memory: &httpcache.MemoryBackendConfig{Size: 10},
}

backend, err := factory.BuildBackend(testConfig, "test")
assert.NoError(t, err)
assert.IsType(t, &httpcache.MemoryBackend{}, backend)
})

t.Run("inmemory error", func(t *testing.T) {
t.Parallel()

testConfig := httpcache.BackendConfig{
BackendType: "memory",
}

_, err := factory.BuildBackend(testConfig, "test")
assert.Error(t, err)
})

t.Run("redis", func(t *testing.T) {
t.Parallel()

testConfig := httpcache.BackendConfig{
BackendType: "redis",
Redis: &httpcache.RedisBackendConfig{
Expand All @@ -88,6 +93,7 @@ func TestHTTPFrontendFactory_BuildBackend(t *testing.T) {
Port: "8080",
},
}

backend, err := factory.BuildBackend(testConfig, "test")
assert.NoError(t, err)
assert.IsType(t, &httpcache.RedisBackend{}, backend)
Expand Down
7 changes: 4 additions & 3 deletions frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

var ErrInvalidEntry = errors.New("cache returned invalid entry type")
var ErrNoCacheBackend = errors.New("no backend defined")

type (
// Frontend caches and delivers HTTP responses
Expand Down Expand Up @@ -40,7 +41,7 @@ func (f *Frontend) SetBackend(b Backend) *Frontend {

func (f *Frontend) Purge(ctx context.Context, key string) error {
if f.backend == nil {
return errors.New("no backend defined")
return ErrNoCacheBackend
}

_, span := trace.StartSpan(ctx, "flamingo/httpcache/purge")
Expand All @@ -60,7 +61,7 @@ func (f *Frontend) Purge(ctx context.Context, key string) error {
// The result of loader will be returned and cached
func (f *Frontend) Get(ctx context.Context, key string, loader HTTPLoader) (Entry, error) {
if f.backend == nil {
return Entry{}, errors.New("no backend defined")
return Entry{}, ErrNoCacheBackend
}

ctx, span := trace.StartSpan(ctx, "flamingo/httpcache/get")
Expand Down Expand Up @@ -98,7 +99,7 @@ func (f *Frontend) Get(ctx context.Context, key string, loader HTTPLoader) (Entr
return f.load(ctx, key, loader)
}

func (f *Frontend) load(ctx context.Context, key string, loader HTTPLoader) (Entry, error) {
func (f *Frontend) load(ctx context.Context, key string, loader HTTPLoader) (Entry, error) { //nolint:contextcheck // this is fine
oldSpan := trace.FromContext(ctx)
newContext := trace.NewContext(context.Background(), oldSpan)

Expand Down
5 changes: 5 additions & 0 deletions frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func TestFrontend_Get(t *testing.T) {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()

wait := make(chan struct{}, 1)
loaderCalled := false
loader := func(ctx context.Context) (httpcache.Entry, error) {
Expand All @@ -127,9 +128,11 @@ func TestFrontend_Get(t *testing.T) {
}

backend := new(mocks.Backend)

if test.cacheGetter != nil {
backend.EXPECT().Get(testKey).Return(test.cacheGetter())
}

if test.wantSet != nil {
backend.EXPECT().Set(testKey, *test.wantSet).Run(func(key string, entry httpcache.Entry) {
wait <- struct{}{}
Expand All @@ -150,8 +153,10 @@ func TestFrontend_Get(t *testing.T) {

if (err != nil) != test.wantErr {
t.Errorf("Get() error = %v, wantErr %v", err, test.wantErr)

return
}

assert.Equal(t, test.want, got)
})
}
Expand Down
2 changes: 1 addition & 1 deletion twoLevelBackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (mb *TwoLevelBackend) Set(key string, entry Entry) error {
mb.logger.WithField("category", "TwoLevelBackend").Error(fmt.Sprintf("Failed to set key %v with error %v", key, err))
}

if errorCount >= 2 { //nolint:gomnd // there are two backends no need to introduce const for that
if errorCount >= 2 { //nolint:mnd // there are two backends no need to introduce const for that
return ErrAllBackendsFailed
}

Expand Down
Loading