Skip to content
Open
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
18 changes: 18 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ linters:
- tagalign
- testifylint
- unconvert
- usetesting
- unparam
- unused
- usestdlibvars
Expand Down Expand Up @@ -199,6 +200,14 @@ linters:
disable:
- go-require
- float-compare
usetesting:
os-create-temp: true # Disallow `os.CreateTemp("", ...)`
os-mkdir-temp: true # Disallow `os.MkdirTemp()`
os-setenv: true # Disallow `os.Setenv()`
os-temp-dir: true # Disallow `os.TempDir()`
os-chdir: true # Disallow `os.Chdir()`
context-background: true # Disallow `context.Background()`
context-todo: true # Disallow `context.TODO()`
unused:
# Mark all struct fields that have been written to as used.
# Default: true
Expand All @@ -216,6 +225,15 @@ linters:
- common-false-positives
- legacy
- std-error-handling
rules:
# Exclude some linters from running on test files.
# 1. Exclude the top level tests/ directory.
# 2. Exclude any file prefixed with test_ in any directory.
# 3. Exclude any directory suffixed with test.
# 4. Exclude any file suffixed with _test.go.
- path: "(^tests/)|(^(.*/)*test_[^/]*\\.go$)|(.*test/.*)|(.*_test\\.go$)"
linters:
- prealloc
formatters:
enable:
- gci
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Mocks are auto-generated using [mockgen](https://pkg.go.dev/go.uber.org/mock/moc
- Run the linter

```sh
./scipts/run_task.sh lint
./scripts/run_task.sh lint
```

### Continuous Integration (CI)
Expand Down
4 changes: 4 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ tasks:
desc: Runs static analysis tests of golang code
cmd: ./scripts/lint.sh

lint-fix:
desc: Runs automated fixing for failing static analysis of golang code
cmd: ./scripts/run_tool.sh golangci-lint run --config .golangci.yml --fix

lint-action:
desc: Runs actionlint to check sanity of github action configuration
cmd: ./scripts/actionlint.sh
Expand Down
28 changes: 14 additions & 14 deletions api/admin/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestStartCPUProfiler(t *testing.T) {
for _, test := range SuccessResponseTests {
t.Run(test.name, func(t *testing.T) {
mockClient := Client{Requester: NewMockClient(&api.EmptyReply{}, test.expectedErr)}
err := mockClient.StartCPUProfiler(context.Background())
err := mockClient.StartCPUProfiler(t.Context())
require.ErrorIs(t, err, test.expectedErr)
})
}
Expand All @@ -88,7 +88,7 @@ func TestStopCPUProfiler(t *testing.T) {
for _, test := range SuccessResponseTests {
t.Run(test.name, func(t *testing.T) {
mockClient := Client{Requester: NewMockClient(&api.EmptyReply{}, test.expectedErr)}
err := mockClient.StopCPUProfiler(context.Background())
err := mockClient.StopCPUProfiler(t.Context())
require.ErrorIs(t, err, test.expectedErr)
})
}
Expand All @@ -98,7 +98,7 @@ func TestMemoryProfile(t *testing.T) {
for _, test := range SuccessResponseTests {
t.Run(test.name, func(t *testing.T) {
mockClient := Client{Requester: NewMockClient(&api.EmptyReply{}, test.expectedErr)}
err := mockClient.MemoryProfile(context.Background())
err := mockClient.MemoryProfile(t.Context())
require.ErrorIs(t, err, test.expectedErr)
})
}
Expand All @@ -108,7 +108,7 @@ func TestLockProfile(t *testing.T) {
for _, test := range SuccessResponseTests {
t.Run(test.name, func(t *testing.T) {
mockClient := Client{Requester: NewMockClient(&api.EmptyReply{}, test.expectedErr)}
err := mockClient.LockProfile(context.Background())
err := mockClient.LockProfile(t.Context())
require.ErrorIs(t, err, test.expectedErr)
})
}
Expand All @@ -118,7 +118,7 @@ func TestAlias(t *testing.T) {
for _, test := range SuccessResponseTests {
t.Run(test.name, func(t *testing.T) {
mockClient := Client{Requester: NewMockClient(&api.EmptyReply{}, test.expectedErr)}
err := mockClient.Alias(context.Background(), "alias", "alias2")
err := mockClient.Alias(t.Context(), "alias", "alias2")
require.ErrorIs(t, err, test.expectedErr)
})
}
Expand All @@ -128,7 +128,7 @@ func TestAliasChain(t *testing.T) {
for _, test := range SuccessResponseTests {
t.Run(test.name, func(t *testing.T) {
mockClient := Client{Requester: NewMockClient(&api.EmptyReply{}, test.expectedErr)}
err := mockClient.AliasChain(context.Background(), "chain", "chain-alias")
err := mockClient.AliasChain(t.Context(), "chain", "chain-alias")
require.ErrorIs(t, err, test.expectedErr)
})
}
Expand All @@ -143,14 +143,14 @@ func TestGetChainAliases(t *testing.T) {
Aliases: expectedReply,
}, nil)}

reply, err := mockClient.GetChainAliases(context.Background(), "chain")
reply, err := mockClient.GetChainAliases(t.Context(), "chain")
require.NoError(err)
require.Equal(expectedReply, reply)
})

t.Run("failure", func(t *testing.T) {
mockClient := Client{Requester: NewMockClient(&GetChainAliasesReply{}, errTest)}
_, err := mockClient.GetChainAliases(context.Background(), "chain")
_, err := mockClient.GetChainAliases(t.Context(), "chain")
require.ErrorIs(t, err, errTest)
})
}
Expand All @@ -159,7 +159,7 @@ func TestStacktrace(t *testing.T) {
for _, test := range SuccessResponseTests {
t.Run(test.name, func(t *testing.T) {
mockClient := Client{Requester: NewMockClient(&api.EmptyReply{}, test.expectedErr)}
err := mockClient.Stacktrace(context.Background())
err := mockClient.Stacktrace(t.Context())
require.ErrorIs(t, err, test.expectedErr)
})
}
Expand All @@ -182,15 +182,15 @@ func TestReloadInstalledVMs(t *testing.T) {
FailedVMs: expectedFailedVMs,
}, nil)}

loadedVMs, failedVMs, err := mockClient.LoadVMs(context.Background())
loadedVMs, failedVMs, err := mockClient.LoadVMs(t.Context())
require.NoError(err)
require.Equal(expectedNewVMs, loadedVMs)
require.Equal(expectedFailedVMs, failedVMs)
})

t.Run("failure", func(t *testing.T) {
mockClient := Client{Requester: NewMockClient(&LoadVMsReply{}, errTest)}
_, _, err := mockClient.LoadVMs(context.Background())
_, _, err := mockClient.LoadVMs(t.Context())
require.ErrorIs(t, err, errTest)
})
}
Expand Down Expand Up @@ -253,7 +253,7 @@ func TestSetLoggerLevel(t *testing.T) {
),
}
res, err := c.SetLoggerLevel(
context.Background(),
t.Context(),
"",
tt.logLevel,
tt.displayLevel,
Expand Down Expand Up @@ -306,7 +306,7 @@ func TestGetLoggerLevel(t *testing.T) {
),
}
res, err := c.GetLoggerLevel(
context.Background(),
t.Context(),
tt.loggerName,
)
require.ErrorIs(err, tt.clientErr)
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestGetConfig(t *testing.T) {
c := Client{
Requester: NewMockClient(tt.expectedResponse, tt.serviceErr),
}
res, err := c.GetConfig(context.Background())
res, err := c.GetConfig(t.Context())
require.ErrorIs(err, tt.clientErr)
if tt.clientErr != nil {
return
Expand Down
18 changes: 9 additions & 9 deletions api/health/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,33 @@ func TestClient(t *testing.T) {
}

{
readiness, err := c.Readiness(context.Background(), nil)
readiness, err := c.Readiness(t.Context(), nil)
require.NoError(err)
require.True(readiness.Healthy)
}

{
health, err := c.Health(context.Background(), nil)
health, err := c.Health(t.Context(), nil)
require.NoError(err)
require.True(health.Healthy)
}

{
liveness, err := c.Liveness(context.Background(), nil)
liveness, err := c.Liveness(t.Context(), nil)
require.NoError(err)
require.True(liveness.Healthy)
}

{
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
ctx, cancel := context.WithTimeout(t.Context(), 3*time.Second)
healthy, err := AwaitHealthy(ctx, c, time.Second, nil)
cancel()
require.NoError(err)
require.True(healthy)
}

{
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
ctx, cancel := context.WithTimeout(t.Context(), 3*time.Second)
healthy, err := AwaitReady(ctx, c, time.Second, nil)
cancel()
require.NoError(err)
Expand All @@ -84,15 +84,15 @@ func TestClient(t *testing.T) {
mc.reply.Healthy = false

{
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Microsecond)
ctx, cancel := context.WithTimeout(t.Context(), 20*time.Microsecond)
healthy, err := AwaitHealthy(ctx, c, time.Microsecond, nil)
cancel()
require.ErrorIs(err, context.DeadlineExceeded)
require.False(healthy)
}

{
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Microsecond)
ctx, cancel := context.WithTimeout(t.Context(), 20*time.Microsecond)
healthy, err := AwaitReady(ctx, c, time.Microsecond, nil)
cancel()
require.ErrorIs(err, context.DeadlineExceeded)
Expand All @@ -104,14 +104,14 @@ func TestClient(t *testing.T) {
}

{
healthy, err := AwaitHealthy(context.Background(), c, time.Microsecond, nil)
healthy, err := AwaitHealthy(t.Context(), c, time.Microsecond, nil)
require.NoError(err)
require.True(healthy)
}

mc.reply.Healthy = false
{
healthy, err := AwaitReady(context.Background(), c, time.Microsecond, nil)
healthy, err := AwaitReady(t.Context(), c, time.Microsecond, nil)
require.NoError(err)
require.True(healthy)
}
Expand Down
8 changes: 4 additions & 4 deletions api/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestPassingChecks(t *testing.T) {
require.NoError(h.RegisterHealthCheck("check", check))
require.NoError(h.RegisterLivenessCheck("check", check))

h.Start(context.Background(), checkFreq)
h.Start(t.Context(), checkFreq)
defer h.Stop()

{
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestPassingThenFailingChecks(t *testing.T) {
require.NoError(h.RegisterHealthCheck("check", check))
require.NoError(h.RegisterLivenessCheck("check", check))

h.Start(context.Background(), checkFreq)
h.Start(t.Context(), checkFreq)
defer h.Stop()

awaitReadiness(t, h, true)
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestDeadlockRegression(t *testing.T) {
return "", nil
})

h.Start(context.Background(), time.Nanosecond)
h.Start(t.Context(), time.Nanosecond)
defer h.Stop()

for i := 0; i < 100; i++ {
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestTags(t *testing.T) {
require.False(health)
}

h.Start(context.Background(), checkFreq)
h.Start(t.Context(), checkFreq)

awaitHealthy(t, h, true)

Expand Down
4 changes: 2 additions & 2 deletions api/health/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestServiceResponses(t *testing.T) {
require.False(reply.Healthy)
}

h.Start(context.Background(), checkFreq)
h.Start(t.Context(), checkFreq)
defer h.Stop()

awaitReadiness(t, h, true)
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestServiceTagResponse(t *testing.T) {
require.False(reply.Healthy)
}

h.Start(context.Background(), checkFreq)
h.Start(t.Context(), checkFreq)

test.await(t, h, true)

Expand Down
6 changes: 3 additions & 3 deletions api/info/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func TestClient(t *testing.T) {
}

{
bootstrapped, err := c.IsBootstrapped(context.Background(), "X")
bootstrapped, err := c.IsBootstrapped(t.Context(), "X")
require.NoError(err)
require.True(bootstrapped)
}

mc.reply.IsBootstrapped = false

{
bootstrapped, err := c.IsBootstrapped(context.Background(), "X")
bootstrapped, err := c.IsBootstrapped(t.Context(), "X")
require.NoError(err)
require.False(bootstrapped)
}
Expand All @@ -64,7 +64,7 @@ func TestClient(t *testing.T) {
}

{
bootstrapped, err := AwaitBootstrapped(context.Background(), c, "X", time.Microsecond)
bootstrapped, err := AwaitBootstrapped(t.Context(), c, "X", time.Microsecond)
require.NoError(err)
require.True(bootstrapped)
}
Expand Down
6 changes: 4 additions & 2 deletions cache/lru/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ func TestCacheOnEvict(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
evictedKeys := make([]int, 0)
evictedValues := make([]int, 0)
var (
evictedKeys []int
evictedValues []int
)
c := NewCacheWithOnEvict(tt.cacheSize, func(key, value int) {
evictedKeys = append(evictedKeys, key)
evictedValues = append(evictedValues, value)
Expand Down
2 changes: 1 addition & 1 deletion codec/codectest/codectest.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ func TestSliceWithEmptySerialization(t testing.TB, codec codecpkg.GeneralCodec)
require.NoError(manager.RegisterCodec(0, codec))

val := &nestedSliceStruct{
Arr: make([]emptyStruct, 0),
Arr: []emptyStruct{},
}
expected := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // codec version (0x00, 0x00) then (0x00, 0x00, 0x00, 0x00) for numElts
result, err := manager.Marshal(0, val)
Expand Down
3 changes: 1 addition & 2 deletions database/corruptabledb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package corruptabledb

import (
"context"
"errors"
"testing"

Expand Down Expand Up @@ -73,7 +72,7 @@ func TestCorruption(t *testing.T) {
return corruptableBatch.Write()
},
"corrupted healthcheck": func(db database.Database) error {
_, err := db.HealthCheck(context.Background())
_, err := db.HealthCheck(t.Context())
return err
},
}
Expand Down
Loading